/***           
*  jquery.heroize.min.js
*  version 0.1  |  2011.06.24
*  author: Joel Peterson | @joelasonian
***/
(function($){$.fn.heroize=function(method){var defaults={heroPlayImg:'play.png',heroPauseImg:'pause.png',heroTimeDelay:5000,heroTransistionSpeed: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.remove_default($element);helpers.determine_settings($element);helpers.position_panes($element);helpers.apply_styles($element);helpers.init_hero($element);});}}
var helpers={apply_styles: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>');}},init_hero:function(parent){parent.find('#feature'+settings.heroCurrent).css('left','0');parent.find('.featnext, .featitem').each(function(){$(this).addClass('transparent');$(this).hover(function(){helpers.open_numbers_pane(parent);$(this).removeClass('transparent');},function(){helpers.close_numbers_pane(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.loader_it_up(parent);}});parent.find('.featnext').click(function(){if(settings.heroPlaying){parent.find('#loader').stop();helpers.next_feat(parent);helpers.loader_it_up(parent);}else{helpers.next_feat(parent);}});for(var i=1;i<=settings.heroTotal;i++){helpers.go_to_feat(parent,i);}
helpers.apply_current_feature(parent,settings.heroCurrent);helpers.animate_panels(parent,0);helpers.loader_it_up(parent);},open_numbers_pane:function(parent){clearTimeout(settings.heroTimerID);if(!settings.heroNumbersPaneOpen){settings.heroNumbersPaneOpen=true;parent.find('#heroitemwrap').slideDown('fast');}},close_numbers_pane:function(parent){if(settings.heroNumbersPaneOpen){settings.heroTimerID=setTimeout(function(){helpers.do_close(parent);},800);}},do_close:function(parent){settings.heroNumbersPaneOpen=false;parent.find('#heroitemwrap').slideUp('fast');},loader_it_up:function(parent){parent.find('#loader').css('width','0%');parent.find('#loader').animate({width:'100%'},settings.heroTimeDelay,"linear",function(){helpers.next_feat(parent);helpers.loader_it_up(parent);})},apply_current_feature:function(parent,newfeature){parent.find('[id^="featitem"]').addClass('transparent');parent.find('#featitem'+newfeature).removeClass('transparent');},animate_panels:function(parent,prevfeat){if(prevfeat!=0){parent.find('#hero'+prevfeat).animate({'left':'-='+settings.heroWidth},settings.heroTransistionSpeed,function(){parent.find('#hero'+prevfeat).css('left',settings.heroWidth);});parent.find('#heroText'+prevfeat).hide();}
parent.find('#hero'+settings.heroCurrent).animate({'left':'0px'},settings.heroTransistionSpeed);parent.find('#heroText'+settings.heroCurrent).fadeIn();},determine_settings:function(parent){settings.heroTotal=parent.find('[class^="heropane"]').size();settings.heroWidth=parent.css('width');settings.heroHeight=parent.css('height');},position_panes:function(parent){parent.find('.heropane').css('left',settings.heroWidth);parent.find('.heropane').css('display','block');},remove_default:function(parent){parent.find('#defaulthero').empty();parent.find('#defaulthero').remove();},go_to_feat:function(parent,targetHero){parent.find('#featitem'+targetHero).click(function(){if(targetHero!=settings.heroCurrent){settings.heroPrev=settings.heroCurrent;settings.heroCurrent=targetHero;helpers.apply_current_feature(parent,settings.heroCurrent);if(settings.heroPlaying){parent.find('#loader').stop();helpers.animate_panels(parent,settings.heroPrev);helpers.loader_it_up(parent);}else{helpers.animate_panels(parent,settings.heroPrev);}}});},next_feat:function(parent){var prevfeat=settings.heroCurrent;settings.heroCurrent++;if(settings.heroCurrent>settings.heroTotal){settings.heroCurrent=1;}
helpers.apply_current_feature(parent,settings.heroCurrent);helpers.animate_panels(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);
