﻿function qj(){//DOM common
	this.$=function(obj,tag){
		if(!tag){return document.getElementById(obj);}
		else if(typeof obj=='string'){return document.getElementById(obj).getElementsByTagName(tag);}
		else{return obj.getElementsByTagName(tag);}
	};	
	this.addEvent=function(obj,behave,fn){
		behave=behave.toLowerCase();
		if (behave.substr(0,2)=='on')behave=behave.substr(2);
		if(window.attachEvent){
			obj[behave+fn]=function(){fn.call(obj);}; 
			obj.attachEvent('on'+behave,obj[behave+fn]);
		}
		else if(window.addEventListener)obj.addEventListener(behave,fn,false);
		else obj['on'+behave]=function(){fn.call(obj);};
	};
    this.removeEvent=function(obj,behave,fn){
        behave=behave.toLowerCase();
        if (behave.substr(0,2)=='on')behave=behave.substr(2);
        if(window.detachEvent){
            obj.detachEvent('on'+behave,obj[behave+fn]);
            obj[behave+fn]=null;
        }
        else if(window.removeEventListener)obj.removeEventListener(behave,fn,false);
        else obj['on'+behave]=null;  
    }
	this.cc=function(obj,c){
		for(var i in c){
			if(typeof c[i]=="string"){obj[i]=c[i];}
			else{for(var n in c[i]){obj[i][n]=c[i][n]}}
		}
	};
	this.cTag=function(tag,c,fobj) {
		var obj=(typeof tag!="object")?document.createElement(tag):tag;
		if(c!="")this.cc(obj,c);
		if(!fobj){return obj;}
		else{fobj.appendChild(obj);}
	};
	this.NextTag=function(obj){
	   if(obj.nextSibling.nodeType==1)return obj.nextSibling;
	   else return obj.nextSibling.nextSibling;
	}
}
var qj=new qj();

 //右侧固定浮动窗口
    function winFloat(x){
	    if(!x.id||typeof x.id!="string")return false;
	    else { var obj=qj.$(x.id);}
	    var my=this;
	    this.fixed=function(){
		    if(!window.XMLHttpRequest){//IE6 特有的属性 if(!-[1,]) 所有IE才会执行
			    obj.style.cssText+="position:absolute;left:"+x.left+"px;";
			    var scrollTop_=function(){
				    var st=(document.documentElement&&document.documentElement.scrollTop)?document.documentElement.scrollTop:(document.body)?document.body.scrollTop:null;
				    obj.style.top=(st+158)+"px";
			    }
			    scrollTop_();
			    qj.addEvent(window,"onscroll",scrollTop_);
		    }
		    else{obj.style.cssText="position:fixed;top:"+x.top+"px;left:"+x.left+"px;"}
	    };
	    this.stopFixed=function(){
		    obj.style.cssText="";
	    };
	    qj.addEvent(window,"onscroll",function(){
		    if(document.documentElement.scrollTop>x.scrollTop)my.fixed();
		    else my.stopFixed();
	    });
    }
    
//搜索结果页 > 选项卡
function searchTab(x){
	var my=this
		,obj=qj.$(x.id)
		,objs=qj.$(obj,x.tags)
		,len=objs.length
		,fn=function(){
			for(var i=0;i<len;i++)objs[i].className=objs[i].cssName;
			my.val=x.url[this.temp];
			this.className+=" "+x.css;
			eval(x.fn+"(\""+my.val+"\")");
		};
	for(var i=0;i<len;i++){
		objs[i].temp=i;
		objs[i].cssName=objs[i].className;
		qj.addEvent(objs[i],"onclick",fn);
	}
	this.newData=function(n){
		if(!n)n="";
		for(var i=0;i<x.url.length;i++){
			if(x.url[i]==n)objs[i].className+=" "+x.css;
			else objs[i].className=objs[i].cssName;
		}
	}	
}
//搜索结果页 > 下拉菜单
function select(x){
	var obj=qj.$(x.id)
		,my=this
		,box
		,span=[]
		,colesBox;
	this.initia=function(){
		var pb=0; 
//		if(navigator.appVersion.split(";")[1].replace(/[ ]/g,"")=="MSIE7.0")pb="3px";		
		box=qj.cTag("span",{"style":{"cssText":"position:absolute;top:-999px;left:0;z-index:999;width:"+(x.width*2+6)+"px;padding:3px 0 "+pb+" 3px;background:#888;overflow:hidden;"}})
		for(var i=0;i<x.text.length;i++){
			var	width=(i==(x.text.length-1)&&x.text.length%2)?(x.width*2+3):x.width;
			span[i]=qj.cTag("span",{"style":{"cssText":"width:"+width+"px;float:left;height:18px;padding-top:4px;margin:0 3px 3px 0;font-size:12px;color:#6c6c6c;background:#e7e7e7;text-align:center;"},"innerHTML":x.text[i]},box);
		}
		qj.cTag(box,{},obj);
	}();
	this.on=function(){
	    qj.addEvent(obj,"onclick",function(){//click show use
			box.style.top=(box.style.top=="20px")?"-999px":"20px";
			if(x.id=="pageImg") obj.style.position="relative";
		});
//		qj.addEvent(obj,"onmouseover",function(){//over show use
//			box.style.top="20px";
//			//if(x.id=="pageImg") obj.style.position="relative";
//		});
		qj.addEvent(obj,"onmouseout",function(){
			colesBox=setTimeout(function(){box.style.top="-999px"},200);
		});
		qj.addEvent(obj,"onmouseover",function(){//alert("");
			clearTimeout(colesBox);
		});
		for(var i=0;i<x.text.length;i++){
			qj.addEvent(box.childNodes[i],"onclick",function(){
				box.style.top="-999px";
				qj.$(box.parentNode,"em")[0].innerHTML=(this.innerHTML=="全部尺寸")?"全部":this.innerHTML;
				var TempInnerHTML = this.innerHTML;
				if(x.id=="pageImg") TempInnerHTML = TempInnerHTML.replace("张","");
				if(x.id=="bgSelect") TempInnerHTML =(TempInnerHTML=="白色")?"0":"1";
				my.val=(TempInnerHTML=="全部尺寸")?"":parseFloat(TempInnerHTML);			
				eval(x.fn+"(\""+my.val+"\")");
			})
		}
	}();
	this.newData=function(n){
		if(!n||n=="")n="全部";
		else{
			if(x.id=="sizeImg")n+="M";
			else if(x.id=="bgSelect")
			{			
			    if(n=="1") n="黑色";
			    else n="白色";
			}
			else n+="张";
		}
		qj.$(box.parentNode,"em")[0].innerHTML=n;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
