/*
DBD.slide-gallery 1.1 (September 14, 2011) widget for jQuery
http://distinctbydesign.com
Copyright (c) 2011 Shannon Davenport
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), the rights to use, copy, modify, merge, publish,
distribute the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function($) {$.widget("ui.dbdgallery", {options: {height:200,width:300,imgDir:'',imgNames:[],imgLinks:[],autoScroll:false,scrollDir:'horizontal',scrollDuration:5,controlLocation:'left'},_create : function(){var self = this;self.element.width(self.options.width+55);self._buildSlider();self._attachLinks();},_buildSlider:function(){var self = this;if(!self.options.autoScroll){var c = $('<div/>',{'class':'dbd-sg-control'});if(self.options.controlLocation=='left'){c.css({'float':'left'}).width(55);}else if(self.options.controlLocation=='right'){c.css({'float':'right'}).width(55);}else if(self.options.controlLocation=='bottom' || self.options.controlLocation=='top'){c.width(self.options.width);}var cul = $('<ul/>',{'class':'dbd-sg-control-ul'}).css({'list-style-type':'none','margin':'0','padding':'0'});var li = $('<li/>').append($('<a/>',{'href':'#'}).css({'text-decoration':'none'}).html('previous').click(function(){return self._onPrevClick();}));if(self.options.controlLocation=='top' || self.options.controlLocation=='bottom'){li.css({'float':'left'});}cul.append(li);li = $('<li/>').append($('<a/>',{'href':'#'}).css({'text-decoration':'none'}).html('next').click(function(){return self._onNextClick();}));if(self.options.controlLocation=='top' || self.options.controlLocation=='bottom'){li.css({'float':'right'});}cul.append(li);c.append(cul);}var g = $('<div/>',{'class':'dbd-sg'}).width(self.options.width).height(self.options.height);if(!self.options.autoScroll){if(self.options.controlLocation=='left'){g.css({'overflow':'hidden','float':'right'});}else if(self.options.controlLocation=='right'){g.css({'overflow':'hidden','float':'left'});}else{g.css({'overflow':'hidden'});}}else{g.css({'overflow':'hidden'});}var gul = $('<ul/>',{'class':'dbd-sg-img-ul'}).css({'list-style-type':'none','margin':'0','padding':'0','z-index':'0','overflow':'hidden'});if(self.options.scrollDir=='horizontal'){gul.width((self.options.width)*self.options.imgNames.length);}g.append(gul);$.each(self.options.imgNames,function(i,img){var li = $('<li/>').height(self.options.height).css({'float':'left'});if(i==0){li.addClass('selected');}var img = $('<img/>',{'id':'dbd-sg-img-'+i,'src':self.options.imgDir+'/'+img});li.append(img);gul.append(li);if($('#dbd-sg-img-'+i).width() > self.options.width){$('#dbd-sg-img-'+i).width(self.options.width);$('#dbd-sg-img-'+i).height(self.options.height);}});if(!self.options.autoScroll){if(self.options.controlLocation=='top' || self.options.controlLocation=='left'){self.element.append(c);if(self.options.controlLocation=='top'){self.element.append($('<div/>').css({'clear':'both'}));}self.element.append(g);}else{self.element.append(g);self.element.append(c);}}else{self.element.append(g);self._onAutoScroll();}},_attachLinks:function(){var self = this;if(self.options.imgLinks.length > 0){$.each(self.options.imgLinks,function(i,link){if(link != ''){$('#dbd-sg-img-'+i).css({'cursor':'pointer'});$('#dbd-sg-img-'+i).click(function(){window.open('http:\/\/'+link);});}});}},_onNextClick:function(){var curr_img = ($('.dbd-sg-img-ul li.selected').length ? $('.dbd-sg-img-ul li.selected') : $('.dbd-sg-img-ul li:first'));var next_img;if(curr_img.next().length){next_img = curr_img.next();$('.dbd-sg').scrollTo(next_img, this.options.scrollDuration*100);}else{next_img = $('.dbd-sg-img-ul li:first');$('.dbd-sg').scrollTo(next_img, 1);}$('.dbd-sg-img-ul li').removeClass('selected');next_img.addClass('selected');return false;},_onPrevClick:function(){var curr_img = ($('.dbd-sg-img-ul li.selected').length ? $('.dbd-sg-img-ul li.selected') : $('.dbd-sg-img-ul li:first'));var next_img;if(curr_img.prev().length){next_img = curr_img.prev();$('.dbd-sg').scrollTo(next_img, this.options.scrollDuration*100);}else{next_img = $('.dbd-sg-img-ul li:last');$('.dbd-sg').scrollTo(next_img, 1);}$('.dbd-sg-img-ul li').removeClass('selected');next_img.addClass('selected');return false;},_onAutoScroll:function(){var self = this;setInterval(function(){self._onNextClick();}, this.options.scrollDuration*1000);}});})(jQuery);
