/* Overlay + tabs + animations
 * @author Nicolas Le Thierry d'Ennequin
 * Requires jQuery, jQuery Tools
 * @version 2011-01-21
 */
(function($){var animSpeed=750;$(document).ready(function(){var i=0;if($("#beforeviewtabs").length===0){a=document.createElement("ul");a.id="beforeviewtabs";$("#viewtabs").before(a);}
if($("#afterviewtabs").length===0){a=document.createElement("ul");a.id="afterviewtabs";$("#viewtabs").after(a);}
$(".viewtrigger").overlay({top:"center",left:"center",closeOnEsc:true,onBeforeClose:closeOverlay,mask:{color:"#000",loadSpeed:"fast",closeSpeed:"fast"}});$("#viewtabs").tabs(".viewpane",{rotate:true});$(".viewtab").each(function(){this.id="tab"+(i++);});$("#viewanimtrigger").attr("class","viewanimtriggerplay").one("click",animationPlay);});function animationPlay(){var isAfter=false;var animClass=$("#viewtabs .current").attr("class").match(/anim-\d+/i);var a;if(animClass===null){$("#viewanimtrigger").attr("class","viewanimtriggerplay").one("click",animationPlay);}else{$("#viewanimtrigger").attr("class","viewanimtriggerstop").one("click",animationStop);$(".viewtab").each(function(){var isAnimClass=$(this).hasClass(animClass);if(isAnimClass){isAfter=true;}else{$(this).detach().appendTo(isAfter?"#afterviewtabs":"#beforeviewtabs").addClass("disabled");}});$("#viewtabs").tabs("#viewpanes ."+animClass,{rotate:true});$("#viewtabs").slideshow({autoplay:true,autopause:false,interval:animSpeed});}}
function animationStop(){var currentViewTab=$("#viewtabs").data("tabs").getCurrentTab().attr("id");$("#viewtabs").data("slideshow").stop();$("#viewtabs").removeData("slideshow");resetViewtabs();$("#viewtabs").data("tabs").click($("#"+currentViewTab).index());$("#viewanimtrigger").attr("class","viewanimtriggerplay").one("click",animationPlay);}
function closeOverlay(){resetViewtabs();if($("#viewtabs").data("slideshow")!==undefined){$("#viewanimtrigger").unbind("click").attr("class","viewanimtriggerplay").one("click",animationPlay);$("#viewtabs").data("slideshow").stop();$("#viewtabs").removeData("slideshow");}}
function resetViewtabs(){var lastItem=null;$("#beforeviewtabs .viewtab").each(function(){if(lastItem===null){lastItem=$(this).detach().prependTo("#viewtabs");}else{lastItem=$(this).detach().insertAfter(lastItem);}});$("#afterviewtabs .viewtab").each(function(){$(this).detach().appendTo("#viewtabs");});$(".viewtab").removeClass("disabled");$("#viewtabs").tabs(".viewpane",{rotate:true});}}(jQuery));
