
//VARIABLES

var videoOpen = false;
var player = null;
var vidURL = null;



function playerReady(thePlayer) {
	//console.log('playerReady()');
	
	
	player = window.document[thePlayer.id];
	
	player.addControllerListener("STOP","stoppedEvent");


}

function stoppedEvent(obj) { 
	player.removeControllerListener("STOP","handleEvent");
	closeVideoBox();
};

////OPEN VIDEO BOX
function openPlayer(fileName) {

	
	
	if(fileName != null && fileName == vidURL){
		videoPath = fileName;
	} else {
		videoPath = 'video/gdmx-intro.mov';
	}
	
		
	//console.log('told to open : ', videoPath);
	var flashvars = {	
		file: videoPath,
		autostart:"true"
	}

	var params = {
		allowfullscreen:"true", 
		allowscriptaccess:"always"
	}

	var attributes = {
		id:"player1",  
		name:"player1"
	}

	swfobject.embedSWF("player.swf", "player", "900", "530", "9.0.115", false, flashvars, params, attributes);
}


////CLOSE VIDEO BOX
function closeVideoBox(){
	

	
//console.log('closeVideoBox() has been called')


	$("#player_container").html("<div id='player'></div>");
	
	$("#header").animate({ 
        height: "257px"
      }, 300, 'linear', function() {
		  	$("#player_container").html("<div id='player'></div>");
			$("#header").removeClass("blk");
			videoOpen = false;
			$("#play_vid").fadeIn();
			$("#animated_background").fadeIn();
			$("#gdmx_logo_lrg").fadeIn();
			$("#gdmx_logo_sml").fadeOut();
			$("#close_vid").hide();
		});
	
	if (window.document.body.id == "home"){
		addHeaderAnimation();
	}

	
}

// INITIATE ANIMATING HEADER 
function addHeaderAnimation(){

	$("#anim_bg_holder").html("<div id='animated_background'></div>");
		var flashvars = {	
		file: 'video/earth_vid.mov',
		autostart:"true"
		}
		var params = {
			allowfullscreen:"false", 
			allowscriptaccess:"always", 
			bgcolor:"#000000", 
			wmode:"opaque"
		}
		var attributes = {
			id:"player0",  
			name:"player0",
			style:"position:absolute; z-index:1;"
		}
	swfobject.embedSWF("video_massive.swf", "animated_background", "900", "257", "9.0.115", false, flashvars, params, attributes);
}




////START OF DOCUMENT.READY

$(document).ready(function(){
	
	if (window.document.body.id == "home"){
		addHeaderAnimation();
	}
	
	
	
	// 'SERVICES SIDEBAR' EXPAND / COLLAPSE
	
	$(".expandable a.expand_head").click(function () {
		
		
		
		if($(this).parent().hasClass("active_tab")){

			$(".active_tab .copy").slideUp();
			$(".active_tab a.expand_head").removeClass("open_tab");
			$(".active_tab").removeClass("active_tab");
			
	
			
		} else {
			
			$(".active_tab .copy").slideUp();
			$(".active_tab a.expand_head").removeClass("open_tab");
			$(".active_tab").removeClass("active_tab");
			
			$(this).parent().addClass("active_tab");
			// JP $(".active_tab .copy").attr("width", "parent's width minus padding");
			$(".active_tab .copy").slideDown();
			$(".active_tab a.expand_head").addClass("open_tab");
			
		}
		
		
		return false;
		
		
	});
						
	
	//SUBNAV OPEN / CLOSE
	$("#services_nav").mouseover(function(){
		$("#srv_subnav").show();

			$("#srv_subnav").mouseover(function(){
				$("#srv_subnav").show();

			}).mouseout(function(){
				$("#srv_subnav").hide();
			});
		return false;
	
    }).mouseout(function(){
    	$("#srv_subnav").hide();
    });
	
	
	
	
	$("#about_nav").mouseover(function(){
		$("#about_subnav").show();
		
			$("#about_subnav").mouseover(function(){
				$("#about_subnav").show();

			}).mouseout(function(){
				$("#about_subnav").hide();
			});
		return false;
	
    }).mouseout(function(){
    	$("#about_subnav").hide();
    });
	
	
	
	
		$(".last_sub").mouseover(function(){
				$(".sub_bottom").addClass("last_sub_over");
			}).mouseout(function(){
				$(".sub_bottom").removeClass("last_sub_over");
			});
	
	
	

});
