//adang 2011-10-15 www.pcwaishe.net
(function(){
	Adang = {
		//收藏
		Collect : function(){
			var url = window.document.title, title  = "http://www.pcweishe.net/";
			try{
				window.external.addFavorite(url, title);
			}catch(e){
				try{
					window.sidebar.addPanel(url, title, "");
				}catch(e){
					alert("请使用 [ Ctrl+D ] 添加 [ " + url + " ] 至您的收藏夹！");
				}
			}
		}
	};
	//首页滚动
	Flash = {
		index : 0,
		ons   : 0,
		imgs  : null,
		title : null,
		spans : null,
		list  : function(){
			var uls = $("#FlashList"), lis = uls.find('li'),arr = [], title = [], spans = [], clas = "none";
			arr.push('<dl id="FlashTitle" class="Flash-txt"><dt>');
			for(var i = 0; i < lis.length; i++){
				if(i == 0){clas = "hover"}else{clas = "none"}
				title.push('<a class="' + clas + '" href="' + lis.eq(i).find('a').eq(0).attr('href') + '" target="_blank">' + lis.eq(i).find('img').eq(0).attr('alt') + '</a>');
			}
			arr.push(title.join(''));
			arr.push('</dt><dd>');
			for(var i = 0; i < lis.length; i++){
				if(i == 0){clas = "hover"}else{clas = "none"}
				spans.push('<span onclick="Flash.Margin(' + i + ')" class="' + clas + '">' + (i + 1) + '</span>');
			}
			arr.push(spans.join(''));
			arr.push('</dd></dl>');
			uls.after(arr.join(''));
			this.action(true);
		},
		action : function(){
			if(this.imgs === null){
				var dls = $("#FlashTitle");
				this.imgs = $("#FlashList ul").eq(0), this.title = dls.find("a"), this.spans = dls.find("span");
			}
			var moving,thas = this;
			//if(t === true){clearInterval(moving);}
			$("#AdangFlash").hover(function(){
				clearInterval(moving);
			},function(){
				moving = setInterval(function(){
					var field = thas.imgs.children('li'),
							k = field.innerHeight();
					thas.index++;
					thas.ons++;
					if(thas.ons >= thas.title.length){
						thas.ons = 0;
					}
					thas.title.attr("class","none");
					thas.title.eq(thas.ons).attr("class","hover");
					thas.spans.attr("class","none");
					thas.spans.eq(thas.ons).attr("class","hover");
					k = k * thas.index;
					thas.imgs.animate({
						marginTop : -k + 'px'
					},300,function(){
						var fi = thas.imgs.children('li').eq(0);
						if(thas.index == (thas.title.length - 1)){
							var h = field.innerHeight();
							fi.css({ "position":"relative","top" : (h * 5) + "px"});
						}else if(thas.index == thas.title.length){
							fi.removeAttr('style');
							thas.imgs.removeAttr('style');
							thas.index = 0;
						}
					});
				},8000);
			}).trigger('mouseleave');
			
		},
		Margin : function(t){
			var thas = this,
					field = thas.imgs.children('li'),
					k = field.innerHeight();
			thas.index = t;
			thas.ons = t;
			if(thas.ons >= thas.title.length){
				thas.ons = 0;
			}
			thas.title.attr("class","none");
			thas.title.eq(thas.ons).attr("class","hover");
			thas.spans.attr("class","none");
			thas.spans.eq(thas.ons).attr("class","hover");
			k = k * thas.index;
			thas.imgs.animate({
				marginTop : -k + 'px'
			},300,function(){
				var fi = thas.imgs.children('li').eq(0);
				if(thas.index == (thas.title.length - 1)){
					var h = field.innerHeight();
					fi.css({ "position":"relative","top" : (h * 5) + "px"});
				}else{
					fi.removeAttr('style');
				}
			});
		}
		
		
	};
})();
