var timer;
function marquee(delay,liHeight,toAlign,lyorderID){
	var o=$(lyorderID);
	var timer_bug;
	if(!o.childNodes.length) return;
	for(i=0;i<o.childNodes.length;i++){
		if(o.childNodes[i].tagName==null){
			o.removeChild(o.childNodes[i]);
		}
	}
	if(o==null)return;
	function scrollup(o,h,d){
		if(d==h){
			var t=o.firstChild;o.appendChild(t);t.style.marginTop=o.firstChild.style.marginTop='0px';d=0;
		}else{
			var s=3,d=d+s,l=(d>=h?d-h:0);o.firstChild.style.marginTop=-d+l+'px';
			timer_bug=setTimeout(function(){scrollup(o,h,d-l)},20);
		}
	}
	timer=setInterval(function(){clearTimeout(timer_bug);scrollup(o,liHeight,toAlign);},delay);
}

var openShow=false;
function show_chat_div(obj){
	if(openShow){close_chat_div();return;}
	openShow=true;
	var name=obj.getAttribute("title");
	var msn=obj.getAttribute("msn");
	var skype=obj.getAttribute("skype");
	var email=obj.getAttribute("email");
	var yahoo=obj.getAttribute("yahoo");
	var aim=obj.getAttribute("aim");
	var str="";
	str+="<ul class='gray_trangle_list'>";
	if(email!=null&&email!=""){str+="<li><span class='big black b'>Email</span><BR/> <span class='p_le_15'><a href='mailto:"+name+"<"+email+">' title='Send an email to "+name+"'>"+email+"</a></span></li>";}
	if(msn!=null&&msn!=""){str+="<li><span class='big black b'>MSN</span><BR/> <span class='p_le_15'><a href='"+getMsgHref('msn', msn, name)+"' title='Chat with "+name+" by MSN'>"+msn+"</a></span></li>";}
	if(skype!=null&&skype!=""){str+="<li><span class='big black b'>SKYPE</span><BR/> <span class='p_le_15'><a href='"+getMsgHref('skype', skype, name)+"' title='Chat with "+name+" by SYKPE'>"+skype+"</a></span></li>";}
	if(yahoo!=null&&yahoo!=""){str+="<li><span class='big black b'>YAHOO</span><BR/> <span class='p_le_15'>"+yahoo+"</span></li>";}
	str+="</ul>";
	Element.update('div-chat-info', str);
	Element.show('div-chat');
	clearInterval(timer);
	hide_select('in');
}
function close_chat_div(){
	Element.hide('div-chat');
	marquee(3000,15,0,'div-chat-list');
	hide_select("out");
	openShow=false;
}

function hide_select(what){
	var anchors=document.getElementsByTagName("select");
	if(what=="in"){
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].getAttribute("rel")=="dropdown"){
				anchors[i].style.visibility="hidden";
			}
		}
	}else{
		for(var i=0;i<anchors.length;i++){
			if(anchors[i].getAttribute("rel")=="dropdown"){
				anchors[i].style.visibility="visible";
			}
		}
	}
}

getMsgHref = function(type, account, name){

	flag = checkInstalled(type);
	switch(type){
		case 'msn':
			if(flag){
				return 'msnim:chat?contact='+account;
			}else{
				return 'javascript:(function(){if(confirm("Install MSN now ?\\n\\nThen you can chat online with '+name+' .")){window.open("http://www.msn.com","newwin");}})()';
			}
		case 'skype':
		 if(flag){
			 return 'skype:'+account+'?chat';
		 }else{
			 return 'javascript:(function(){if(confirm("Install SKYPE now ?\\n\\nThen you can chat online with '+name+' .")){window.open("http://download.skype.com/share/skypebuttons/oops/oops.html","newwin");}})()';
		 }
	}
};
checkInstalled = function(m) {
	switch(m){
		case 'msn':
			try {
				new ActiveXObject("MSNMessenger.P4QuickLaunch");
				return true;
			}
			catch (e) {
				return false;
			}			
		case 'skype':	
			try{
				new ActiveXObject("Skype.Detection");
				return true;
			}catch(e){
				return false;
			}
		case 'qq':
      try {
				new ActiveXObject("TimwpDll.TimwpCheck");
				return true;
      }
      catch (e) {
				return false;
      }
	}
}


