﻿// jQuery Plugin - Heroize
// Animated Hero/Feature Panel with play/pause, timer, buttons and sliding animation
// version 0.1, May 3rd, 2011
(function($){$.fn.heroize=function(method){var defaults={heroPlayImg:'fileadmin/template/main/Scripts/jquery/play.png',heroPauseImg:'fileadmin/template/main/Scripts/jquery/pause.png',heroTimeDelay:5000,heroTransitionSpeed:300,heroNextChar:'>',heroWidth:0,heroHeight:0,heroTotal:0,heroPrev:0,heroTracker:1,heroCurrent:1,heroPlaying:true,heroTimerID:0,heroNumbersPaneOpen:false,heroTextStr:""}
var settings={}
var methods={init:function(options){settings=$.extend({},defaults,options)
return this.each(function(){var $element=$(this);helpers.removeDefault($element);helpers.determineSettings($element);helpers.positionPanes($element);helpers.applyStyles($element);helpers.initHero($element);});}}
var helpers={applyStyles:function(parent){parent.find('[class^="heropane"]').each(function(){$(this).attr('id','hero'+settings.heroTracker);if($(this).next().hasClass('herotext')){settings.heroTextStr+='<div class="herotext">'+$(this).next().remove().html()+'</div>';}else{settings.heroTextStr+='<div class="herotext"></div>';}
settings.heroTracker++;});settings.heroTracker=1;parent.append('<div class="featblackbar">'+settings.heroTextStr+'</div>');parent.find('[class^="herotext"]').each(function(){$(this).attr('id','heroText'+settings.heroTracker)
settings.heroTracker++;});parent.find('[class="featblackbar"]').each(function(){$(this).append('<div id="herocontrols" class="featcontrols"></div>');$(this).append('<div class="featbarbg transparent"></div>');})
parent.find('#herocontrols').each(function(){$(this).append('<div id="featloader"><div id="loader"></div></div>');$(this).append('<div id="playpause"><img src="'+settings.heroPauseImg+'" width="6" height="7" /></div><div class="featnext">'+settings.heroNextChar+'</div><div id="heroitemwrap"></div>');});for(var i=1;i<=settings.heroTotal;i++){parent.find('#heroitemwrap').append('<div class="featitem" id="featitem'+i+'">'+i+'</div>');}},initHero:function(parent){parent.find('#feature'+settings.heroCurrent).css('left','0');parent.find('.featnext, .featitem').each(function(){$(this).addClass('transparent');$(this).hover(function(){helpers.openNumbersPane(parent);$(this).removeClass('transparent');},function(){helpers.closeNumbersPane(parent);if($(this).attr('id')!=parent.find('#featitem'+settings.heroCurrent).attr('id')){$(this).addClass('transparent');}});});parent.find('#playpause').click(function(){if(settings.heroPlaying){parent.find('#playpause img').attr("src",settings.heroPlayImg);settings.heroPlaying=false;parent.find('#loader').stop();}else{parent.find('#playpause img').attr("src",settings.heroPauseImg);settings.heroPlaying=true;helpers.loaderItUp(parent);}});parent.find('.featnext').click(function(){if(settings.heroPlaying){parent.find('#loader').stop();helpers.nextFeat(parent);helpers.loaderItUp(parent);}else{helpers.nextFeat(parent);}});for(var i=1;i<=settings.heroTotal;i++){helpers.goToFeat(parent,i);}
helpers.applyCurrentFeature(parent,settings.heroCurrent);helpers.animatePanels(parent,0);helpers.loaderItUp(parent);},openNumbersPane:function(parent){clearTimeout(settings.heroTimerID);if(!settings.heroNumbersPaneOpen){settings.heroNumbersPaneOpen=true;parent.find('#heroitemwrap').slideDown('fast');}},closeNumbersPane:function(parent){if(settings.heroNumbersPaneOpen){settings.heroTimerID=setTimeout(function(){helpers.doClose(parent);},800);}},doClose:function(parent){settings.heroNumbersPaneOpen=false;parent.find('#heroitemwrap').slideUp('fast');},loaderItUp:function(parent){parent.find('#loader').css('width','0%');parent.find('#loader').animate({width:'100%'},settings.heroTimeDelay,"linear",function(){helpers.nextFeat(parent);helpers.loaderItUp(parent);})},applyCurrentFeature:function(parent,newfeature){parent.find('[id^="featitem"]').addClass('transparent');parent.find('#featitem'+newfeature).removeClass('transparent');},animatePanels:function(parent,prevfeat){if(prevfeat!=0){parent.find('#hero'+prevfeat).animate({'left':'-='+settings.heroWidth},settings.heroTransitionSpeed,function(){parent.find('#hero'+prevfeat).css('left',settings.heroWidth);});parent.find('#heroText'+prevfeat).hide();}
parent.find('#hero'+settings.heroCurrent).animate({'left':'0px'},settings.heroTransitionSpeed);parent.find('#heroText'+settings.heroCurrent).fadeIn();},determineSettings:function(parent){settings.heroTotal=parent.find('[class^="heropane"]').size();settings.heroWidth=parent.css('width');settings.heroHeight=parent.css('height');},positionPanes:function(parent){parent.find('.heropane').css('left',settings.heroWidth);parent.find('.heropane').css('display','block');},removeDefault:function(parent){parent.find('#defaulthero').empty();parent.find('#defaulthero').remove();},goToFeat:function(parent,targetHero){parent.find('#featitem'+targetHero).click(function(){if(targetHero!=settings.heroCurrent){settings.heroPrev=settings.heroCurrent;settings.heroCurrent=targetHero;helpers.applyCurrentFeature(parent,settings.heroCurrent);if(settings.heroPlaying){parent.find('#loader').stop();helpers.animatePanels(parent,settings.heroPrev);helpers.loaderItUp(parent);}else{helpers.animatePanels(parent,settings.heroPrev);}}});},nextFeat:function(parent){var prevfeat=settings.heroCurrent;settings.heroCurrent++;if(settings.heroCurrent>settings.heroTotal){settings.heroCurrent=1;}
helpers.applyCurrentFeature(parent,settings.heroCurrent);helpers.animatePanels(parent,prevfeat);}}
if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==='object'||!method){return methods.init.apply(this,arguments);}else{$.error('Method "'+method+'" does not exist in Heroize plugin!');}}})(jQuery);
