// JavaScript Document
function changeTabs(thisObj,num){
	if(thisObj.className=="active")
		return;
	var myTabId = thisObj.parentNode.id;
	var tabList = document.getElementById(myTabId).getElementsByTagName("li");
	for(i=0;i<tabList.length;i++)
	{
		if(i==num)
		{
			thisObj.className = "active";
			document.getElementById(myTabId + "_" + i).style.display = "";
		}else{
			tabList[i].className = "normal";
			document.getElementById(myTabId + "_" + i).style.display = "none";
		}
	}
}

function addCookie(){
	if (document.all){
		window.external.addFavorite('http://www.myliwu.com','买礼网－选礼就上买礼网，礼多多利多多！');
    }else if (window.sidebar){
		window.sidebar.addPanel('买礼网－选礼就上买礼网，礼多多利多多！', 'http://www.myliwu.com', "");
	}
	return false;
}

function setHomepage(){
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.myliwu.com');
	}else if (window.sidebar){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch (e){
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
         	}
    	}
    	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    	prefs.setCharPref('browser.startup.homepage','http://www.myliwu.com');
	}
	return false;
}

function setHeights(){
	var compare = new Array();
	for(var i=0; i<arguments.length; i++){
		var element = arguments[i];
		compare.push(element)
	}
	var maxHeight = 0;
	for(var j=0; j<compare.length; j++){
		if(!document.getElementById(compare[j])) continue;
		document.getElementById(compare[j]).style.height = 'auto';
		var newHeight = document.getElementById(compare[j]).offsetHeight;
		if(newHeight >maxHeight)
			maxHeight = newHeight
	}
	for(var r=0; r<compare.length; r++){
		if(document.getElementById(compare[r]))
		document.getElementById(compare[r]).style.height = maxHeight + 'px';
	}
}

function simplescroll(c, config) {
	this.config = config ? config : {start_delay:30, speed: 30, delay:30, scrollItemCount:1};
	this.container = document.getElementById(c)
	this.pause = false;
	var _this = this;
	
	this.init = function() {
		_this.scrollTimeId = null;
		setTimeout(_this.start, _this.config.start_delay);
	}
	
	this.start = function() {
		var d = _this.container;
		var liNum = d.getElementsByTagName('li');
		if(liNum.length == 0)	return false;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		if(d.scrollHeight-d.offsetHeight>=line_height);
		_this.scrollTimeId = setInterval(_this.scroll,_this.config.speed);
	};
	
	this.scroll = function() {
		if(_this.pause)return;
		var d = _this.container;
		d.scrollTop+=2;
		var line_height = d.getElementsByTagName('li')[0].offsetHeight;
		if(d.scrollTop%(line_height*_this.config.scrollItemCount)<=1){
			d.scrollTop=0;
			for(var i=0;i<_this.config.scrollItemCount;i++){
				d.appendChild(d.getElementsByTagName('li')[0]);
			}
			clearInterval(_this.scrollTimeId);
			setTimeout(_this.start,_this.config.delay);
		}
	}
	
	this.container.onmouseover=function(){_this.pause = true;}
	this.container.onmouseout=function(){_this.pause = false;}
}

function scrollfun(){
	var div = new simplescroll('hotList', {start_delay:10, speed:10, delay:3000, scrollItemCount:2});
	var div2 = new simplescroll('hotList2', {start_delay:10, speed:10, delay:3000, scrollItemCount:2});
	var div3 = new simplescroll('hotList3', {start_delay:10, speed:10, delay:3000, scrollItemCount:2});
	div.init();
	div2.init();
	div3.init();
}

function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
 	}
}

addLoadEvent(scrollfun);