var flashPlayer;
function initialize() {
	/*
	 * Check if the browser is IE. If so, flashVideoPlayer is
	 * window.videoPlayer. Otherwise, it's window.document.videoPlayer. The
	 * videoPlayer is the id assigned to <object> and <embed> tags.
	 */
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	flashPlayer = (ie) ? window['ihome'] : document['ihome'];
}

var message = ["★★★ 您有", "★☆★ 新的", "☆☆☆ 消息"];
var speed = 300;  
var doLoop = false;
var lastTimeoutId = 0;
var popupTimeoutId = 0;
var originalTitle = document.title;
var msgtype = 0;

function startNotify(user, message, _msgtype)
{
	msgtype = _msgtype;
	doLoop = true;
	if (lastTimeoutId != 0) {
		window.clearTimeout(lastTimeoutId);
	}
	if (popupTimeoutId != 0) {
		window.clearTimeout(popupTimeoutId);
	}
	changeTitle(0);
	try {
		popupMessage(user, message);
	}
	catch (e){}
}

function stopNotify()
{
	doLoop = false;
	window.clearTimeout(lastTimeoutId);
	try {
		hidePopup();
	}
	catch (e){}
	lastTimeoutId = 0;
	popupTimeoutId = 0;
	top.document.title = originalTitle;
}

function changeTitle(loop) {
	lastTimeoutId = 0;
	if (!doLoop) {
		return;
	}
	top.document.title = message[loop];
	window.status = document.title;
	
	if (++loop == message.length) {
		loop = 0;
	}
	if (doLoop) {
		lastTimeoutId = setTimeout(function() { changeTitle(loop); }, speed);
	}
}

function forTest()
{
	top.document.title = new Date();
	window.status = document.title;
	try {
		popupMessage("你好，你有新的短消息，请查收");
	}
	catch (e){}
}

try
{
	var oPopup = window.createPopup();
}
catch (e){}

String.prototype.length2 = function() {
    var cArr = this.match(/[^\x00-\xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
} 

var msgimg_width = 229;
var msgimg_height = 133;

var popTop = 20;
function popupMessage(user, message) {
	var content = '<div style="position: absolute;left:10px;top:22px;cursor:pointer;WIDTH: 150px; HEIGHT: 120px;" onClick="parent.hidePopupAndPopDialog()">'+getUser(user)+'</div><div style="position: absolute;left:17px;top:45px;cursor:pointer;WIDTH: 110px; HEIGHT: 120px;" onClick="parent.hidePopupAndPopDialog()">'+getMsg(message)+'</div><DIV style="WIDTH: 229px; HEIGHT: 133px;cursor:pointer;"><map name="FPMap0"><area  shape="circle" coords="148, 11, 10" onClick="parent.hidePopup()"><area  shape="rect" coords="4,12,159,85" onClick="parent.hidePopupAndPopDialog()"></map><img src="/ihomestatics/cn/images/mail.gif" border="0" usemap="#FPMap0" width="229" height="133" /></DIV>';
	oPopup.document.body.innerHTML = content;
	showPopup();
}
function showPopup() {
	if(popTop>1000) {
		hidePopup();
		return;
	}else if(popTop<msgimg_height){
		oPopup.show(screen.width-250, screen.height, msgimg_width, popTop);
	}else if (popTop>=msgimg_height && popTop<120) {
		oPopup.show(screen.width-250, screen.height-popTop-45, 160, msgimg_height);
	}else if (popTop>=880 && popTop<1000-msgimg_height) {
		oPopup.show(screen.width-250, screen.height+955-popTop, msgimg_width, 1000-popTop);
	}else if(popTop>=1000-msgimg_height && popTop<1000) {
		oPopup.show(screen.width-250, screen.height, msgimg_width, 1000-popTop);
	}
	popTop += 10;
	popupTimeoutId = setTimeout("showPopup();", 20);
}

function getUser(user){
	if (user.length > 9)
	{
		user = user.substr(0,9);
	}
	return "<span style='color:#DE7426; font-size: 13px;'>" + user + "说:</span>";
}

function getMsg(message){
	if (message.length > 16)
	{
		message = message.substr(0,16)+"...";
	}
	return "<span style='color:#CC3333; font-size: 12px;'>" + message + "</span>";
}

function hidePopup()
{
	window.clearTimeout(popupTimeoutId);
	popupTimeoutId = 0;
	oPopup.hide();
	popTop = 20;
}

function hidePopupAndPopDialog()
{
	document.body.focus();
	hidePopup();
	openMessageDialog();
}

function openMessageDialog(){
	flashPlayer.__openMyMsgs(msgtype);
}

function ihome_refresh() {
	var addre = window.location.href;
	var newAddre = "";
	if (addre.indexOf("&go=true") != -1)
	{
		newAddre = addre.substr(0, addre.indexOf("&go=true"))+"&go=false";
	}else if (addre.indexOf("http://ihome.1001m.com/ihomestatic/riji163/ihomelogin.ihm") != -1)
	{
		newAddre = "http://riji.163.com/";
	}else{
		newAddre = "http://www.1001m.com/";// addre;
	}
	window.location.href = newAddre;
}


if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else {
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; 
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = null;
			}
		}
	}
}
if (typeof window.onunload == 'function') {
	var oldunload = window.onunload;
		window.onunload = function() {
		deconcept.SWFObjectUtil.cleanupSWFs();
		oldunload();
	}
} else {
	window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; 
var SWFObject = deconcept.SWFObject;
function openNewWindow(URLtoOpen, windowName, windowFeatures){ 
	newWindow=window.open(URLtoOpen, windowName, windowFeatures);
	newWindow.focus();
}

var ihomehrefstr = window.location.href;
if ( window != window.top ) {
try{
	ihomehrefstr = window.top.location.href;	
}catch(e){}
}

function loadMovie(server){
	var search = window.location.search;
	if ( window != window.top ) {
		try{
			search = window.top.location.search;	
		}catch(e){}	
	}	
	if (typeof(addparm) != 'undefined'){
		if (search.indexOf("?") != -1){
			search += "&"+addparm;
		}else{
			search += "?"+addparm;
		}
	}
	search = search.replace(/fromid=[0-9]+&*/i,'');	
	var width = "970";
	var height = "540";
	
	if (typeof(stageSize) != 'undefined') {
		var a = stageSize.split(":");
		width = a[0];
		height = a[1];
	}
	var fo = new SWFObject(server+main_swf_name+search, "ihome", width, height, "9.0.28" ,"ffffff",false,"high","http://ihome.1001m.com","http://ihome.1001m.com/updateFlashPlayer.html");
	fo.addParam("menu","false");
	if (typeof(config) != 'undefined')
		fo.addVariable("config", config);
	if (typeof(background) != 'undefined')
		fo.addVariable("background", background);		
	fo.addVariable("appserver",server);	
	fo.addVariable("ihomehrefstr",ihomehrefstr);
	if (typeof(client) != 'undefined')
		fo.addVariable("client", client);
	fo.addParam("allowFullScreen", "true");
	fo.addParam("allowScriptAccess", "true");
	fo.addParam("scale","noscale");
	fo.addParam("salign","TL");	
	if (typeof(stageSize) == 'undefined' && (window.screen.height >= 768 || window.screen.width >=1024))
	{
	   fo.setAttribute("width", "100%");
	   fo.setAttribute("height", "100%");
	}
	fo.write("ihomecontent");
	setCookie("5519810215", "xadwciwcuxmdus", "1001m.com"); // 为小窝设置cookie
	initialize();
}

function getCookie(name) {
	var prefix = name + "="
	var start = document.cookie.indexOf(prefix)
	if (start==-1) {
		return null;
	}
	var end = document.cookie.indexOf(";", start+prefix.length)
	if (end==-1) {
		end=document.cookie.length;
	}
	var value=document.cookie.substring(start+prefix.length, end)
	return unescape(value);
}

function setCookie(name,value,domain)
{
    var Days = 30;
    var exp  = new Date();    // new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";domain="+domain;
}


function setUrl(url){
	document.location.href = url;
}

// 添加到收藏夹代码---------------------------------------------
function addFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

// 刷新url
function refreshUrl(){
	try{
		window.top.location.reload();
	}catch(e){
		window.location.reload();
	}
}

function ihomeQuit() {
	try{
		var link = window.top.location.href;
		window.top.location.href = link.substring(0,link.indexOf('.com')+4);		
	}catch(e){
		var link = window.location.href;
		window.location.href = link.substring(0,link.indexOf('.com')+4);		
	}
}

// 信息调用接口
function jsCallingDispatcher(functionName) {
	var args = [];
	if ( arguments.length > 1 ) {
		args = [].slice.call(arguments,1);
	}
	
	// ////////////////////////////////////
	try {
		console.debug("ActionScript calling : " + functionName);
		console.debug("arguments : " + args);
	} catch (err) {}
	// ////////////////////////////////////
	
	if ( window.top == window ) {
		return false;
	}
	var right = window.top.rightFrame;
	if ( right && right[functionName] ) {
		return right[functionName].apply(right, args);
	}
	var iRight = right.frames[0];
	if ( iRight && iRight[functionName] ) {
		return iRight[functionName].apply(iRight, args);
	}
}

document.write("<div id='ihomecontent'></div>");
loadMovie("/");
