var _MOVIEPATH = "/microsites/sp/unicef/swf/loader.swf";
var _MOVIEWIDTH = 998;
var _MOVIEHEIGHT = 568;
var main;

var so; 

function getParameter(name){
    var loc = location.search;    
    var pos = loc.indexOf(name);
    if (pos < 0) return null;
    var len = pos+name.length+1;
    var param = loc.substring(len);
    if (param.indexOf('&') > 0) param = param.substring(0, param.indexOf('&'));
    return param;
}

function isWindowsFirefox(){
	var agent = navigator.userAgent;
	var isWFirefox = false;
	if (agent.indexOf("IE") == -1 && agent.indexOf("Windows") != -1 ) isWFirefox = true;
	if (isWFirefox) {
		return "1";
	}else{
		return "0";
	}
}

function embedFlash(){
	var isWF = isWindowsFirefox();
	var query = location.search.substring(1);
	var movie_path = _MOVIEPATH + '?random='+Math.random(1000) + query;

	so = new SWFObject(movie_path, "flash", 998, 568, "8", "#ffffff");
    so.write("flashContent");

	main = document.getElementById('flashContent');
	resizeHandler();	
	window.onresize = resizeHandler;
}


/*
*	RESIZE STUFF
*/




var b = navigator.userAgent.toLowerCase();

// Figure out what browser is being used
var browser = {
		safari: /webkit/.test(b),
		opera: /opera/.test(b),
		msie: /msie/.test(b) && !/opera/.test(b),
		mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
};

// Check to see if the W3C box model is being used
var boxModel = browser.msie || document.compatMode == "CSS1Compat";




function getDocumentWidth(){
	return window.innerWidth || boxModel && document.documentElement.clientWidth || document.body.clientWidth;
}

function getDocumentHeight(){
	return window.innerHeight || boxModel && document.documentElement.clientHeight || document.body.clientHeight;
}




function resizeHandler(){
	if(_MOVIEWIDTH > getDocumentWidth() || _MOVIEHEIGHT > getDocumentHeight()){
		//alert('?');
		main.style.position = 'absolute';
		main.style.top = 0;
		main.style.left = 0;
		if(_MOVIEWIDTH > getDocumentWidth()) main.style.marginLeft = '0';
		else main.style.marginLeft = ((getDocumentWidth() - Math.floor(_MOVIEWIDTH) - 20) / 2) + 'px';
		main.style.marginTop = '0';
	}
	else{	
		main.style.position = 'absolute';
		main.style.top = '50%';
		main.style.left = '50%';
		main.style.marginLeft = '-'+Math.floor(_MOVIEWIDTH / 2)+'px';
		main.style.marginTop = '-'+Math.floor(_MOVIEHEIGHT / 2)+'px';
	}
}





