function showBlackout() {
    if (!$('#blackout').length) {
    	if (!window.XMLHttpRequest) { //IE6-
    		$('select').hide();
		}
        $('body').append('<div id="blackout"></div>');
        if (!window.XMLHttpRequest) { //IE6-
    		$('#blackout').css('height', $('body').height()+"px");
		}
    }
}
function removeBlackout() {
	if (!window.XMLHttpRequest) { //IE6-
    	$('select').show();
	}
    $('#blackout').remove();
}
function centerElement(elementID) {
    if (window.innerWidth) {
        var windowWidth = window.innerWidth;
        var windowHeight = window.innerHeight;
    }
    else if (document.all) {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
    }
    var elementWidth = $('#'+elementID).width();
    var elementHeight = $('#'+elementID).height();
    
    if (!window.XMLHttpRequest) { //IE6-
    	$('#'+elementID).css('position', 'absolute');
        window.scrollTo(0,0);
	}
	else {
		$('#'+elementID).css('position', 'fixed');
	}
    $('#'+elementID).css('z-index', '99999');
    $('#'+elementID).css('top', (windowHeight/2)-(elementHeight/2));
    $('#'+elementID).css('left', (windowWidth/2)-(elementWidth/2));
}



$(function() {
	/*********** History Slider****************/
	var index = 0;

	// trigger button
	$('#paddle_top_button').click(function(){
		if(index != 0) {
			$("#view_pane_container").animate({"top": "+=258px"}, "slow");
			index -= 1;
		}
	});
	
	$('#paddle_bottom_button').click(function(){
		if(index != 4) {
			$("#view_pane_container").animate({"top": "-=258px"}, "slow");
			index += 1;
		}
	});
	

	/*********** Pic/Text/Video Pop-up****************/
	//popupStatus: 0 means disabled; 1 means enabled;	
	var popup;
	
	$(".text_popup").click(function(){
		//replace the content in the text-box
		var currentID = $(this).attr('id');  
		var imgID= '#'+ currentID +'_text';
		$('#text_box #contactArea').html($(imgID).html());
		popup = '#text_box';
		//centering with css
		centerPopup(popup);
		//load popup
		loadPopup(popup);
		return false;
	});

	/*$(".video_popup").click(function(){
		popup = '#pop_videoPlayer_container';
		//centering with css
		centerPopup(popup);
		//load popup
		loadPopup(popup);
		return false;
	});*/

	//CLOSING POPUP
	$(".popupContactClose").live('click', function(){
		disablePopup(popup);
		return false;
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup(popup);
		return false;
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup(popup);
			return false;
		}
	});
	
	/*********** according ****************/
	$('#accordion h3').bind('click', function() {
		if (!$(this).is('.open')) {
			$('h3.open').removeClass('open').next('p').slideUp();
			$(this).addClass('open').next('p').slideDown();
		}
	});
	
	/*********** Clear Map Location Textfield****************/
	$("#mapSearchText").click(function(){
		$(this).attr('value','');
	});
	

	/*********** pin board text selector****************/

	$('#pinboard a').mouseenter(function() {	
		var id = $(this).attr('id');
		//console.log(id);
	});
	
	/* --- Video Popup --- */
	
	$(".closeVideoPlayer").live('click', function(){
		//disablePopup(popup);
		removeBlackout();
		$('#pop_videoPlayer_container').remove();
		return false;
	});

	$('#link6').bind('click', function()
	{
		var popUpHTML = '<div id="pop_videoPlayer_container">\
			<a id="videobox_Close" class="closeVideoPlayer png"></a>\
			<div id="videoPlayer">\
				<div class="nojavascript">JavaScript is turned off,you need JavaScript to enable the video player and other interactive features on the site</div>\
				<div class="novideo">You need HTML5 or Flash to view videos.<br />For HTML5,please download the latest web browser such as <br />&ndash; FireFox <a href="http://www.mozilla.com/en-US/firefox/personal.html">Download</a> <br />&ndash; Chrome <a href="http://www.google.com/chrome">Download</a> <br />&ndash; Safari <a href="http://www.apple.com/safari/download/">Download</a></div>\
				<div class="skin" style="display: none;">\
					<div class="videoHolder">\
						<div class="video"></div>\
					</div>\
					<div class="bar">\
						<div class="uibutton play"></div>\
						<div class="uibutton pause"></div>\
						<div class="seekbar">\
							<div class="seekbarfilling"></div>\
						</div>\
					</div>\
				</div>\
			</div>\
		</div>';
		
		$('body').append(popUpHTML);
		showBlackout();
		centerElement('pop_videoPlayer_container');
		
		var config = {
			"settings":
			{
				"forceflash":true,
				"html":
				{
					"id": "videoPlayer",
					"width": "480",
					"height": "270"
				},
				"flash":
				{
					"swfUrl": "/flash/VideoPlayer.swf",
					"id": "videoPlayer",
					"width": "503",
					"height": "335",
					"version": "9.0.0",
					"expressInstallSwfurl": "expressInstall.swf",
					"flashvars":
					{
						"type": "file"
					},
					"params":
					{
						"wmode" : "transparent",
						"allowfullscreen": "true", 
						"allowscriptaccess": "always"
					},
					"attributes":
					{
					}
				}
			}
		}
		
		config.settings.flash.flashvars.file = $(this).attr('rel');
		
		Landlord.loadVideoPlayer(config);		
		
		return false;
		
	});
	
	$('.video_section a').bind('click', function() {
		
		if ($('#inlineVideoPlayer').length) {
			Landlord.pause('inlineVideoPlayer');
		}
		
		var popUpHTML = '<div id="pop_videoPlayer_container">\
			<a id="videobox_Close" class="closeVideoPlayer png"></a>\
			<div id="videoPlayer">\
				<div class="nojavascript">JavaScript is turned off,you need JavaScript to enable the video player and other interactive features on the site</div>\
				<div class="novideo">You need HTML5 or Flash to view videos.<br />For HTML5,please download the latest web browser such as <br />&ndash; FireFox <a href="http://www.mozilla.com/en-US/firefox/personal.html">Download</a> <br />&ndash; Chrome <a href="http://www.google.com/chrome">Download</a> <br />&ndash; Safari <a href="http://www.apple.com/safari/download/">Download</a></div>\
				<div class="skin" style="display: none;">\
					<div class="videoHolder">\
						<div class="video"></div>\
					</div>\
					<div class="bar">\
						<div class="uibutton play"></div>\
						<div class="uibutton pause"></div>\
						<div class="seekbar">\
							<div class="seekbarfilling"></div>\
						</div>\
					</div>\
				</div>\
			</div>\
		</div>';
		
		
		$('body').append(popUpHTML);
		centerElement('pop_videoPlayer_container');
		showBlackout();
		
		var config = {
			"settings":
			{
				"forceflash":true,
				"html":
				{
					"id": "videoPlayer",
					"width": "480",
					"height": "270"
				},
				"flash":
				{
					"swfUrl": "/flash/VideoPlayer.swf",
					"id": "videoPlayer",
					"width": "503",
					"height": "335",
					"version": "9.0.0",
					"expressInstallSwfurl": "expressInstall.swf",
					"flashvars":
					{
						"type": "file"
					},
					"params":
					{
						"wmode" : "transparent",
						"allowfullscreen": "true", 
						"allowscriptaccess": "always"
					},
					"attributes":
					{
					}
				}
			}
		}
		
		config.settings.flash.flashvars.file = $(this).attr('rel');
		
		Landlord.loadVideoPlayer(config);		
		
		return false;
	});
	
	/* Used on the job search and apply page */
	$('#downloadSection a').mouseenter(function() {
		$('#'+$(this).attr('rel')).addClass('hover');
	}).mouseleave(function() {
		$('#'+$(this).attr('rel')).removeClass('hover');
	});
	
	
	/* --- Career Paths JS --- */
	$('.career_profile_item_photo').bind('click', function() {
		if (!$(this).is('.selectedProfile')) {
			//hide all profiles first
			$('.career_profile_history_text_pane').hide();
			
			$('.selectedProfile').removeClass('selectedProfile');
			$(this).addClass('selectedProfile');
			
			//show the career path item
			$('.career_profile_history_text_pane').eq($(this).index()).show();
			
			$('#career_profile_selection_arrow').animate({"left": $(this).position().left}, "slow");
		}
	});
	
});/**End of document.ready()********/
	
var	videosPlayed = 0;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(popup){
	//loads popup only if it is disabled
	if(popupStatus == 0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("300");
		$(popup).fadeIn("300");
		popupStatus = 1;		
	}
}

//disabling popup with jQuery magic!
function disablePopup(popup){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("300");
			$(popup).fadeOut("300");
		}
		popupStatus = 0;
	}

//centering popup
function centerPopup(popup){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(popup).height();
	var popupWidth = $(popup).width();

			//centering
		$(popup).css({
			//"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight
	});

}
