var userOSAgent = navigator.userAgent.toLowerCase();

// Figure out what browser is being used
jQuery.platform = {
        mac: /mac/.test(userOSAgent),
        osx: /mac os x/.test(userOSAgent),
        win: /win/.test(userOSAgent),
        linux: /linux/.test(userOSAgent)
};

 $(document).ready(function() {
    if(document.getElementById('container')){checkForSection();}
    if(document.getElementById('testflv')){
        var embed = FlashVideo_plain('/swf/assets/flv/Sample.flv');
        showVideoWindow(embed);
    }
    if(document.getElementById('testflv2')){
        var embed = FlashVideo_cartoon('/swf/assets/flv/Sample.flv');
        showVideoWindow(embed);
    }
    if($('.overlay')[0]){
        $('.overlay').click(function() {
            closeVideoWindow();
        });
    }
   $("#header #headerRightBottom #topNav li").hover(
     function(){
	   $(this).addClass("active");
	 },
	 function(){
	   $(this).removeClass("active");
   });
   
   $("#boxLink1").click(function() {
     $("#boxNav a").removeClass("active");
     $(this).addClass("active");
	 $(".boxSub").removeClass("active");
	 $("#boxSub1").addClass("active");
   });
   
   $("#boxLink2").click(function() {
     $("#boxNav a").removeClass("active");
     $(this).addClass("active");
	 $(".boxSub").removeClass("active");
	 $("#boxSub2").addClass("active");
   });
   
   $("#boxLink3").click(function() {
     $("#boxNav a").removeClass("active");
     $(this).addClass("active");
	 $(".boxSub").removeClass("active");
	 $("#boxSub3").addClass("active");
   });
   if(jQuery.platform.mac){
		$("a.learnMore").css("padding-top","6px")
   }
   
    var vLinks = $('.videoLinkPlain');
    for(var i=0; i<vLinks.length; i++){
	    vLinks[i].onclick = function(){
		    var src = this.href;
		    var objSrc = FlashVideo_plain(src);
		    showVideoWindow(objSrc);
		    return false;
	    };
    }
    
    var vLinks = $('.videoLinkCartoon');
    for(var i=0; i<vLinks.length; i++){
	    vLinks[i].onclick = function(){
		    var src = this.href;
		    var objSrc = FlashVideo_cartoon(src);
		    showVideoWindow(objSrc);
		    return false;
	    };
    }
   
 });
 
 function checkForSection(){
    var template = $('#container.nopad')[0];
    var section = $('#container .section')[0];
    if(!section && template){
        $('#container').addClass('withPadding');
    }   
 }
 
function showVideoWindow(src){
	$('.modal').html(src);
	$('.overlay').addClass('overlayon');
	$('.modal').addClass('modalon');	
}
 
function closeVideoWindow(){    
	$('.modal').html('');
	$('.overlay').removeClass('overlayon');
	$('.modal').removeClass('modalon');
}

//FLV Functions
// plain flash
function FlashVideo_plain(flvFile){
	var swfName = "VideoPlayer";
	var swfFile = "/swf/Kids_Hope_VideoPlayer_PlainSkin.swf";
	var swfWidth = 530;
	var swfHeight = 370;
	var swfWMode = "opaque";
	var swfFullscreen = "false";
	var swfMenu = "false";
	var swfBGColor = "#ffffff";
	var vars = "flv="+flvFile+"&assetsDir=/swf/plainimages/";
	var html = loadFlash(swfName, swfFile, swfWidth, swfHeight, swfWMode, swfFullscreen, swfMenu, swfBGColor, vars);
	return html;
}

// cartoon flash
function FlashVideo_cartoon(flvFile){
	var swfName = "VideoPlayer";
	var swfFile = "/swf/Kids_Hope_VideoPlayer_CartoonSkin.swf";
	var swfWidth = 530;
	var swfHeight = 370;
	var swfWMode = "opaque";
	var swfFullscreen = "false";
	var swfMenu = "false";
	var swfBGColor = "#ffffff";
	var vars = "flv="+flvFile+"&assetsDir=/swf/cartoonimages/";
	var html = loadFlash(swfName, swfFile, swfWidth, swfHeight, swfWMode, swfFullscreen, swfMenu, swfBGColor, vars);	
	return html;
}
