/*
Project Name:Gfan.com
Developed By:poyue
Date Created:2010 06 25
Last Updated:2010 12 09 16:50
Copyright:mAPPn
*/

try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}//IE6 缓存
var doc=document;
var ie=document.all;
var $id = function(id){return "string" == typeof id ? doc.getElementById(id) : id};
var forEach=function(array,callback,thisObject){if(array.forEach){array.forEach(callback,thisObject);}else{for(var i=0,len=array.length;i<len;i++){callback.call(thisObject,array[i],i,array);}}}
var $tag= function(tag,id){if(id){return id.getElementsByTagName(tag)}else{return doc.getElementsByTagName(tag)}};
var setCss=function(el,css){if(ie){el.style.cssText=css}else{el.setAttribute("style",css)}};
var hide=function(el){el.style.display="none"};
var show=function(el){el.style.display=""};
var bindEvent=function(elem,type,fn){if(elem.attachEvent){var typeRef="_"+type;if(!elem[typeRef]){elem[typeRef]=[];}for(var i in		elem[typeRef]){if(elem[typeRef][i]==fn){return;}}elem[typeRef].push(fn);elem["on"+type]=function(){for(var i in this[typeRef]){this[typeRef][i].apply(this,arguments);}}}else{elem.addEventListener(type,fn,false);}};
var removeEvent=function (elem,type,fn){if(elem.detachEvent){if(elem["_"+type]){for(var i in elem["_"+type]){if(elem["_"+type][i]==fn){elem["_"+type].splice(i,1);break;}}}}else{elem.removeEventListener(type,fn,false);}};
var $ready=(function(){var load_events=[],load_timer,script,done,exec,old_onload,init=function(){done=true;clearInterval(load_timer);while(exec=load_events.shift())exec();if(script)script.onreadystatechange='';};return function(func){if(done)return func();if(!load_events[0]){if(document.addEventListener)document.addEventListener("DOMContentLoaded",init,false);if(/WebKit/i.test(navigator.userAgent)){load_timer=setInterval(function(){if(/loaded|complete/.test(document.readyState))init();},10);}old_onload=window.onload;window.onload=function(){init();if(old_onload)old_onload();};}load_events.push(func);}})();
var DOMReady=(function(){var load_events=[],load_timer,script,done,exec,old_onload,init=function(){done=true;clearInterval(load_timer);while(exec=load_events.shift())exec();if(script)script.onreadystatechange='';};return function(func){if(done)return func();if(!load_events[0]){if(document.addEventListener)document.addEventListener("DOMContentLoaded",init,false);if(/WebKit/i.test(navigator.userAgent)){load_timer=setInterval(function(){if(/loaded|complete/.test(document.readyState))init();},10);}old_onload=window.onload;window.onload=function(){init();if(old_onload)old_onload();};}load_events.push(func);}})();

var stopDefault=function (e) {if ( e && e.preventDefault )e.preventDefault();else{window.event.returnValue = false}return false;} ;
var Tween={Quart: {easeOut: function(t,b,c,d){return -c * ((t=t/d-1)*t*t*t - 1) + b;}},Back: {easeOut: function(t,b,c,d,s){if (s == undefined) s = 1.70158;return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;}},Bounce: {easeOut: function(t,b,c,d){if ((t/=d) < (1/2.75)) {return c*(7.5625*t*t) + b;} else if (t < (2/2.75)) {return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;} else if (t < (2.5/2.75)) {return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;} else {return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;}}}};
var triggerC=function(el){if(document.all) {el.click();}else{var evt = doc.createEvent("MouseEvents"); evt.initEvent("click",true,true);el.dispatchEvent(evt);};};
var MoveTo=function(o,p,b,e,d){var b,e,d=d||50,t=0;c=e-b;function start(){if(p=="opacity"){if(ie){o.style.filter="alpha(opacity="+Math.round(Tween.Quart.easeOut(t,b,c,d))+")";}else{o.style.opacity=0.01*Math.round(Tween.Quart.easeOut(t,b,c,d));}if(t<d){t++; moveStart=setTimeout(start,10)}}else{o.style[p]=Math.round(Tween.Quart.easeOut(t,b,c,d))+"px";if(t<d){t++; moveStart=setTimeout(start,10)};}}start();}
var Extend = function(destination, source) {for (var property in source) {destination[property] = source[property];}return destination;}

var key=1;

var GFan={

	sortHover:function(){
		if($id("sort")){
			var sortLeft=$id("sort_left").getElementsByTagName("a");
			var sortRight=$id("sort_right").getElementsByTagName("ul");
			var sLength=sortLeft.length;
		
			for(i=0;i<sLength;i++){
				sortLeft[i].index=i;
				sortLeft[i].onmouseover=function(){
					this.style.color="#333333";	
				};
				sortLeft[i].onmouseout=function(){
					this.style.color="#A09F9F";
				};
				sortLeft[i].onclick=function(){
					key=this.index;
					for (k=0;k<sLength;k++){
						sortRight[k].style.display="none";
						sortLeft[k].className="hi";
					}
					sortRight[this.index].style.display="block";
					this.className="current";
					if(this.index>0){sortLeft[this.index-1].className="pre";}
					return false;
				};
			}
		}
		
	},
	Show:function(n,target,nur,el){
		var holder=el.parentNode.getElementsByTagName("a");
		for(i=0;i<nur;i++){
			$id(target+i).style.display="none";
			holder[i].className="hi"
		}
		$id(target+n).style.display="block";
		el.className="orange";
		
	},//endShow
	cShow:function(){

		function run(){
			var nur=$id("tip_key").getAttribute("nur");
			if(key>1&&key<nur){
				$id("star_pre").style.background='url("/templets/gfan/css/images/more_2.png") no-repeat  0 -12px';
				$id("star_next").style.background='url("/templets/gfan/css/images/more_2.png") no-repeat -12px 0';
			}

			else if(key==1){$id("star_pre").style.background='url("/templets/gfan/css/images/more_2.png") no-repeat 0 0';}
			else if(key==nur){$id("star_next").style.background='url("/templets/gfan/css/images/more_2.png") no-repeat -12px -12px';}

			$id("tip_key").innerHTML=key;
			
			for(i=0;i<nur;i++){
				var temp="star_"+(i+1);
				$id(temp).style.display="none";
				$id("star_"+key).style.display="block";
			}
				
		};//run()
			
			if($id("star_pre")){
				$id("star_pre").onclick=function(){
					if(key>1){
						key--;
						run();
						return false;
					}
				};
				$id("star_next").onclick=function(){
					if(key<3){
						key++;
						run();
						return false;
					}
				};
			}
		
	},//cShow
	allLink:function(){
		if($id("link_box")){
			$id("link_box").onmouseover=function(){
					$id("link_box").className="hi";	
			}
			$id("link_box").onmouseout=function(){
					$id("link_box").className="h60";	
			}
		}
	
	}

}//endGFan

function navJudge(){
	var nav_bottom =$id("nav_bottom").getElementsByTagName("a");
	var pageUrl=location.href;
	if(pageUrl.indexOf("market")!=-1){nav_bottom[1].className="current"}
	else if(pageUrl.indexOf("news")!=-1){nav_bottom[2].className="current"}
	else if(pageUrl.indexOf("app")!=-1){nav_bottom[3].className="current"}
	else if(pageUrl.indexOf("media")!=-1){nav_bottom[4].className="current"}
	else if(pageUrl.indexOf("mobilegame")!=-1){nav_bottom[5].className="current"}
	else{nav_bottom[0].className="current"}}


var Album_p=function(tomove,options) {
	this.index=0;
	this.tomove=tomove;
	this.tomoveType="li";
	this.tomoveList=$tag(this.tomoveType,tomove);
	this.tomoveNur=this.tomoveList.length;
	this.SetOptions(options);
	this.direction=this.options.direction;
	this.pause=this.options.pause;
	this.ifNurList=this.options.ifNurList;
	this.aTime=this.options.aTime;
	this.nurListName=this.options.nurListName;
	this.change=this.options.change;
	this.timer1=null;
	this.timer2=null;
	this.timer3=null;
}

 Album_p.prototype = {
	SetOptions: function(options) {
		this.options = {
		direction: "left",
		pause: 5000,
		ifNurList:"open",
		nurListName:"nur_1208",
		aTime:50,
		change:200
		};
	Extend(this.options, options || {});
	},
	turnTo:function(o,dir,index,c,aTime){
		var end=-1*index*c;
		if(dir=="left"){var current=o.offsetLeft;}
		if(dir=="top"){var current=o.offsetTop;}
		var MoveTo=function(o,p,b,e,d){var b,e,d=d||50,t=0;c=e-b;function start(){if(p=="opacity"){if(ie){o.style.filter="alpha(opacity="+Math.round(Tween.Quart.easeOut(t,b,c,d))+")";}else{o.style.opacity=0.01*Math.round(Tween.Quart.easeOut(t,b,c,d));}if(t<d){t++; moveStart=setTimeout(start,10)}}else{o.style[p]=Math.round(Tween.Quart.easeOut(t,b,c,d))+"px";if(t<d){t++; this.timer3=setTimeout(start,10)};}}start();}
		MoveTo(o,dir,current,end,aTime);
	},
	autoRun:function(){
		var that=this;
		var tomove=that.tomove;
		var turnTo=that.turnTo;
		var tomoveNur=that.tomoveNur;
		var d=that.direction;
		var t=that.pause;
		var ifNurList=that.ifNurList;
		var nurListName=that.nurListName;
		var c=that.change;
		var aTime=that.aTime;

		var run=function(){ 
				if(that.index<tomoveNur-1){
					that.index++;	
				}
				else{that.index=0;}
				turnTo(tomove,d,that.index,c,aTime);
				if(ifNurList=="open"){
					var nurList=$tag("a",$id(nurListName));
					for(i=tomoveNur;i--;){
						nurList[i].className="";
					}
					nurList[that.index].className="current";
					
				}
				that.timer1=setTimeout(run,t);
				
			}
			that.timer2=setTimeout(run,t);
		},//run
	nurList:function(){
		var that=this;
		var nur=that.tomoveNur;
		var h="";
		var n=that.nurListName;
		for(i=nur;i--;){
			h+='<a href="###"></a>';
		}
		$id(n).innerHTML=h;
		var nurList=$tag("a",$id(that.nurListName));
		nurList[0].className="current"
	},
	nurListAction:function(){
		var that=this;
		var tomove=that.tomove;
		var nurList=$tag("a",$id(that.nurListName));
		var tomoveNur=that.tomoveNur;
		var turnTo=that.turnTo;
		var d=that.direction;
		for(i=tomoveNur;i--;){
			var c=that.change;
			var aTime=that.aTime;
			nurList[i].setAttribute("key",i);
			nurList[i].onclick=function(e){
				stopDefault(e);
				clearTimeout(that.timer1);
				clearTimeout(that.timer2);
				that.index=this.getAttribute("key");
				var key=this.getAttribute("key");
				turnTo(tomove,d,key,c,aTime);
					for(k=tomoveNur;k--;){
						nurList[k].className="";
					}
					nurList[key].className="current";
			}

			nurList[i].onmouseout=function(){
			clearTimeout(that.timer1);
			clearTimeout(that.timer2);
			that.autoRun();

			}
		
		}
	
	}
 }




function to_1208_outer(){
	 if($id("to_1208")){
		var to_1208=new Album_p($id("to_1208"),{change:200});
		to_1208.nurList();
		to_1208.autoRun();
		to_1208.nurListAction();
		setCss($id(to_1208.nurListName),"width:"+to_1208.tomoveNur*15+"px");
	 } 
}
function ad_1209_outer(){
	 if($id("ad_1209")){
		var ad_1209=new Album_p($id("ad_1209"),{direction:"top",change:100,ifNurList:"close",aTime:20,pause:10000});
		ad_1209.autoRun();
	 } 
}



DOMReady(navJudge);
DOMReady(to_1208_outer);
DOMReady(ad_1209_outer);
