/*********************************************************************************************************
This CS_ONLINE plugin was designed by jason.leung. Please feel free to contact me if any problems. Thanks.
You could link to shlzh1984.gicp.net to leave a message. Thank you for your support.
Email: 147430218@qq.com
SinaWeibo: @切片面包
*********************************************************************************************************/
// Public functions
function myEvent(obj,ev,fn)
{
	if(obj.attachEvent)
	{
		obj.attachEvent('on'+ev,fn);
	}
	else
	{
		obj.addEventListener(ev,fn,false);
	}
};
function getbyClass(oParent,sClass)
{
	var value=[];
	var tmp=oParent.getElementsByTagName('*');
	for (var i=0; i<tmp.length; i++)
	{
		if (tmp[i].className==sClass)
		{
			value.push(tmp[i]);
		}
	}
	return value;
};
function getStyle(obj,name)
{
	if (obj.currentStyle)
	{
		return obj.currentStyle[name];
	}
	else
	{
		return getComputedStyle(obj,false)[name];
	}
};
function startMoving(obj,json,fnEnd)
{
	clearInterval(obj.timer);
	obj.timer=setInterval(function()
	{
		var cur=0;
		var bStop=true;
		for (var attr in json)
		{
			if (attr == 'opacity')
			{
				cur=Math.round(parseFloat(getStyle(obj,attr))*100);
			}
			else
			{
				cur=parseInt(getStyle(obj,attr));
			}
			var speed=(json[attr]-cur)/5;
			speed=speed>0?Math.ceil(speed):Math.floor(speed);
			if (cur!=json[attr])bStop=false;
			if (attr == 'opacity')
			{
				obj.style.filter='alpha(opacity:'+cur+speed+')';
				obj.style.opacity=(cur+speed)/100;
			}
			else
			{
				obj.style[attr]=cur+speed+'px';
			}
		}
		if (bStop)
		{
			clearInterval(obj.timer);
			if (fnEnd)fnEnd();
		}
	}, 30);
}

// CS_ONLINE functions
myEvent(window,'load',function()
{
	var cs_online=document.getElementById('cs_online');
	var cs_type=document.getElementById('m_type').value;
	var cs_title=getbyClass(cs_online,'cs_title')[0];
	var second=3;				//Open this plugin automatically after 2 seconds later.
	var timer=null;	
	var opened;
	if(cs_type=="1"){
		opened=0;
	}
	else {
		opened=1;
	}
	cs_title.onclick=function ()
	{
		opened++;
		if (opened%2)
		{
			startMoving(cs_online,{right:-122});
		}
		else
		{
			startMoving(cs_online,{right:0});
		}
	}
});