/**
 * @author Mousebomb
 */
$(document).ready(function(){
	if(getSearch()=="noflash")
	{
		noFlash();
		return;
	}else{
		$("#noflash").hide();
		$("#err .js").hide();
		$("#err .fp10").hide();
		fpver = flpVer();
		if(fpver>=9)
		{
			WSWFobj("100%", "100%", 'SiteLoader.swf', ['allowScriptAccess','wmode'], ['always','window'], 'flashContainer', 'mainFlash');
			confSize();
			defTitle = "鼠标炸弹 - Mousebomb 2009";
			curHash = getHash();
			setInterval(checkHashChange,50);
		}else{
			$("#err .fp10").show();
			$("#err .fp10 span").html(fpver);
		}
	}
});

$(window).resize(function(){
    confSize();
});

$(window).scroll( function()
	{
		try{thisMovie('mainFlash').onScrollTopChange($(window).scrollTop()); }catch(err){}
	}
);

function noFlash()
{
		//保持noflash的显示,隐藏其他所有内容
		$("#flashContainer").hide();
		$("#noflash").show();
}

var minW = 984;
var minH = 550;
var fpver=0;
function confSize(){
    var w = $(window).width();
    var h = $(window).height();
    if (w < minW) 
    {
		w = minW;
		$("#wrap").width(w);
	}else{
		$("#wrap").width("100%");
	}
    if (h < minH) 
	{
        h = minH;
	}
	$("#wrap").height(h);
	$("#mainFlash").height(h);
}

//---API4Flash
//size setter
function setMinSize(w, h){
    minW = w;
    minH = h;
	confSize();
}
//size getter
function getClientHeight(){
    return $(window).height();
}
function getClientY(){
    return $(window).scrollTop();
}

//deeplink

//默认标题,setHash后恢复标题
var defTitle;
//记录当前hash
var curHash;

function getHash() {
   var idx = document.location.href.indexOf('#');
   return (idx >= 0) ? document.location.href.substr(idx+1) : '';
}
function getSearch() {
   var idx = document.location.href.indexOf('?');
   return (idx >= 0) ? document.location.href.substr(idx+1) : '';
}
function setHash(hash)
{
	if (hash == '') hash = '#';
    document.location.hash = hash;
	setTimeout(updateTitle,200);
	curHash=getHash();
}
function checkHashChange()
{
	var newHash = getHash();
	if(curHash != newHash)
	{
		//通知 Flash
		try{thisMovie('mainFlash').onHashChange(newHash);  }catch(err){}
	}
	curHash = newHash;
}
function updateTitle()
{
	document.title = defTitle;
}

