/*
bxGallery v1.1
Plugin developed by: Steven Wanderski
http://bxgalleryplugin.com
http://stevenwanderski.com

Released under the GPL license:
http://www.gnu.org/licenses/gpl.html

v.1.6.2 by RUff - Webway IT Labs - 2010

*/
(function($){$.event.special.load={setup:function(data,namespaces,hollaback){var retVal=false;if(this.tagName.toLowerCase()==='img'&&this.src!==""){if(this.complete||this.readyState===4){$(this).bind('load',data||{},hollaback).trigger('load');retVal=true}else if(this.readyState==='uninitialized'&&this.src.indexOf('data:')>=0){$(this).trigger('error');retVal=true}}return retVal}}}(jQuery));(function($){$.fn.extend({bxGallery:function(options){var defaults={maxwidth:'',maxheight:'',minheight:'',thumbwidth:110,thumbcrop:false,croppercent:.35,opacity:.7,load_text:'',load_image:'/_pic/cb/loading.gif',thumbsclass:'photo_thumbs',zoomlink:'',onStart:false,onComplete:false,onImage:false};var options=$.extend(defaults,options);var o=options;var cont='';var $outer='';var $orig=this;var $mask=$('<i></i>').addClass('mask');var $thumbs=$('.'+o.thumbsclass);if(o.zoomlink!='')var $zoom=$('.'+o.zoomlink);var tall=0;var wide=0;var showing=0;var i=0;var k=$orig.find('img').size();var current;if(o.onStart)o.onStart.call(this);preload_img();function preload_img(){$orig.hide();if(o.load_text!=''){$orig.before('<div id="loading">'+o.load_text+'</div>')}else{$orig.before('<div id="loading"><img src="'+o.load_image+'" /></div>')}$orig.parent().find('#loading').css({'width':o.maxwidth,'height':o.minheight});$orig.find('img').each(function(){var the_source=$(this).attr('src');var the_img=new Image();$(the_img).bind('load',function(){preload_check()});the_img.src=the_source})}function preload_check(){i++;if(i==k){init()}}function init(){set_layout();set_main_img();place_thumbcontainer();set_thumbs();if(o.zoomlink!='')$zoom.css('visibility','visible');if(o.onComplete)o.onComplete.call(this)}function set_layout(){$orig.parent().find('#loading').hide();$orig.show();$outer=$orig.parent();$orig.find('li').css({'position':'absolute'});if(o.zoomlink!='')$zoom.css('visiblity','visible')}function set_main_img(){$orig.find('img').each(function(){var $this=$(this);var $imgheight=$this.height();var $imgwidth=$this.width();if($this.attr('title')!=''){}if(o.maxwidth!=''){if($this.width()>o.maxwidth){$this.width(o.maxwidth);$this.height(($imgheight/$imgwidth)*o.maxwidth)}}if(o.maxheight!=''){if($this.height()>o.maxheight){$this.height(o.maxheight);$this.width(($imgwidth/$imgheight)*o.maxheight)}}if($this.height()>tall){tall=$this.outerHeight()}if($this.width()>wide){wide=$this.outerWidth()}cont+='<li><img src="'+$this.attr('src')+'" /></li>'});$orig.find('li:not(:first)').hide();$orig.height(tall);$orig.width(wide);if(o.zoomlink!=''){$orig.find('a').click(function(){return false});var currentlink=$orig.find('li:first a').attr('href');$zoom.attr('href',currentlink)}}function place_thumbcontainer(){$thumbs.append('<ul class="lst dib">'+cont+'</ul>')}function set_thumbs(){$thumbs.find('li').each(function(){var $this=$(this);var $img=$this.find('img');var $imgwidth=$img.width();var $imgheight=$img.height();if(o.thumbcrop){$img.width($imgwidth*o.croppercent);$img.height(($imgheight/$imgwidth)*$img.width());$this.css({'float':'left','width':o.thumbwidth,'height':o.thumbwidth,'overflow':'hidden','cursor':'pointer'})}else{$img.width(o.thumbwidth);$img.height(($imgheight/$imgwidth)*o.thumbwidth);$this.css({'cursor':'pointer'})}$this.click(function(){var x=$thumbs.find('li').index($this);if(showing!=x){$orig.find('li').fadeOut();$orig.find('li').eq(x).fadeIn();if(o.zoomlink!=''){var currentlink=$orig.find('li').eq(x).find('a').attr('href');$zoom.attr('href',currentlink)}showing=x}})});var $thumb=$thumbs.find('li');$thumb.eq(0).addClass('on').css('cursor','default').append($mask.clone());$thumb.not('.on').fadeTo(0,o.opacity);$thumb.click(function(){var t=$(this);var i=$thumb.index(this);if(current!=i){$('.'+$mask.attr('class')).remove();t.append($mask.clone());$thumb.removeClass('on').css('cursor','pointer');t.addClass('on').css('cursor','default');$thumb.not('.on').fadeTo(200,o.opacity);current=i}if(o.onImage)o.onImage.call(this)}).hover(function(){$(this).stop().fadeTo(200,1)},function(){$(this).not('.on').stop().fadeTo(200,o.opacity)})}}})})(jQuery);
