﻿if((typeof jQuery)=="function"){(function($){$.fn.dodImageCarousel=function(p){var p;if(p==="select"){return select.apply(this,Array.prototype.splice.call(arguments,1))}else if(p==="getSelectedIndex"){return getSelectedIndex.apply(this.eq(0))}else if(p==="scrollRight"){return scrollRight.apply(this)}else if(p==="scrollLeft"){return scrollLeft.apply(this)}else if(p==="scrollDown"){return scrollDown.apply(this)}else if(p==="scrollUp"){return scrollUp.apply(this)}else if(p==="stopAutoPlay"){return stopAutoPlay.apply(this)}else if(p==="startAutoPlay"){return startAutoPlay.apply(this)}else if(p==="toggleAutoPlay"){return toggleAutoPlay.apply(this)}return this.each(function(){p=$.extend(true,{autoPlay:true,autoPlayInterval:7000,autoPlayClickStop:true,imagesVisible:5,imageOpacity:1.0,imageOpacityHover:0.7,imageOpacitySelect:0.3,selected:null,select:null,orientation:'horizontal',showScrollButtons:true,scrollLeftElem:null,scrollRightElem:null,scrollUpElem:null,scrollDownElem:null},p);var d=$(this);var e;var f;var g;var h;var j;var k;var l;var m;var n;var o;f=d.before("<div class=\"DODImageCarouselViewPort\"></div>").prev();e=d.find("a").appendTo(f.eq(0)).wrap("<div class=\"DODImageCarouselItem\"></div>");e=f.eq(0).find("div");e.each(function(){var a=$(this);var b=a.children("a");var c=b.children("img");b.css("display","block").width(a.width()).height(a.height());a.css("opacity",p.imageOpacity).css("background","url("+c.attr("src")+") center center no-repeat").attr("alt",c.attr("alt")).attr("title",c.attr("title"));if(p.orientation=="horizontal"){a.css("float","left")}c.hide()});e.children("a").mouseenter(function(){var a=$(this);if(p.imageOpacityHover!==null&&!a.parent().hasClass("DODImageCarouselItemSelected")){a.parent().animate({opacity:p.imageOpacityHover},200)}});e.children("a").mouseleave(function(){var a=$(this);if(p.imageOpacity!==null&&!a.parent().hasClass("DODImageCarouselItemSelected")){a.parent().animate({opacity:p.imageOpacity},200)}});e.each(function(i){var a=$(this);var b=a.children("a").eq(0);b.click(function(){if(p.autoPlayClickStop){stopAutoPlay.apply(d)}itemClick.apply(d.get(0),[i]);this.blur();return false})});if((typeof p.select)=="function"){d.bind("dodImageCarouselSelect",p.select)}switch(p.orientation){case"vertical":n=parseInt(e.css("margin-bottom"),10);f.height(((e.outerHeight()+n)*p.imagesVisible)-n).width(e.outerWidth()).css("overflow","hidden").css("position","relative");g=e.wrapAll("<div class=\"DODImageCarouselItemContainer\"></div>").parent().height(((e.outerHeight()+n)*e.length)).css("position","absolute").css("left","0");h=f.wrap("<div class=\"DODImageCarousel\"></div>").parent().css("position","relative").width(f.width());if(p.showScrollButtons&&(p.scrollUpElem==null||p.scrollDownElem==null)){l=h.append("<div class=\"DODImageCarouselScrollerBottom\"></a></div>").children(".DODImageCarouselScrollerBottom");l.css("position","absolute").css("cursor","pointer").css("bottom","0").css("right",(h.outerWidth()/2)-(l.outerWidth()/2)).css("visibility","hidden").click(function(){scrollDown.apply(d);return false});m=h.append("<div class=\"DODImageCarouselScrollerTop\"></div>").children(".DODImageCarouselScrollerTop");m.css("position","absolute").css("cursor","pointer").css("top","0").css("left",(h.outerWidth()/2)-(m.outerWidth()/2)).css("visibility","hidden").click(function(){scrollUp.apply(d);return false});h.css("padding-bottom",l.outerHeight()+parseInt(l.css("margin-top"),10)).css("padding-top",m.outerHeight()+parseInt(m.css("margin-bottom"),10)).mouseenter(function(){toggleAutoPlay.apply(d)}).mouseleave(function(){toggleAutoPlay.apply(d)})}else if(p.scrollUpElem!=null&&p.scrollDownElem!=null){l=$(p.scrollDownElem);l.css("visibility","hidden").click(function(){scrollDown.apply(d);if(p.autoPlayClickStop){stopAutoPlay.apply(d)}return false});$scrollerUp=$(p.scrollUpElem);$scrollerUp.css("visibility","hidden").click(function(){scrollUp.apply(d);if(p.autoPlayClickStop){stopAutoPlay.apply(d)}return false});h.mouseenter(function(){toggleAutoPlay.apply(d)}).mouseleave(function(){toggleAutoPlay.apply(d)})}break;default:n=parseInt(e.css("margin-right"),10);f.width(((e.outerWidth()+n)*p.imagesVisible)-n).height(e.outerHeight()).css("overflow","hidden").css("position","relative");g=e.wrapAll("<div class=\"DODImageCarouselItemContainer\"></div>").parent().width(((e.outerWidth()+n)*e.length)).css("position","absolute").css("left","0");h=f.wrap("<div class=\"DODImageCarousel\"></div>").parent().css("position","relative").width(f.width()).height(f.height());if(p.showScrollButtons&&(p.scrollLeftElem==null||p.scrollRightElem==null)){j=h.append("<div class=\"DODImageCarouselScrollerRight\"></a></div>").children(".DODImageCarouselScrollerRight");j.css("position","absolute").css("cursor","pointer").css("top",(h.outerHeight()/2)-(j.outerHeight()/2)).css("right","0").css("visibility","hidden").click(function(){scrollRight.apply(d);return false});k=h.append("<div class=\"DODImageCarouselScrollerLeft\"></div>").children(".DODImageCarouselScrollerLeft");k.css("position","absolute").css("cursor","pointer").css("top",(h.outerHeight()/2)-(k.outerHeight()/2)).css("left","0").css("visibility","hidden").click(function(){scrollLeft.apply(d);return false});h.css("padding-left",k.outerWidth()+parseInt(k.css("margin-right"),10)).css("padding-right",j.outerWidth()+parseInt(j.css("margin-left"),10)).mouseenter(function(){toggleAutoPlay.apply(d)}).mouseleave(function(){toggleAutoPlay.apply(d)})}else if(p.scrollLeftElem!=null&&p.scrollRightElem!=null){j=$(p.scrollRightElem);j.css("visibility","hidden").click(function(){scrollRight.apply(d);if(p.autoPlayClickStop){stopAutoPlay.apply(d)}return false});k=$(p.scrollLeftElem);k.css("visibility","hidden").click(function(){scrollLeft.apply(d);if(p.autoPlayClickStop){stopAutoPlay.apply(d)}return false});h.mouseenter(function(){toggleAutoPlay.apply(d)}).mouseleave(function(){toggleAutoPlay.apply(d)})}}o={imagesVisible:p.imagesVisible,$itemContainer:g,itemWidth:e.outerWidth(),itemHeight:e.outerHeight(),itemSpacing:n,leftIndex:0,scrollerRight:j,scrollerLeft:k,scrollerBottom:l,scrollerTop:m,imageOpacity:p.imageOpacity,imageOpacitySelect:p.imageOpacitySelect,timerID:0,autoPlayInterval:p.autoPlayInterval,autoPlayPaused:false,selected:null,orientation:p.orientation,showScrollButtons:p.showScrollButtons};d.data("DODImageCarouselState",o);setScrollerVisibility.apply(d);d.children().remove().end().hide();if(p.selected!==null){itemClick.apply(d.get(0),[p.selected]);scrollTo.apply(d,[p.selected])}if(p.autoPlay){startAutoPlay.apply(d)}})};function getSelectedIndex(){return(this.data("DODImageCarouselState")).selected}function scrollRight(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");var c=b.$itemContainer.children().length-(b.leftIndex+b.imagesVisible);var d;if(b.imagesVisible<c){d=b.imagesVisible}else{d=c}b.$itemContainer.animate({left:"-="+((b.itemWidth+parseInt(b.itemSpacing,10))*d)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}});b.leftIndex+=d})}function scrollLeft(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");var c;if(b.imagesVisible<b.leftIndex){c=b.imagesVisible}else{c=b.leftIndex}b.$itemContainer.animate({left:"+="+((b.itemWidth+parseInt(b.itemSpacing,10))*c)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}});b.leftIndex-=c})}function scrollDown(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");var c=b.$itemContainer.children().length-(b.leftIndex+b.imagesVisible);var d;if(b.imagesVisible<c){d=b.imagesVisible}else{d=c}b.$itemContainer.animate({top:"-="+((b.itemHeight+parseInt(b.itemSpacing,10))*d)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}});b.leftIndex+=d})}function scrollUp(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");var c;if(b.imagesVisible<b.leftIndex){c=b.imagesVisible}else{c=b.leftIndex}b.$itemContainer.animate({top:"+="+((b.itemHeight+parseInt(b.itemSpacing,10))*c)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}});b.leftIndex-=c})}function select(a){return this.each(function(){itemClick.apply(this,[a]);scrollTo.apply($(this),[a])})}function startAutoPlay(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");if(b.timerID!==0){return false}b.timerID=setInterval(function(){if(b.selected<b.$itemContainer.children().length-1){select.apply(a,[b.selected+1])}else{select.apply(a,[0])}},b.autoPlayInterval)})}function stopAutoPlay(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");if(b.timerID===0&&!b.autoPlayPaused){return false}b.autoPlayPaused=false;clearTimeout(b.timerID);b.timerID=0})}function toggleAutoPlay(){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");if(b.timerID===0){if(b.autoPlayPaused){startAutoPlay.apply(a);b.autoPlayPaused=false}else{return false}}else{stopAutoPlay.apply(a);b.autoPlayPaused=true}})}function itemClick(a){var b=$(this).data("DODImageCarouselState");var c=b.$itemContainer.children().eq(a);var d;if(b.selected==a){return false}var e={index:a,imageURL:b.$itemContainer.children().eq(a).css("background-image"),source:c.get(0)};while(e.imageURL.indexOf("\"")>-1){e.imageURL=e.imageURL.replace("\"","")}e.imageURL=e.imageURL.substring(4,e.imageURL.length-1);$(this).triggerHandler("dodImageCarouselSelect",[e]);b.$itemContainer.children().eq(b.selected).removeClass("DODImageCarouselItemSelected").css("opacity",b.imageOpacity);c.stop().addClass("DODImageCarouselItemSelected").css("opacity",b.imageOpacitySelect);b.selected=a}function scrollTo(e){return this.each(function(){var a=$(this);var b=a.data("DODImageCarouselState");var c=b.$itemContainer.children(".DODImageCarouselItem").length;var d=0;if(b.imagesVisible>=c){return false}if(b.leftIndex==e){return false}if((c-b.imagesVisible)<e){d=(c-b.leftIndex)-b.imagesVisible;b.leftIndex=c-b.imagesVisible}else{d=e-b.leftIndex;b.leftIndex=e}switch(b.orientation){case"vertical":b.$itemContainer.animate({top:"-="+((b.itemHeight+parseInt(b.itemSpacing,10))*d)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}});break;default:b.$itemContainer.animate({left:"-="+((b.itemWidth+parseInt(b.itemSpacing,10))*d)+"px"},{duration:500,complete:function(){setScrollerVisibility.apply(a)}})}})}function setScrollerVisibility(){var a=$(this).data("DODImageCarouselState");if(!a.showScrollButtons){return false}if(a.imagesVisible>=a.$itemContainer.children(".DODImageCarouselItem").length){return false}switch(a.orientation){case"vertical":if(a.leftIndex>0){a.scrollerTop.css("visibility","visible")}else{a.scrollerTop.css("visibility","hidden")}var b=a.$itemContainer.children().length-(a.leftIndex+a.imagesVisible);if(b!==0){a.scrollerBottom.css("visibility","visible")}else{a.scrollerBottom.css("visibility","hidden")}break;default:if(a.leftIndex>0){a.scrollerLeft.css("visibility","visible")}else{a.scrollerLeft.css("visibility","hidden")}var b=a.$itemContainer.children().length-(a.leftIndex+a.imagesVisible);if(b!==0){a.scrollerRight.css("visibility","visible")}else{a.scrollerRight.css("visibility","hidden")}}}})(jQuery)}
