var runLayer;
var body = document['CSS1Compat' == document.compatMode ? 'documentElement' : 'body'];

function writeRanikingTag(){
	var html ="";
	var rankingSwf = "swf/ranking.swf";
	html += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='100%' height='100%' id='aquaAll' align='middle'>";
	html += "<param name='allowScriptAccess' value='always' />";
	html += "<param name='movie' value='" + rankingSwf + "' /><param name='scale' value='noscale' /><param name='salign' value='lt' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#ffffff' /><embed src='" + rankingSwf + "' quality='high' scale='noscale' salign='lt' wmode='transparent' bgcolor='#ffffff' width='100%' height='100%' name='aquaAll' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	html += "</object>";
	runLayer = createRunLayer(html);
	/*$(function(){
        $('#ranking-swf').exFixed(); // for IE6
    });*/
}

function createRunLayer(html){
	var oLayer = document.createElement('div');
	oLayer.setAttribute('id','ranking-swf');
	oLayer.innerHTML = html;
	oLayer.style.position = 'absolute';
	oLayer.style.background = 'transparent';
	//
	var browser =checkBrowser() ;
	var XX=0;
	var YY=0;
	var WW;
	var HH;

	if(browser == "MSIE"){
		//XX = body.scrollLeft;
		//YY = body.scrollTop;
		WW = body.clientWidth;
		HH = body.clientHeight;
	}else {
		//XX = window.pageXOffset;
		//YY = window.pageYOffset;
		WW = window.innerWidth;
		HH = window.innerHeight;
	}

	var dX = 0;
	if(browser == "Netscape"){
		dX = -15;
	}

	if(browser == "Safari"){
		//YY -= 15;
	}

	oLayer.style.left =(XX + dX) + 'px';
	oLayer.style.height = HH + 'px';
	oLayer.style.width = WW + 'px';
	oLayer.style.top = YY + 'px';
	oLayer.style.zIndex = '1000';
	oLayer.style.display = 'block';
	return oLayer;
}

function runLayerResize(){
	if (document.getElementById("ranking-swf")) {
		var browser =checkBrowser() ;
			var XX;
			var YY;
			var WW;
			var HH;
			if(browser == "MSIE"){
				XX = body.scrollLeft;
				YY = body.scrollTop;
				WW = body.clientWidth;
				HH = body.clientHeight;
			} else {
				XX = pageXOffset;
				YY = pageYOffset;
				WW = window.innerWidth;
				HH = window.innerHeight;
			}
			document.getElementById("ranking-swf").style.height = HH + 'px';
			document.getElementById("ranking-swf").style.width = WW + 'px';
	}
}

function checkBrowser(){
	var uName = navigator.userAgent;
	if (uName.indexOf("Safari") > -1) return "Safari";
	if (uName.indexOf("MSIE") > -1) return "MSIE";
	if (uName.indexOf("Firefox") > -1) return "Firefox";
	return "Netscape";
}

function showRanking(){
	jQuery("html").css("overflow-y","hidden");
	document.getElementById('flashContent').style.display = 'none';
	document.getElementById('photoContent').style.display = 'block';
	writeRanikingTag();
	document.body.appendChild(runLayer);
	window.onresize = runLayerResize;
}

function hideRanking(){
	jQuery("html").css("overflow-y","scroll");
	document.getElementById('flashContent').style.display = 'block';
	document.getElementById('photoContent').style.display = 'none';	
	document.body.removeChild(runLayer);
}
