var initialized = false;
var flashContentDiv = null;
var flashObj = null;

var DeloitteCareers = {
	flash : {	//We'll be checking for flash 9.0.0 and above
		major : 10,
		minor : 0,
		revision : 0
	},
	options : {		
		minWidth : 960	//Used for IE6 min width for the SEO / no-flash version
	},
	contentHeight : null,
	hasFlash : false,
	isIE6 : null,
	initialize : function(){
		var version = swfobject.getFlashPlayerVersion();
		DeloitteCareers.hasFlash = ((version["major"]>DeloitteCareers.flash.major) || (version["major"]==DeloitteCareers.flash.major && version['minor']>DeloitteCareers.flash.minor) || (version["major"]==DeloitteCareers.flash.major && version['minor']==DeloitteCareers.flash.minor && version['release']>=DeloitteCareers.flash.revision));
		DeloitteCareers.isIE6 = (jQuery.browser.msie==true) && (jQuery.browser.version==6.0);
		DeloitteCareers.load();
	},
	load : function(){
		if (DeloitteCareers.hasFlash){
			//Prepare page for full flash takeover
			Util.fullwin();
			
			var swfSource="resources/global/flash/careers_preloader.swf";
			var flashvars = {};
			var locale = "en_ROW";

			flashvars.locale = locale;
			flashvars.useDeviceFont = "false";
			flashvars.configPath = "resources/global/flash/data/config/deloitte_careers_config.xml";
			flashvars.languagePath = "resources/global/flash/data/languages/deloitte_careers_"+locale+".xml";
			
			// place location containg all the swfs here
			flashvars.swfPath = "resources/global/flash/";
			
			// place location to "flash_content" here
			// structure and file names inside "flash_content" needs to remain intact
			flashvars.assetsPath = "resources/global/flash_content/";
			
			// pass the domain name of where this html is located to allow cross-domain scripting
			flashvars.allowDomainScript = "";
			
			var params = {};
			//params.menu = "false";
			params.wmode = "window";
			params.allowFullScreen = "true";
			params.scale = "noborder";
			params.align = "middle";
			params.allowScriptAccess = "always";

			var attributes = {};
			attributes.id = "flashContent";
			attributes.name = "flashContent";
			attributes.bgcolor = "#f6f6f6";

			swfobject.embedSWF(swfSource, "flashContent", "100%", "100%", "10.0.0", "", flashvars, params, attributes);
			// ok you have flash, but did the load not work?
			if( jQuery("#wrap .p-wrap-one").html() != null ) {
				jQuery("body").addClass("no-flash-body");
			}
			
			flashContentDiv = document.getElementById("flashContent");
			flashObj = document.getElementById("flashContent");
			
			//window.onresize = Util.size;
			swffit.fit("flashContent",960,768,2500,2000);
		} else {
			//User does not have flash, or it is an older version. Instead, show the SEO copy
			//The resize functionality is separate from the resize version for the SWF, as this version will vertically center the SEO section
			jQuery("body").addClass("no-flash-body");
			//$("#page").css("display","block");
			//$("#flashContent").css("display","none");
			DeloitteCareers.contentHeight = $("#header").height()+$("#footer").height()+$("#content").height();
			window.onresize = Util.resize;
			Util.resize();
			//User does not have flash; Show the default SEO / "Get Flash" 
		}
	}
}

var Util = {
	options : {
		maxWidth : 2500,
		maxHeight : 2000
	},
	resize : function(){
		//The resize functionality is separate from the resize version for the SWF, as this version will vertically center the SEO section

		//HEIGHT
		_h_body = $(window).height();
		//alert(_h_body);
		if (DeloitteCareers.contentHeight<_h_body){
			_h_diff = _h_body - DeloitteCareers.contentHeight;
			$("#header").css("padding-bottom",Math.floor(_h_diff*47/(86+47)));
			$("#content-sub-wrapper").css("padding-bottom",Math.floor(_h_diff*86/(86+47)));
		}
		
		//WIDTH only on IE6 since no min-width
		if (DeloitteCareers.isIE6){
			_w_body = $(window).width();
			if (DeloitteCareers.options.minWidth<_w_body){
				//Expand width
				$("#footer").css("width",_w_body);
			} else {
				//Contract width
				$("#footer").css("width",DeloitteCareers.options.minWidth);
			}
		}
	},
	fullwin : function(){
		//Resize window to max dimensions for flash takeover
		
		screenW = screen.width;
		screenH = screen.availHeight;
		
		if(screenW > Util.options.maxWidth)
			screenW = Util.options.maxWidth;
		if(screenH > Util.options.maxHeight)
			screenH = Util.options.maxHeight;	
		window.resizeTo(screenW, screenH);
		window.moveTo((screen.width-screenW)/2,0);
	},
	size : function(){
		//Resize window for flash takeover

		flashObj.height = Math.max(flashContentDiv.clientHeight,document.getElementById("body").clientHeight);
		if (document.getElementById("body").clientWidth<1003){
			flashObj.width = 1003;
		} else {
			flashObj.width = "100%";
		}
		if (document.getElementById("body").clientHeight<768){
			flashObj.height = 768;
		} else {
			flashObj.height = "100%";
		}
	}
}


$(document).ready(function() {
	DeloitteCareers.initialize();
});
