var flashStatus=false;
var avatarChange = false;
getElement = function(id) {
	var elem;
   if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[id];
	} else {
		if (document[id]) {
			elem = document[id];
		} else {
			elem = document.getElementById(id);
		}
		return elem;
	}
}
Comunicate= function() {
}

Comunicate.prototype.callMethod = function(param1, param2) {
	//alert($("guodongdev").id);
	getElement("guodongdev").callMethod(param1, param2);
}
var comunicateInstance = new Comunicate();

setImageUrls=function(url,modelId,zIndex,type){
	if(waitforamoment()) return;
	avatarChange = true;
	//if(Object.prototype.toString.apply(arr) === '[object Array]'){
		//alert(arr.length);
	//}else{
		arr = [url,modelId,zIndex,type];
		//alert(arr);
	//}
	//alert(arr);
	comunicateInstance.callMethod('setImageUrls',arr);
	var num = 	new Date().getTime();
    var rand = Math.round(Math.random() * 10000);
    num = num + rand;
	var url2 = _STATS_SITEURL+"itemhit.php?type=2D&itemid="+modelId+"&v="+num;
	var o=new GetJs(url2);
	o.init();
}

setMusicUrls=function(arr){
	if(waitforamoment()) return;
	avatarChange = true;
	if(Object.prototype.toString.apply(arr) === '[object Array]'){
		//alert(arr.length);
	}else{
		arr = arr;
	}
	//alert(arr);
	comunicateInstance.callMethod('setMusicUrls',[arr]);
}
setText=function(arr){
	if(waitforamoment()) return;
	avatarChange = true;
	if(Object.prototype.toString.apply(arr) === '[object Array]'){
		//alert(arr.length);
	}else{
		arr = [arr];
	}
	comunicateInstance.callMethod('setText',arr);
}
waitforamoment = function(){
	if(!flashStatus){
		top.mainFrame.AlertShow(300,"Flash加载中...请稍等!"); 
		return true;
	}
	return false;
}
setModelById=function(id,mtype){
	if(waitforamoment()) return;
	avatarChange = true;
	if(id){
	  comunicateInstance.callMethod('setModelById',[id]);
	   var num = 	new Date().getTime();
       var rand = Math.round(Math.random() * 10000);
       num = num + rand;
	  var url2 = _STATS_SITEURL+"itemhit.php?type="+mtype+"&itemid="+id+"&v="+num;
	  var o=new GetJs(url2);
	  o.init();
	}else{
	 alert('id is underfined');
	}
}
setAllModelsById=function(id){
	if(waitforamoment()) return;
	avatarChange = true;
   if(id>=0){
	   comunicateInstance.callMethod('setAllModelsById',[id]);
	   var num = 	new Date().getTime();
       var rand = Math.round(Math.random() * 10000);
       num = num + rand;
      var url2 = _STATS_SITEURL+"tjitemhit.php?itemid="+id+"&v="+num;
	  var o=new GetJs(url2);
	  o.init();
	}else{
	 alert('id is underfined');
	}
}

deleteRecordById=function(id){
	if(waitforamoment()) return;
	avatarChange = true;
   if(id){
	   comunicateInstance.callMethod('deleteRecordById',[id]);
	}else{
	 alert('id is underfined');
	}


}

noticeUserSignIn=function(){

	comunicateInstance.callMethod('noticeUserSignIn');
}
noticeUserSignOut=function(){

	comunicateInstance.callMethod('noticeUserSignOut');
}

checkInit = function(){
	flashStatus=true;
	top.mainFrame.closeAlert();
		if(Cookies.getCookie("ineedtoo")!='') {
			 setAllModelsById(0);
		}
	
}
saveUserInfo=function(s){
	if(waitforamoment()) return;
	if(Cookies.getCookie('IDOL_INFO')=='') {
		Cookies.setCookie("GO_ACTION",'saveUserInfo',0,"/",_COOKIE_DOMAIN);
		top.mainFrame.show_loginwin();
		return;
	}
	//alert(Cookies.getCookie('IDOL_INFO'));
	if(s=='autoSave'){
		Cookies.setCookie("GO_ACTION","autoSaveOk",0,"/",_COOKIE_DOMAIN);
	}
	try{
		//alert(123);
		comunicateInstance.callMethod('saveUserInfo');
	}catch(e){
		alert(e);
	}
}
setViewWH = function(width,height){
	if(waitforamoment()) return;
	var arr = [width,height];
	try{
		comunicateInstance.callMethod('setViewWH',arr);
	}catch(e){
		alert(e);
	}
}
saveView = function (){
	try{
		comunicateInstance.callMethod('saveView');
	}catch(e){
		alert(e);
	}
}
clearAll = function (type){
	if(waitforamoment()) return;
	try{
		comunicateInstance.callMethod('clearAll',[type]);
	}catch(e){
		alert(e);
	}
}
deleteDiy = function (str){
	if(waitforamoment()) return;
	try{
		comunicateInstance.callMethod('deleteDiy',[str]);
	}catch(e){
		alert(e);
	}
}
flashMessageJs = function (obj){
	var str="";
	//for(var item in obj)str+=item+"\n";
	obj = obj[0];
	switch(obj.type){
		case "function":
		this.func = eval(obj.fun)
		this.params = obj.params;
		break;
	}
	this.func(this.params);
}
function setMucic(){
	top.mainFrame.window.location.href="/index.php/show/music";
}
function maxActionTip(){
	top.mainFrame.AlertShow(300,"您已经达到最大动作数限制，请先删除再继续添加！");
}
function widgetPreview(x){
	//.swf?userId=kakapo&views=views
	show_view(x);
}
