SouthTynesideCouncil.WebTeam.Carousel=function(N){var I=SouthTynesideCouncil.WebTeam,P="3-0-2",U="",D=null,E=[],L=false,V=[],T=[],J=false,K=5000,S=500,C=0,W=0,H=1,O=null,M=false;
if(!I.isValid(N)||N===""){return;
}U=N;
YAHOO.util.Get.css("/assets/carousel/"+P+"/css/carousel.css");
loader=new YAHOO.util.YUILoader({base:"",require:["animation"],loadOptional:false,combine:true,filter:"MIN",allowRollup:true,onSuccess:function(){M=true;
}});
loader.insert();
this.addItem=function(c,a,b,Y,Z){if(!I.isValid(c)||c===""){return;
}if(!I.isValid(Z)||Z===""){return;
}if(!I.isValid(a)||a===""){return;
}if(!I.isValid(b)||b===""){return;
}if(!I.isValid(Y)||Y===""){return;
}if(E.length>=10){return;
}E.push({linkTitle:c,url:Z,title:a,description:b,imageUrl:Y});
};
this.render=function(){L=true;
YAHOO.util.Event.onContentReady(U,G,null,this);
};
function F(){var f,h,Y,c,b,Z,a,e,g,j,d,i;
C=W;
W=H;
H++;
if(H>=T.length){H=0;
}h=new YAHOO.util.Anim(T[C]);
h.attributes.opacity={to:0};
h.attributes.duration=1;
h.method=YAHOO.util.Easing.easeBoth;
h.onComplete.subscribe(function(k,n,l){var m=I.getElementStyle(l.page);
if(m.substring(m.length-1,1)!==";"){m+=";";
}I.setElementStyle(l.page,m+"display:none;");
},{page:T[C]});
i=I.getElementStyle(T[W]);
i=i.replace(/\s{0,}display:\s{0,}none;{0,1}/gi,"");
I.setElementStyle(T[W],i);
f=new YAHOO.util.Anim(T[W]);
f.attributes.opacity={to:1};
f.attributes.duration=1;
f.method=YAHOO.util.Easing.easeBoth;
Z=V[C].getElementsByTagName("a")[0];
b=new YAHOO.util.ColorAnim(Z);
b.attributes.color={to:"#B1005D"};
b.attributes.backgroundColor={to:"#f5f5f5"};
b.attributes.duration=1;
b.method=YAHOO.util.Easing.easeBoth;
b.onComplete.subscribe(function(){var k=I.getAncestorNodeOfType(Z,"li",false);
k.className=k.className.replace(/\s{0,}selected\s{0,}/gi,"");
I.setElementStyle(Z,"");
});
Z.setAttribute("href","javascript:void(0);");
c=V[W].getElementsByTagName("a")[0];
Y=new YAHOO.util.ColorAnim(c);
Y.attributes.color={to:"#fff"};
Y.attributes.backgroundColor={to:"#B2005E"};
Y.attributes.duration=1;
Y.method=YAHOO.util.Easing.easeBoth;
Y.onComplete.subscribe(function(){c.setAttribute("href",c.getAttribute("url"));
});
g=V[C].getElementsByTagName("img")[0];
j=new YAHOO.util.Anim(g);
j.attributes.opacity={to:0};
j.attributes.duration=1;
j.method=YAHOO.util.Easing.easeBoth;
a=V[W].getElementsByTagName("img")[0];
e=new YAHOO.util.Anim(a);
e.attributes.opacity={to:1};
e.attributes.duration=1;
e.method=YAHOO.util.Easing.easeBoth;
h.animate();
f.animate();
b.animate();
Y.animate();
j.animate();
e.animate();
if(J){A();
O=window.setTimeout(F,K);
}}function A(){if(O!==null){window.clearTimeout(O);
O=null;
}}function G(){var b,c,Z,f,e,a,Y,k,j,d,g,h;
if(E.length===0){return;
}if(!M){window.setTimeout(G,100);
return;
}D=document.getElementById(U);
I.removeAllChildNodes(D);
c=I.createNode(null,"div",[{name:"id",value:"carousel-sleeve"}],"","");
Z=I.createNode(c,"div",[{name:"id",value:"carousel-container"}],"","");
f=I.createNode(Z,"div",[{name:"id",value:"carousel-page-holder"}],"","");
YAHOO.util.Event.addListener(f,"click",R);
e=I.createNode(Z,"ul",[{name:"id",value:"carousel-link-list"}],"","");
YAHOO.util.Event.addListener(e,"click",Q);
for(Y=0;
Y<E.length;
Y++){b=E[Y];
a=I.createNode(e,"li",[],(Y===0?"selected":""),"");
g=I.createNode(a,"img",[{name:"src",value:"assets/carousel/"+P+"/images/arrow.png"},{name:"border",value:"0"}],"","");
if(Y===0){I.createNode(a,"a",[{name:"href",value:b.url},{name:"page",value:Y},{name:"url",value:b.url}],"",b.linkTitle);
}else{I.createNode(a,"a",[{name:"href",value:"javascript:void(0);"},{name:"page",value:Y},{name:"url",value:b.url}],"",b.linkTitle);
}YAHOO.util.Dom.setStyle(g,"opacity",0);
V.push(a);
k=I.createNode(f,"div",[{name:"style",value:"background:transparent url("+b.imageUrl+") scroll no-repeat top left;"+(Y!==0?"display:none":"")}],"carousel-page"+(Y===0?" selected":""),"");
j=I.createNode(k,"div",[],"carousel-page-overlay","");
I.createNode(j,"p",[],"carousel-page-title",b.title);
I.createNode(j,"p",[],"carousel-page-description",b.description);
YAHOO.util.Dom.setStyle(k,"opacity",0);
T.push(k);
}YAHOO.util.Dom.setStyle(D.childNodes[0],"opacity",0);
YAHOO.util.Dom.setStyle(T[0],"opacity",1);
YAHOO.util.Dom.setStyle(V[0].getElementsByTagName("img")[0],"opacity",1);
D.appendChild(c);
h=new YAHOO.util.Anim(c);
h.attributes.opacity={to:1};
h.duration=1;
h.method=YAHOO.util.Easing.easeBoth;
h.onComplete.subscribe(B);
h.animate();
}function B(){var Y=document.getElementById("carousel-pause-button");
J=true;
A();
O=window.setTimeout(F,K);
I.setElementStyle(Y,"");
}function X(){J=false;
A();
}function R(Y,b,Z){var a=V[W].getElementsByTagName("a")[0];
document.location.href=a.getAttribute("url");
}function Q(Y,b,Z){var a=YAHOO.util.Event.getTarget(Y);
if(a.getAttribute("href")===a.getAttribute("url")){document.location.href=a.getAttribute("url");
}if(a.nodeName.toLowerCase()!=="a"){a=a.getElementsByTagName("a")[0];
}H=parseInt(a.getAttribute("page"),10);
X();
A();
F();
}};
