var intval;
var online = false;
var img1 = new Image();
img1.src="images/ls_icon_on.png";
var img2 = new Image();
img2.src = "images/ls_icon_off.png";
function getObj(id)
{
	return document.getElementById(id);	
}

function init()
{
	if(!getObj("liveSupport"))
	{
		var live = document.createElement("div"); //for icon 
		var cv = live.cloneNode(false); //for support page
		var bg = live.cloneNode(false); // background div
		live.id = "liveSupport";
		live.className = "offlive";
		live.onclick = support;
		live.onmouseover = mover;
		live.onmouseout = mout;
		cv.id = "livePage";
		cv.className = "livePage";
		bg.id = "liveBack";
		bg.className = "livebg"
		document.body.appendChild(live);
		document.body.appendChild(bg);
		document.body.appendChild(cv);
	}
	var s = document.createElement("script");
	s.type = "text/javascript";
	s.src = "http://messenger.services.live.com/users/67f1817f64e1f92c@apps.messenger.live.com/presence/?cb=getState";
	document.body.appendChild(s);
}

//67f1817f64e1f92c    eng8
//1cbb483e13f126d1     ic
//43f786a3b035fb4d	  pig
function support()
{
	clearInterval(intval);
	getObj("liveSupport").style.display = "none";
	getObj("livePage").style.display = "block";
	getObj("liveBack").style.display = "block";
	var wid = document.documentElement.clientWidth;
	var hei = document.documentElement.clientHeight;
	if(online)
	{
		var str = '<iframe name="supportFrame" id="supportFrame" width="692" scrolling="no" height="620" style="overflow:hidden;" align="top" frameborder="0"	src="online.html?'+Math.random()+'" ></iframe>';
	}
	else
	{
		var str = '<iframe name="supportFrame" id="supportFrame" width="691" scrolling="no" height="622" style="overflow:hidden" align="top" frameborder="0"	src="offline.html?'+Math.random()+'" ></iframe>';	
	}
	getObj("livePage").innerHTML = str;
	getObj("liveBack").style.width = wid  + "px";
	getObj("liveBack").style.height = hei + "px";
}

function changebg()
{
	var obj=getObj("liveSupport");
	var pos = (obj.style.backgroundPosition.indexOf("top") != -1) ? "bottom" : "top" ;
	obj.style.backgroundPosition = pos;
}
function mover()
{
	this.style.backgroundPosition = "bottom";
}
function mout()
{
	this.style.backgroundPosition = "top";
}
function getState(info)
{
	var obj = getObj("liveSupport");
	online = info.statusText.toLowerCase() == "offline" ? false:true;
	obj.className = online ? 'onlive' : 'offlive';
	obj.style.display = "block";
	//intval = setInterval(changebg,1000);
}

function away()
{
	getObj("livePage").innerHTML = "";
	getObj("livePage").style.display = "none";
	getObj("liveSupport").style.display = "block";
	getObj("liveBack").style.display = "none";
	//intval = setInterval(changebg,1000);
}

$(document).ready(init); 