(function(a){a.autoSlide=function(x){function na(){y=a("ul.submenu li:eq("+W+")");y.addClass("selectedSubItem");y.addClass("hover");var b=a(y).text();a(X).text(b)}function fa(){c&&clearTimeout(c);h&&clearInterval(h);f&&clearTimeout(f);i=[];j=[];z=[];P=[];oa();a(s).css("top",0);a(s).width(0);k=0;Q=R=l=H=I=J=t=M=u=v=!1;A=z.length-1;o=!0;Y()}function oa(){var b=a("#autoSlideWrapper #imageList").find("div.category").eq(W);a(b).find("ul").each(function(){var b=a(this),p=[];z.push(p);var g;b.find("li").each(function(){var b= a(this),d=b.attr("title");if(b.html()!="")var h=b.html();g={url:d,link:h?h:null};p.push(g)})})}function pa(){for(var b=0,d=P.length,p;b<d;b++)p=P[b],a(p).unbind("click",ga);a(s).empty();m=!1;fa()}function Y(){if(m)return!1;J=!0;var b=z[A].length,d=0;Z=0;var p=[],g=a("<div></div>");g.id=A;g.css("position","relative");g.css("overflow","hidden");g.css("marginRight",n);g.css("float","left");o||(l?(s.prepend(g),i.unshift(g)):(s.append(g),i.push(g)));j[A]=g;for(var e,c,f;d<b;d++){e=new Image;a(e).css("opacity", 0);a(e).css("display","block");g.append(e);b>1&&d!=b-1&&a(e).css("marginBottom",S);f=z[A][d];c=f.url;if(e.link=f.link)a(e).css("cursor","pointer"),a(e).click(ga),P.push(e);a(e).load(function(){p.push(a(this));Z++;if(Z==b&&!m){var e=p.length,d,c,f,i;B=$();if(e==1)d=p[0],c=a(d).attr("width"),f=a(d).attr("height"),e=B*(c/f),a(d).height(B),a(d).width(e),a(g).width(e),o?a(d).css("opacity",1):(l&&(aa(e+n-k),k=-e-n+k),a(d).stop().animate({opacity:1},ha));else if(e>1){for(var q=0,N=c=0;q<e;q++)d=p[q],c+= a(d).attr("height");i=(B-(e-1)*S)/c;for(q=0;q<e;q++)d=p[q],c=a(d).attr("width")*i,f=a(d).attr("height")*i,a(d).width(c),a(d).height(f),c>N&&(N=c),o?a(d).css("opacity",1):a(d).delay(qa*q).stop().animate({opacity:1},ha);a(g).width(N);!o&&l&&(aa(N+n-k),k=-N-n+k)}o||K();!u&&ba()>ca()&&(u=!0,v?da&&L.attr("src","data/icons/play.png"):(h&&clearInterval(h),h=setInterval(E,w?C:D),v=!0,da&&L.attr("src","data/icons/pause.png")));if(!M){d=0;e=z.length;for(q=!0;d<e;d++)if(j[d]==void 0||j[d]==null){q=!1;break}q&& (M=!0)}J=!1;r()}}).attr("src",c);a(e).error(function(a){console.log("error "+a)})}}function r(){c&&clearTimeout(c);f&&clearTimeout(f);o=!1;var b=ca()*ra;if(ba()<b)if(M){if(l){b=i[0];b=b.id-1;b<0&&(b=j.length-1);var b=ia(b),d=parseInt(a(b).css("width"));b&&(b.css("display","block"),a(s).prepend(b),i.unshift(b),aa(d+n-k),k=-d-n+k,K())}else if(b=i[i.length-1],b=b.id+1,b>j.length-1&&(b=0),b=ia(b))b.css("display","block"),a(s).append(b),i.push(b),K();t?f=setTimeout(r,T):c=setTimeout(r,O)}else{b=0;for(d= z.length;b<d;b++)if(j[b]==void 0||j[b]==null){A=b;Y();break}}else if(M)t?f=setTimeout(r,T):c=setTimeout(r,O);else for(b=z.length-1;b>-1;b--)if(b!=A&&(j[b]==void 0||j[b]==null)){A=b;o=!0;Y();break}}function aa(b){for(var d=0,c=i.length,g;d<c;d++)g=i[d],a(g).css("left",-b)}function ia(a){if(j[a]!=void 0&&j[a]!=null)return a=j[a]}function ba(){for(var b=0,d=i.length,c,g=0;b<d;b++)c=i[b],g+=a(c).width()+n;return g}function K(){var a=ba()+10;s.width(a)}function sa(){var b=0,d=i.length,c,g,e,f,k,l;for(B= $();b<d;b++){e=i[b];c=a(e).children().size();if(c==1)g=a(e).children(0),f=a(g).width(),k=a(g).height(),l=f/k,c=B*l,a(g).height(B),a(g).width(c),a(e).width(c);else if(c>1){for(var j=0,m=f=0;j<c;j++)g=a(e).children()[j],f+=a(g).height();l=(B-(c-1)*S)/f;for(j=0;j<c;j++)g=a(e).children()[j],f=a(g).width()*l,k=a(g).height()*l,a(g).width(f),a(g).height(k),f>m&&(m=f);a(e).width(m)}K()}h&&clearInterval(h);v&&(h=setInterval(E,w?C:D))}function E(){var b,d,c=0,f=i.length,e;e=w?ja:ka;for(l?t?I?k-=e:H&&(k+=e): k+=la:t?I?k-=e:H&&(k+=e):k-=la;c<f;c++)if(e=i[c])if(e.css("left",k),l){if(c==f-1){b=parseInt(e.css("left"));d=0;for(var h=i.length-1,j=void 0,m=0;d<h;d++)j=i[d],m+=a(j).width()+n;b+m>ca()&&(e.detach(),e.css("display","none"),i.pop(),K())}}else if(c==0&&(b=parseInt(e.css("left")),d=parseInt(e.css("width")),Math.abs(b)>d+n)){e.detach();e.css("display","none");i.shift();e=Math.abs(b)-(d+n);b=-e;d=0;h=i.length;for(j=void 0;d<h;d++)j=i[d],a(j).css("left",b);k=-e;K()}}function $(){return a(F).parent().is("body")? Math.max(a(window).height()-G,document.documentElement.clientHeight-G):a(F).parent().height()-G>Math.max(a(window).height()-G,document.documentElement.clientHeight-G)?a(F).parent().height()-G:a(F).parent().height()}function ca(){return a(F).parent().is("body")?Math.max(a(window).width(),document.documentElement.clientWidth):a(F).parent().width()}function ga(a){if(!a)a=window.event;a=window.open((window.event?a.srcElement:a.target).link,"myWindow");window.focus&&a.focus()}var ea=a(document),F=a("#autoSlideWrapper"), s=a("#autoSlideHolder"),L,U,V,G=0,D,C,la=1,ka,ja,h,k=0,n,S,A=0,Z=0,qa=350,ha=1E3,B,W=0,da=!1,y,X,ra=2,O=1E3,c,T=100,f,i=[],j,P,z,v=!1,u=!1,M=!1,l=!1,J=!1,o=!1,t=!1,I=!1,H=!1,m=!1,R=!1,Q=!1,ma=!1;a(F).parent().is("body")&&(ma=!0);var w=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);U=/chrome/.test(navigator.userAgent.toLowerCase());V=a.browser.safari&&/chrome/.test(navigator.userAgent.toLowerCase())?!1:!0;U&&!V&&(w=!0);n=x.verticalMarginSpace;S=x.horizontalMarginSpace;D=x.autoSlideInterval; C=x.IEautoSlideInterval;ka=x.manualIncrement;ja=x.IEmanualIncrement;ea.find("#autoSlideHeader").length>0&&(G=parseInt(a("#autoSlideHeader").css("height")),ea.find("#autoSlideNavigation").length>0&&(da=!0,x=a("#backward"),L=a("#pausePlay"),U=a("#forward"),V=a("#direction"),a(x).mousedown(function(){if(m||!u)return!1;h&&clearInterval(h);c&&clearTimeout(c);f&&clearTimeout(f);H=t=!0;l||(R=l=!0);h=setInterval(E,w?C:D);f=setTimeout(r,T);return!1}),a(U).mousedown(function(){if(m||!u)return!1;h&&clearInterval(h); c&&clearTimeout(c);f&&clearTimeout(f);t=I=!0;l&&(l=!1,Q=!0);h=setInterval(E,w?C:D);f=setTimeout(r,T);return!1}),a(document).mouseup(function(){if(m||!u)return!1;if(H){h&&clearInterval(h);c&&clearTimeout(c);f&&clearTimeout(f);H=t=!1;R&&(R=l=!1);if(v){var a=w?C:D;h=setInterval(E,a)}!J&&!o&&(c=setTimeout(r,O))}else I&&(h&&clearInterval(h),c&&clearTimeout(c),f&&clearTimeout(f),I=t=!1,Q&&(l=!0,Q=!1),v&&(a=w?C:D,h=setInterval(E,a)),!J&&!o&&(c=setTimeout(r,O)));return!1}),a(L).click(function(){if(m)return!1; f&&clearTimeout(f);h&&clearInterval(h);c&&clearTimeout(c);v?L.attr("src","data/icons/play.png"):(u&&(h=setInterval(E,w?C:D),!J&&!o&&(c=setTimeout(r,O))),L.attr("src","data/icons/pause.png"));v=!v;return!1}),a(V).click(function(){if(m||!u)return!1;l=!l;return!1})),ea.find("#autoSlideMenu").length>0&&(X=a("#selectedMenuItem"),a("ul.submenu").slideUp(0),a("ul.menu li").hover(function(){m||(a(this).hasClass("selected")||a(this).addClass("hover"),a("ul:first",this).slideDown(100))},function(){m||(a(this).hasClass("selectedSubItem")|| a(this).removeClass("hover"),a("ul:first",this).slideUp(100))}),a("#selectedMenuItem").click(function(){return!1}),a("ul.submenu li").click(function(){if(m||a(this).hasClass("selectedSubItem"))return!1;m=!0;y&&(y.removeClass("selectedSubItem"),y.removeClass("hover"));a("#selectedMenuItem").parent().removeClass("hover");a(this).addClass("selectedSubItem");y=a(this);var b=a(this).text();a(X).text(b);W=a(this).attr("id");a("ul.submenu").slideUp(200,function(){test=!0;f&&clearTimeout(f);c&&clearTimeout(c); h&&clearInterval(h);a(s).stop().animate({top:$()+5},500,pa)});return!1}),na()));fa();a(window).resize(function(){if(!ma||m||!u||!i)return!1;h&&clearInterval(h);clearTimeout(this.id);this.id=setTimeout(sa,500)})}})(jQuery);
