﻿$().ready(function(){    
    if(jQuery.browser.msie == true)
    {        
        if(jQuery.browser.version < 7)
        {
            $("img.fixpng").ifixpng();
            
            $("ul.tablist li").hover(function(){
                $(this).css("background","white url(images/tabbg-on.jpg) no-repeat scroll 0 0");
                var a = $(this).find("a");
                a.css({color: "#2547A0", background: "transparent url(images/listtriangle-blue.gif) no-repeat scroll 0px 70%"});
            },function(){
                if($(this).hasClass("on") == false)
                {
                    $(this).css("background","#666666 url(images/tabbg.png) no-repeat scroll 0 0");
                    var a = $(this).find("a");
                    a.css({color: "white", background: "transparent url(images/listtriangle-white.gif) no-repeat scroll 0px 70%"});
                }
            });
        }
    }    
    else
    {
        $("#show-changeshowbox").fadeTo(1,0.85).hover(function(){$(this).fadeTo("normal",1);},function(){$(this).fadeTo("slow",0.85);});
    }
    
    $(".todayfm-turnonyet").fadeOut(1,function(){$(this).fadeIn(2000);});    
    
    $("#LNS ul li").click(function(){        
        window.location = $(this).find("a").attr("href");
    });
        
    $("div.show-content").each(function(){
        var link = $(this).find("a").attr("href");
        if(link != null && link.length > 0)
        {         
            this.Link = link;   
            $(this).click(function(){
                window.location = this.Link;
            });
            $(this).hover(function(){
                $(this).css("border-color","yellow");
                $(this).find("a").css("text-decoration","underline");
            },
            function(){
                $(this).css("border-color","white");
                $(this).find("a").css("text-decoration","none");
            });
        }
        else
        {
            $(this).css("cursor","default");
        }
    });   
    $("ul.tablist li").click(function(){
        window.location = $(this).find("a").attr("href");        
    });
    $("#divHighlightsPanel dd img").hover(function(){
        $(this).parent().parent().find("a").css("text-decoration","underline");
    },function(){
        $(this).parent().parent().find("a").css("text-decoration","none");
    });
    $(".photoGalleryListControl dd img").hover(function(){
        $(this).parent().parent().find("a").css("text-decoration","underline");
    },function(){
        $(this).parent().parent().find("a").css("text-decoration","none");
    });    
    $("#divHighlightsPanel dd img").click(function(){
        var link = $(this).parent().parent().find("a").attr("href");
        if(link != null && link.length > 0)
        {
            window.location = $(this).parent().parent().find("a").attr("href");
        }
    }); 
    $(".photoGalleryListControl dd img").click(function(){
        window.location = $(this).parent().parent().find("a").attr("href");        
    });  
    
    var showMePlayer = $("#ShowPlayMe");
    if(showMePlayer.length >0)
    {
        if(jQuery.browser.msie == true)
        {
            var msieVer = parseInt(jQuery.browser.version);
            if(msieVer < 7)
            {
                showMePlayer.find("a").addClass("ie6");
            }
        }
        showMePlayer.fadeIn();
        setInterval('ShakeObj("'+showMePlayer.attr("id")+' a");',4000);
        
        showMePlayer.toggle(function(){
            showMePlayer.find(".playerWrapper .videoPlayerBg").css({width: "0px",height: "0px",opacity: 0,left: "0px",top: "0px"}).animate({left: "12px",width: "240px",height: "180px", top: "13px", opacity: 0.8},800,function(){
                //playingShowVideo = true;
                $(this).parent().find(".videoPlayer").show();      
                //playYouTubeVideo('showPlayerObject');          
            });
        },function(){
            stopYouTubeVideo("showPlayerObject");
            showMePlayer.find(".videoPlayer").hide(1,function(){
                showMePlayer.find(".playerWrapper .videoPlayerBg").animate({left: "0px",width: "0px",height: "0px", top: "0px", opacity: 0},500,function(){playingShowVideo = false;});
            });            
        });
        
        setTimeout("$('#ShowPlayMe').click();",3000);
    }
    
    CheckFlash();
    HomepageBlogLinks();   
});

var playingShowVideo = false;

function onYouTubePlayerReady(playerId)
{
    /*
    if(playerId == 'showPlayerObject')
        playYouTubeVideo('showPlayerObject');
    */
}

function playYouTubeVideo(playerId)
{
    try{
        $("#"+playerId).get(0).playVideo();
    }catch(Exception){}
}
function stopYouTubeVideo(playerId)
{
    $("#"+playerId).get(0).pauseVideo();
}
function ShakeObj(objId)
{
    if(playingShowVideo == false)
    {
        var elem = $("#"+objId);
        var x = elem.position().left;
        var y = elem.position().top;
        elem.animate({left: (x+2)+"px",top: (y+2)+"px"},100).animate({left: (x-2)+"px",top: (y)+"px"},100).animate({left: (x+2)+"px",top: (y-2)+"px"},100).animate({left: (x-2)+"px",top: (y+2)+"px"},100).animate({left: (x+2)+"px",top: (y+2)+"px"},100).animate({left: (x+2)+"px",top: (y)+"px"},100).animate({left: (x)+"px",top: (y)+"px"},100);
     }
}

function CheckFlash()
{
    var flashWrapper = $("#flash-wrapper");
    if(flashWrapper.length > 0 && detectFlash() == false)
    {
        flashWrapper.empty();
        flashWrapper.addClass("noflash");
        flashWrapper.css({width: (flashWrapper.width()-2)+"px", height: (flashWrapper.height()-2)+"px"});
        
        var noFlash = $("#footer-footer").clone();
        noFlash.attr("id","noflash-content").find("span").remove();        
        flashWrapper.append(noFlash);
        noFlash.animate({top: "100px"},3000);
    }
}

function HomepageBlogLinks()
{
    var ulPosts = $(".sectionbox-wrapper .sf_postListing");
    if(ulPosts != null && ulPosts.length > 0)
    {
        ulPosts.find("li").each(function(){
            var blogUrl = $(this).find('.sf_postAuthor a').attr('href');
            $(this).find('.sf_postTitle a').attr('href', blogUrl);
        });
    }
}