// JavaScript Document
atv = {};
$(document).ready(function(){
// Loop through initalitation object
for(var i in atv.init){
atv.init[i]();
}
});
atv.init = {};
atv.nav = {};
atv.nav.focusDropdown = false;
atv.nav.open = function(){
var preSlideHeight = $("#ziwai-nav .products .dropdown").height();
$("#ziwai-nav .products .dropdown").css("height", "0px").css("top", "40px").stop().animate({
height: preSlideHeight
}, 200, function(){
$(this).addClass("open");
});
}
atv.init.nav = function(){
var dropdown = $("#ziwai-nav .products .dropdown");
var preSlideHeight = dropdown.height();
$("#ziwai-nav .products a.products").click(function(){return false;}).parent().hoverIntent({    
sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
interval: 200, // number = milliseconds for onMouseOver polling interval    
timeout: 0, // number = milliseconds delay before onMouseOut
over: function(){
if(!dropdown.hasClass("open")){
dropdown.css("height","0px").css("top","40px").stop().animate({height:preSlideHeight},200,function(){
$(this).addClass("open");
});
}
},
out:function(){
if(!atv.nav.focusDropdown){
$("#goproducts").blur();
if(dropdown.hasClass("open")){
dropdown.stop().animate({height:0},200,function(){
$(this).css("height",preSlideHeight).css("top","-1000px").removeClass("open");
});
}
}
}
});
$("#goproducts").change(function(){
location.href = "/"+atv.urlprefix+"product/"+$(this).val()+"/";
}).focus(function(){
atv.nav.focusDropdown = true;
}).blur(function(){
//setTimeout("atv.nav.focusDropdown=false;",200);
setTimeout(function(){atv.nav.focusDropdown=false;},200);
}).mouseout(function(){
//setTimeout("atv.nav.focusDropdown=false;",200);
setTimeout(function(){atv.nav.focusDropdown=false;},200);
});
};
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// fcu pic
var myFocus={
$:function(id){return document.getElementById(id);},
$$:function(tag,obj){return (typeof obj=='object'?obj:this.$(obj)).getElementsByTagName(tag);},
easeOut:function(t,b,c,d){return -c*((t=t/d-1)*t*t*t - 1) + b;},
move:function(obj,dir,val,type,spd,fn){//位移函数，spd越大速度越小，即分更多的帧来完成，一般建议设置在dis值左右
var t=0,b=parseInt(obj.style[dir])||0,c=val-b,d=spd||50,st=type||'linear',m=c>0?'ceil':'floor';
if(obj[dir+'timer']) clearInterval(obj[dir+'timer']);
obj[dir+'timer']=setInterval(function(){
if(t<d){obj.style[dir]=Math[m](myFocus[st](++t,b,c,d))+'px';}
else {clearInterval(obj[dir+'timer']);fn&&fn.call(obj);}
},10);return this;
},
addList:function(obj,cla,arr){//生成HMTL列表部分,cla为生成列表的class,cla='txt'表示把图片alt生成其中的文字,cla='num'表示生成按钮数字
var s=[],n=this.$$('li',this.$$('ul',obj)[0]).length,num=cla.length;
for(var j=0;j<num;j++){
s.push('<ul class='+cla[j]+'>');
for(var i=0;i<n;i++){s.push('<li>'+(cla[j]=='num'?(i+1):(cla[j]=='txt'?this.$$('li',obj)[i].innerHTML.replace(/\<img.*?\>/i,this.$$('img',obj)[i].alt):''))+'<span></span></li>')};
s.push('</ul>');
}; obj.innerHTML+=s.join('');
},
setting:function(par){//设置DOM/文档加载就绪后执行的任务
if(window.attachEvent){window.attachEvent('onload',function(){myFocus[par.style](par)});}
　　		else{window.addEventListener('load',function(){myFocus[par.style](par)},false);}
},
//下面是风格样式(皮肤),格式mF_xxx(xxx是皮肤名字)
mF_qiyiNE:function(par){
var box=this.$(par.id),t=par.time*3000;//焦点图盒子、停留时间
box.removeChild(this.$$('div',box)[0]);
this.addList(box,['txt']);
box.innerHTML='<div class=box><div class=slide>'+box.innerHTML+'</div></div>';
this.addList(box,['num']);
//初始化HTML完毕,下面为相应对象作定义
var l = this.$$('img',box)[0].clientWidth,sde = this.$$('div',this.$$('div', box)[0])[0],n = this.$$('img', sde).length;
var txt = this.$$('ul', box)[1],tip = this.$$('li',txt),btn = this.$$('ul', box)[2],index = 0;
sde.style.width = l * n + 'px';
//表演开始
this.$$('li', btn)[index].className = 'current';
this.move(tip[index],'top',-34,'easeOut');
var run = function(idx) {
myFocus.$$('li', btn)[index].className = '';
if (index == n - 1) index = -1;
var N = idx != undefined ? idx: index + 1;
tip[N].style.top=0+'px';
myFocus.$$('li', btn)[N].className = 'current';
myFocus.move(sde, 'left', -l * N, 'easeOut',50,function(){myFocus.move(tip[N],'top',-34,'easeOut');});
index = N;
}
var auto=setInterval(function(){run()},t);
//下面为绑定交互事件
for (var j=0;j<n;j++){
this.$$('li',btn)[j].j=j;
this.$$('li',btn)[j].onmouseover=function(){if(!this.className) run(this.j)}
}
box.onmouseover=function(){clearInterval(auto);}
box.onmouseout=function(){auto=setInterval(function(){run()},t);}
}
};
//下面只是应用一款样式，更多焦点图样式&更多DIY修改请期待myFocus正式推出的那天^^
myFocus.setting({//第一款
style:'mF_qiyiNE',//风格样式
id:'myFocus',//焦点图ID
time:3//每帧的停留时间，单位秒
});
