AP.Home=(function(){var A={},B={timer:null,currentIndex:0,slideLength:0,delay:6000};var H=function(){A.$module=jQuery("#dynamicLead");if(A.$module.length===0){return}A.$module.$body=A.$module.find(".body");A.$playlist=A.$module.find("#playlist");A.$playlist.$clips=A.$playlist.find("div.clip");B.slideLength=A.$playlist.$clips.length;A.$header=jQuery('<div class="head"></div>');A.$imageWrapper=jQuery('<div class="leadImage"></div>');A.$nav=jQuery('<div class="nav"></div>');A.$currentClip=jQuery('<div class="currentClip"></div>');A.$currentCategory=jQuery("<h4></h4>");A.$navList=jQuery("<ul></ul>");A.$transportWrapper=jQuery("<p></p>");A.$transport=jQuery('<a class="transport"></a>');A.$prev=jQuery('<a class="previous ">Previous</a>');A.$next=jQuery('<a class="next">Next</a>');A.$module.$body.prepend(A.$imageWrapper);(A.$module.find("span.tl").length>0)?A.$module.find("span.tl").after(A.$header):A.$module.prepend(A.$header);A.$nav.insertBefore(A.$playlist);A.$currentClip.insertBefore(A.$playlist);A.$transportWrapper.append(A.$transport);A.$playlist.$clips.each(function(L){var N=jQuery(this);var K=jQuery('<a href="#"></a>').text(L+1);var M=K.get(0);var P=jQuery("<li></li>");var J=N.find("img").attr("lowsrc");var O=N.find("h1").text();M.$preview=jQuery('<div class="preview"></div>').append(jQuery('<img src="'+J+'" alt="'+O+'" />')).append(jQuery("<p></p>").text(O)).appendTo(A.$nav).css({left:"-9999px"});M.clipIndex=L;M.showPreview=function(){var Q=jQuery(this);Q.pos=Q.position();this.$preview.styles={top:Q.pos.top-(this.$preview.outerHeight()+14),left:((Q.pos.left+(Q.outerWidth()/2))-(this.$preview.outerWidth()/2)),"z-index":"10"};if(Q.hasClass("active")){return}this.$preview.css(this.$preview.styles).fadeIn(150)};M.hidePreview=function(){this.$preview.css({"z-index":"1"}).fadeOut(150)};M.loadClip=function(Q){Q.preventDefault();if(B.timer){D()}this.hidePreview();G("paused");E(this.clipIndex,true)};K.mouseover(M.showPreview);K.mouseout(M.hidePreview);K.click(M.loadClip);K.appendTo(P.appendTo(A.$navList))});A.$prev.click(function(J){J.preventDefault();I();D();G("paused")});A.$next.click(function(J){J.preventDefault();F();D();G("paused")});A.$prev.appendTo(jQuery("<li></li>").prependTo(A.$navList));A.$next.appendTo(jQuery("<li></li>").appendTo(A.$navList));A.$transport.click(function(J){J.preventDefault();if(jQuery(this).hasClass("playing")){G("paused");D()}else{G("playing");C()}});A.$nav.append(A.$currentCategory).append(A.$transportWrapper).append(A.$navList);E(0)};var E=function(K,O){if(typeof K!=="number"){return}O===(typeof O==="boolean")?O:false;var N=A.$playlist.$clips.eq(K),M=N.clone(),L=M.find("img").addClass("large").removeAttr("lowsrc"),J=N.find("img").outerHeight(),P;A.$header.$h1=A.$header.find("h1");L.css({opacity:0,display:"block","z-index":"10"});A.$imageWrapper.css({height:J}).append(L);if(N.find("a").length>0){L.wrap('<a href="'+N.find("a").eq(0).attr("href")+'"></a>')}L.animate({opacity:1},500,function(){L.prev().remove();L.css({"z-index":"1"})});A.$currentClip.empty().append(M.find("p"));A.$currentClip.find("p").prepend("<b>"+M.find("h1").text()+"</b> ");A.$currentCategory.text(M.find("h4").text());A.$navList.find("a").each(function(){var Q=jQuery(this);if(this.clipIndex===K){Q.addClass("active");B.currentIndex=K;P=Q;if(B.timer===null&&!O){C()}}else{Q.removeClass("active")}});A.$currentClip.animate({backgroundPosition:((P.position().left-492)+"px 0")},250,"swing");AP.Global.ieCornerFix()};var C=function(){B.timer=window.setInterval(F,B.delay);G("playing")};var D=function(){clearInterval(B.timer);B.timer=null};var I=function(){var J=(B.currentIndex===0)?B.slideLength-1:B.currentIndex-1;E(J)};var F=function(){var J=(B.currentIndex===B.slideLength-1)?0:B.currentIndex+1;E(J)};var G=function(J){if(J!=="playing"&&J!=="paused"){return}if(J==="playing"){A.$transport.removeClass("paused").addClass("playing").text("pause")}else{A.$transport.removeClass("playing").addClass("paused").text("play")}};return{initialize:function(){if(this.initialized===true){return}H();this.initialized=true}}})();jQuery(document).ready(function(){AP.Home.initialize.apply(AP.Home)});
