(function(b){b.fn.offerCarousel=function(c){var e=b(this);var d=b.extend({delay:10000,imageArray:[],prevNextOn:true,itemsViewable:1,itemWidth:300,itemHeight:300,animatedSlide:true,slideSpeed:250,controlsPosition:"above",automatic:true,infoBackgroundOn:true,infoBackgroundColor:"000",infoBackgroundOpacity:0.4},c||{});if(e.children().length>0){e.wrap('<div id="slider"></div>');b("#slider").css({width:d.itemWidth*d.itemsViewable,height:d.itemHeight,overflow:"hidden",position:"relative"});e.css({position:"relative",width:d.itemWidth*e.children().length,height:d.itemHeight,margin:0,padding:0,"list-style":"none"});e.children().each(function(g){var f=b(this);f.attr("id",f.parent().attr("id")+"-item-"+g);f.css({position:"relative","float":"left",width:d.itemWidth,height:d.itemHeight,overflow:"hidden"});if(g===0){f.css("left","0")}if(d.imageArray.length>0){f.css("background","url("+d.imageArray[g]+") no-repeat")}f.wrapInner('<div class="offer-content" style="width:100%;position:absolute;z-index:1;"></div>');if(d.infoBackgroundOn){f.prepend('<div class="offer-content-background" style="width:100%;"></div>');b("#"+f.attr("id")+" .offer-content-background").css({backgroundColor:"#"+d.infoBackgroundColor,height:b("#"+f.attr("id")+" .offer-content").height(),width:"100%",opacity:d.infoBackgroundOpacity,position:"absolute","z-index":"1"})}if(d.prevNextOn&&d.itemsViewable<=1){strControls='<div class="next-prev-controls">';if(g!==0){strControls+='<a class="prev" href="#'+f.parent().attr("id")+"-item-"+(g-1)+'">';if(d.prevImageURL!==""){strControls+='<img src="'+d.prevImageUrl+'"" alt="previous" />'}else{strControls+="prev"}strControls+="</a>"}if(g===0||g!==e.children().length-1){strControls+='<a class="next" href="#'+f.parent().attr("id")+"-item-"+(g+1)+'">';if(d.nextImageURL!==""){strControls+='<img src="'+d.nextImageUrl+'"" alt="next" />'}else{strControls+="next"}strControls+="</a>"}strControls+="</div>";if(d.controlsPosition==="below"){f.append(strControls)}else{f.prepend(strControls)}}b("#"+f.attr("id")+" a.prev").bind("click",function(){if(d.animatedSlide&&e.not(":animated").length>0){e.stop().animate({marginLeft:(parseInt(e.css("margin-left"))+d.itemWidth*d.itemsViewable)},d.slideSpeed)}return false});b("#"+f.attr("id")+" a.next").bind("click",function(){if(d.animatedSlide&&e.not(":animated").length>0){e.stop().animate({marginLeft:(parseInt(e.css("margin-left"))-d.itemWidth*d.itemsViewable)},d.slideSpeed)}return false});b(".next-prev-controls a").fadeTo(0,0.5).hover(function(){b(this).stop().fadeTo(700,1)},function(){b(this).stop().fadeTo(700,0.5)})});if(d.automatic){a(e,d)}}else{alert("Please provide a container and item selector which returns results")}};function a(e,d,c){if(c==null){c=false}e.hover(function(){c=true},function(){c=false});setTimeout(function(){if(e.not(":animated").length>0&&c===false){var h=parseInt(e.css("margin-left"))*-1;var g=parseInt((d.itemWidth*e.children().length)-d.itemWidth*d.itemsViewable);if(h<g){if(d.animatedSlide){e.stop().animate({marginLeft:(parseInt(e.css("margin-left"))-d.itemWidth*d.itemsViewable)},d.slideSpeed)}else{e.css({marginLeft:(parseInt(e.css("margin-left"))-d.itemWidth*d.itemsViewable)})}}else{if(typeof d.slideSpeed=="string"){alert("slideSpeed needs to be in milliseconds")}else{if(d.animatedSlide){var f=parseInt(d.slideSpeed)*e.children().length;e.stop().animate({marginLeft:0},f)}else{e.css({marginLeft:0})}}}}a(e,d,c)},d.delay)}})(jQuery);