/** 
  CHANGELOG: 
    2007/12/03 - Upgraded to v1.2 syntax 
    2008/02/07 - Added specific functionality for todaynetwork gallery 
                 - Popup for gallery speed 
                 - Toggle Rotate changes 
    2008/02/22 - Ad refreshes only once for rotate 
               - Ad refreshes every image change 
               - Image alt changes per image change 
               - Image anchor title changes per image change 
	2008/06/02 - Changed the nielsen reporting function call to a gallery specific one. (currently austereo specific) 
	2008/06/17 - Updated with endOfShow screen 
	2008/06/18 - Added item poll functionality 
	2008/06/23 - Added timestamp to swap poll request URL to stop IE caching the response. 
	2008/07/09 - Changed filename (and location) to allow use across all Austereo sites. 
	2008/08/01 - Roll back of nielsen function call. Added (22/08/2008). 
	2008/10/14 - Design version and sectionSubDir of the poll is now driven from the template. 
	2009/05/04 - Added title to img tag to display correctly in firefox (Austereo TripleM issue 1276). 
	2009/09/02 - Changed moveNavToCurrentImage logic 
	2010/03/12 - Updated image poll form/results to be loaded on page load to work with front side caching 
 **/ 
if(window.FD){FD.SuperGallery=new Class({Extends:FD.Gallery,Implements:Events,options:{rotateSpeeds:[0,5000,3500,1500],rotateClasses:["stop","slow","med","fast"],adSwapCount:1},toggles:["about","moreGalleries","emailAFriend","endOfShow","emailFailure"],errors:{name:"Please enter your friend's name",email:"Please enter your friend's email address",yourName:"Please enter your name",yourEmail:"Please enter your email address"},initialize:function(){if(typeof (window.FDGalleryOptions)!="object"){FDGalleryOptions={}
}this.options=$merge(this.options,FDGalleryOptions);this.parent(this.options);for(var C=0;C<this.toggles.length;C++){var B=this.toggles[C];if(B){this.parseInnerButtons($(B+"Screen"));var A=$(B);if(A){A.addEvent("click",this.toggle.bindWithEvent(this,B))}}}var E=$(this.options.idImgDesc);if(E){this.defaultDescHeight=E.getStyle("height").toInt();this.defaultOpenPos=this.options.openPos;var D=this.getNav()}this.checkDesc();this.setupEmailForm();this._initShowHide("share");this._initShowHide("autoplay");
this._initItemPollForm();this.addEvent("swap",this.checkDesc.bind(this));this.addEvent("swap",this.doDynB.bind(this));this.addEvent("swap",this.swapItemPoll.bind(this));this.addEvent("navOpen",this.setThumbsTitle.bind(this,"Hide Thumbs"));this.addEvent("navClosed",this.setThumbsTitle.bind(this,"Show Thumbs"));var F=$("thumbnails");if(F){F.addEvent("click",this.closeNav.bind(this))}},_initShowHide:function(C){var B=$(C);if(B){var A=B.getElements("ul")[0];if(A){B.addEvent("mouseenter",this.show.bind(this,A));
B.addEvent("mouseleave",this.hide.bind(this,A))}}},_initItemPollForm:function(){var A=$("galleryItemPollForm");if(A){A.addEvent("submit",this.itemPollVote.create({bind:this,event:true}))}},setThumbsTitle:function(A){if(A){var B=$("thumbnails");if(B){B.empty().innerHTML=A}}},appendMouseE:function(A){var C=$("thumbnails");var B=this.getNav();if(C){C.addEvent("click",this.checkNav.bind(this))}},setupEmailForm:function(){var A=$("emailAFriendScreen");if(A){var B=A.getElements("form")[0];if(B){B.addEvent("submit",this.validateEmailForm.bindWithEvent(this,B))
}}},validateEmailForm:function(H,F){if(H){new Event(H).stop()}var C=F.getElements("input");var D=$("validationError");if(D){for(var A=0;A<C.length;A++){var E=C[A];D.empty();if(E.type!="submit"){var G=E.getParent();if(G&&((E.name.toLowerCase().indexOf("email")>-1&&!this.validateEmail(E.value))||E.value.trim()=="")){G.addClass("error");D.empty().innerHTML=this.errors[E.name];E.focus();E.select();return false}else{G.removeClass("error")}}}}var B={};if(!this.setOnComplete){B.onComplete=this.updateForm.bind(this);
this.setOnComplete=true}F.send(B)},updateForm:function(A){if(A){var B=$("emailFailureScreen");B.setHTML(A);this.toggle(null,"emailFailure");this.parseInnerButtons(B)}},validateEmail:function(C){if(C.length>0){var F=C.indexOf("@");if(F>0){var G=C.lastIndexOf("@");if(F==G){var B=C.substr(0,G+1);var E=/^([a-zA-Z0-9_\.\-\+])+\@/;if(!E.test(B)){return false}}else{return false}}else{return false}var D=C.substr(C.indexOf("@")+1,C.length);var A=/^(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;if(!A.test(D)){return false
}return true}},moveBy:function(B,A){if(B){new Event(B).stop()}else{var B=null}if(this.disabled){if(this.imgPos!=(this.imgC-1)){this.closeAllToggles()}}if(this.options.hotZone>0){if(B){this.closeNav()}}else{if(this.navOn){this.toggleNav()}}var C=this.imgPos+A;if((C==this.imgC&&!this.disabled)||(A<0&&this.disabled)){this.toggle(B,"endOfShow")}this.swap(B,C);this.moveNavToCurrentImage()},toggle:function(F,E){var B=false;if(F){new Event(F).stop()}if(E){this.checkNav();for(var D=0;D<this.toggles.length;
D++){var C=this.toggles[D];var H=$(C+"Screen");if(H){var G="hidden";var A=H.getStyle("visibility");if(A=="hidden"&&E==C){G="visible";B=true;if(this.rotating){this.rotate()}}H.setStyle("visibility",G)}}this.disabled=B}},show:function(A){if(A){A.setStyle("visibility","visible")}},hide:function(A){if(A){A.setStyle("visibility","hidden")}},parseInnerButtons:function(D){if(D){var B=D.getElements("a.close");for(var C=0,E=B.length;C<E;C++){B[C].addEvent("click",this.toggle.bindWithEvent(this,D))}var A=D.getElements(".email");
for(var C=0,E=A.length;C<E;C++){A[C].addEvent("click",this.toggle.bindWithEvent(this,"emailAFriend"))}}},toggleRotate:function(){if(this.disabled){if((this.imgC-1)==this.imgPos){this.reset()}else{this.closeAllToggles();this.disabled=false}}this.sentRotateReq=false;var A=$("rotateStop");if(A){A.setStyle("display",(this.rotating?"none":"block"))}this.rotate()},doDynB:function(){if(this.clickNo>0&&this.clickNo%this.options.adSwapCount==0){FD.refreshAd("*")}var A=$(this.options.idMainImg);if(A&&A.getParent().get("tag")=="a"){var C=A.getParent();
C.href=window.location.href;var B;if(window.s_pageName){B=s_pageName}else{if(window.s){B=s.pageName}}if(!this.rotating||(this.rotating&&!this.sentRotateReq)){FD.doNielsonImpression.delay(50,FD,[B,C]);this.sentRotateReq=true}}},swapItemPoll:function(){new Request({url:this.options.galleryItemPollPath,onComplete:this.handleSwapItemPollResponse.create({bind:this}),autoCancel:true}).get({galleryPollAssetId:FDGalleryImageAssetIds[this.imgPos],designVersionName:this.options.currentDesignVersion,sectionSubDir:this.options.pollComponentSectionSubDir,reqTime:new Date().getTime()})
},handleSwapItemPollResponse:function(B){var A=$("galleryWrapper");var C=$("galleryItemPollWrapper");if(B.trim()==""){C.empty();A.removeClass("galleryWithPoll");A.addClass("galleryWithoutPoll")}else{A.removeClass("galleryWithoutPoll");A.addClass("galleryWithPoll");C.set("html",B)}this._initItemPollForm()},itemPollVote:function(C){C.stop();var B=$("galleryItemPollForm");var A=B.get("send");A.addEvent("onComplete",this.handleItemPollVoteResponse.create({bind:this}));B.send()},handleItemPollVoteResponse:function(A){var B=$("galleryItemPollWrapper");
B.set("html",A);this._initItemPollForm()},closeAllToggles:function(){this.disabled=false;var B=this.toggles;for(var A=0;A<B.length;A++){var C=$(B[A]+"Screen");if(C){C.setStyle("visibility","hidden")}}},initRotate:function(){var B=$(this.options.idRotate);if(B){var H=$(this.options.idRotate+"Switch");if(H){H.addEvent("click",this.toggleRotate.bindWithEvent(this));var D=B.getElements("."+this.options.idRotate);var A=this.options.rotateClasses;var F=this.options.rotateSpeeds;if($type(A)=="array"){for(var E=0,G=D.length;
E<G;E++){for(var C=0;C<A.length;C++){if(D[E].hasClass(A[C])){D[E].addEvent("click",this.setRotateSpeed.bindWithEvent(this,[F[C],E,D]))}}}}}}},setRotateSpeed:function(E,D,C,A){if(E){new Event(E).stop()}if($type(D)=="number"){if(D==0){if(this.rotating){this.toggleRotate()}return }this.options.rotateDur=D;if(this.rotating){$clear(this.rotateID);this.rotateID=false;this.rotating=false}this.rotate();var B=$("rotateStop");if(B){B.setStyle("display",(!this.rotating?"none":"block"))}A.removeClass(this.options.classSelected);
if(A[C]){A[C].addClass(this.options.classSelected)}}},checkDesc:function(){var G=$(this.options.idImgDesc);var F=this.getNav();if(G){var E=G.offsetHeight;var D=this.options.galH-(E+10);this.options.openPos=this.options.galH-E-(F.offsetHeight-15);if(this.navOn){D=this.options.openPos}if(!this.navTrans){F.setStyle("top",D+"px")}else{this.closeNav()}}var B=$(this.options.idMainImg);var A=B.getParent();if(this.setMImgTitle&&B){B.set("alt",G.get("html"));B.set("title",G.get("html"));if(FDGalleryDesc){var C=FDGalleryDesc[this.imgPos+1]||FDGalleryDesc[0]
}A.set("title",C)}else{this.setMImgTitle=true}}});function initFDSuperGallery(){if(window.FDGalleryOptions){var A=new FD.SuperGallery(FDGalleryOptions);window.FDSuperGallery=A;A.swapItemPoll()}}window.addEvent("initFDSuperGallery",initFDSuperGallery);FD.register("FDSuperGallery",1)};