/*!
	tinyRotary.js: jQuery Content Carousel plugin - v0.7 - 10/22/2011
	http://frankiejr.com/tiny/rotary
	Copyright (c) 2011 Frankie Benevides Jr. "frankiejr"
	Made possible with gracious help from ViridianSpark.com
	Dual licensed under the MIT and GPL licenses
*/(function($){$.rotary={opt:{multiplier:1,speed:600,interval:7E3,rtl:true,tray:".tray",tile:".tile",win:"window",prev:"prev",next:"next",prevTxt:"&laquo;",nextTxt:"&raquo;",btnBox:"btns",nav:"navList",active:"active",autoplay:true}};$.fn.tinyRotary=function(opt){var opt=$.extend({},$.rotary.opt,opt);this.each(function(){$(this).data(new Rotary($(this),opt))})};function Rotary(el,opt){var obj=$(el);var tray=obj.children(opt.tray+":first");var tiles=tray.children();var total=tiles.length;var tileW=$(tiles[0]).outerWidth(true);var btnBox;var prev;var next;var nav;tray.wrap('<div class="'+opt.win+'" style="width: '+(tileW-3)+'px;" />');tray.css("width",total*tileW*2);if(total>opt.multiplier){var m=opt.multiplier;if(opt.prev.length>0||opt.next.length>0||opt.nav.length>0)btnBox=obj.append('<div class="'+opt.btnBox+'" />').find("."+opt.btnBox);if(opt.nav.length>0)buildNav();if(opt.prev.length>0||opt.next.length>0)buildButtons();if(opt.interval>0)autoPlay()}if(total<opt.multiplier*2&&total>opt.multiplier)m=1;else if(total<=opt.multiplier)m=0;function buildButtons(){if(opt.prev.length>0){prev=btnBox.prepend('<a href="#" class="'+opt.prev+'">'+opt.prevTxt+"</a>").find("."+opt.prev);prev.bind("click.prev",function(event){event.preventDefault();animateTray("prev",m);stopAutoPlay()})}if(opt.next.length>0){next=btnBox.append('<a href="#" class="'+opt.next+'">'+opt.nextTxt+"</a>").find("."+opt.next);next.bind("click.next",function(event){event.preventDefault();animateTray("next",m);stopAutoPlay()})}}function buildNav(){nav=btnBox.append('<ul class="'+opt.nav+'" />').find("."+opt.nav);for(var t=0;t<total;t++){$(tiles[t]).attr("data-num",t);var button=nav.append('<li data-num="'+t+'"><a href="#">'+t+"</a></li>").find("li:last");button.bind("click",function(event){event.preventDefault();stopAutoPlay();if(tray.is(":animated")!=true){var target=parseInt($(this).attr("data-num"));var currentOrder=tray.children();var loc;for(loc=0;loc<currentOrder.length;loc++)if($(currentOrder[loc]).attr("data-num")==target)break;var current=parseInt($(currentOrder[0]).attr("data-num"));var diff=target-current;if(diff>0)if(diff<=total/2)animateTray("next",diff);else animateTray("prev",total-diff);else if(diff<0){diff=Math.abs(diff);if(diff<=total/2)animateTray("prev",diff);else animateTray("next",total-diff)}}})}if(opt.nav.length>0)setActive(0)}function setActive(num){nav.children().removeClass(opt.active);if(m<=1)nav.find("li:eq("+num+")").addClass(opt.active);else if(m>1){var btns=nav.children();for(var b=num;b<num+m;b++)nav.find("li:eq("+b+")").addClass(opt.active);if(num+m>total){var leftover=num+m-total;nav.find("li:lt("+leftover+")").addClass(opt.active)}}}function animateTray(dir,count){if(tray.is(":animated")!=true){var loopers;var distance=count*tileW;if(dir==="prev"){var dir="+";loopers=tray.children(opt.tile+":gt("+(total-count-1)+")");loopers.clone().prependTo(tray);tray.css("left",-distance)}else if(dir==="next"){var dir="-";loopers=tray.children(opt.tile+":lt("+count+")");loopers.clone().appendTo(tray)}tray.animate({left:dir+"="+distance},opt.speed,function(){loopers.remove();tray.css("left",0);if(opt.nav.length>0)setActive(parseInt(tray.find(":first-child").attr("data-num")));videoTile()})}}function autoPlay(){if(opt.interval>0&&m!=0){var timer;function slideTimer(){if(opt.autoplay===true)timer=setInterval(function(){if(opt.rtl===true&&$("#homeSlider li:first").hasClass("playing")!=true)animateTray("next",m);else if($("#homeSlider li:first").hasClass("playing")!=true)animateTray("prev",m)},opt.interval)}slideTimer();obj.hover(function(){clearInterval(timer)},function(){slideTimer()})}}function videoTile(){thisTile=$("#homeSlider li:first");if(thisTile.hasClass("video")==true){var playButton=thisTile.find(".playButton");playButton.bind("click",function(){stopAutoPlay();thisTile.addClass("playing");var thisPlayer=thisTile.find("object").attr("id");playButton.hide();nav.hide();thisTile.find(".content").fadeOut("1000");document.getElementById(thisPlayer).playVideo()});function layerButtonShow(){playButton.show();nav.show();thisTile.removeClass("playing").find(".content").show()}layerButtonShow();obj.find(".btns a").bind("click",function(){var thisPlayer=thisTile.find("object").attr("id");try{document.getElementById(thisPlayer).pauseVideo()}catch(err){}layerButtonShow()})}}if($("#homeSlider li:first").hasClass("video")===true)videoTile();function stopAutoPlay(){opt.autoplay=false}obj.find("a").bind("click",function(){stopAutoPlay()})}})(jQuery);
