/*
jQuery Plugin: Sideswap v 1.0.3
Author: BrianBlocker.com
Tools: Dreamweaver CS4 / 2009 iMac (early edition) / 2009 Mac Mini (late edition)
modified by mike howard 20100512 to make it grab selected tags (defaults to img) and strip any other html
also added ability to pass a list of images so they load a little later
added detection of msie for pngs - ie can't transition transparent pngs so the transition speed is set to 0 20100705
fixed msie pngs where the faded element may not have been an image 2010831
modified the png transparency issue to a setting so you can still have fading non transparent pngs mh 20110429

example usage:
jQuery(document).ready(function() {
	jQuery('#block-block-25').sideswap({selector:'a'});
});

'#block-block-25' is id of the containing element
{selector:'a'} selects elements that can get faded within the containing element

*/
(function(jQuery){jQuery.fn.sideswap=function(options){var opts={navigation:false,previous:'prev',next:'next',display_time:5000,transition_speed:200,auto_run:true,selector:'img',delete_other_html:false,hover_stop:true,transparent_pngs:false,images:[]};if(options)jQuery.extend(opts,options);var clicked=false;return this.each(function(){var img_count=opts.images.length;if(img_count>0){var imgsrc=jQuery(opts.selector,this).get(0).src;var path=imgsrc.substr(0,imgsrc.lastIndexOf('/')+1);for(var i=0;i<img_count;i++){jQuery('<img src="'+path+opts.images[i]+'" />').appendTo(this)}}var $this=jQuery(this),$parent=$this.parent(),timer=false,$images,count;if(opts.delete_other_html){$images=jQuery(opts.selector,this).clone();$this.empty()}else{$images=jQuery(opts.selector,this)}if(opts.delete_other_html){$images.appendTo(this)}count=$images.size();if(count&&opts.transparent_pngs&&jQuery.browser.msie){var img=$images.get(0);if(img.tagName.toLowerCase()!='img'){img=jQuery('img',img).get(0)}if(img&&img.src.substr(img.src.length-3).toLowerCase()=='png'){opts.transition_speed=0}}setup();function setup(){$this.css('position','relative');$images.css({"display":"block","position":"absolute","top":"0px","left":"0px"}).removeClass('hide').hide();$this.children(opts.selector+':first').show();if(opts.navigation&&count>1){createNavigation()}if(opts.auto_run&&count>1){initiateInterval();if(opts.hover_stop){$parent.hover(function(){clearInterval(timer)},function(){initiateInterval()})}}}function rotate(direction){var $current_image=$this.children(':visible:first')=='undefined'?$this.children(':first'):$this.children(':visible:first'),$previous_image=$current_image.prev()=='undefined'||$current_image.prev().html()==null?$this.children(':last'):$current_image.prev(),$next_image=$current_image.next()=='undefined'||$current_image.next().html()==null?$this.children(':first'):$current_image.next();if(count>1){$current_image.fadeOut(opts.transition_speed);switch(direction){case-1:$previous_image.fadeIn(opts.transition_speed,function(){clicked=false});break;default:$next_image.fadeIn(opts.transition_speed,function(){clicked=false});break}}}function createNavigation(){var $div=jQuery('<DIV></DIV>'),$next=$div.clone().addClass('sideswap_nav sideswap_next').html(opts.next).appendTo($parent).hide(),$previous=$div.clone().addClass('sideswap_nav sideswap_previous').html(opts.previous).appendTo($parent).hide();$next.click(function(){if(!clicked){clicked=true;rotate(1)}});$previous.click(function(){if(!clicked){clicked=true;rotate(-1)}});$parent.hover(function(){$next.fadeIn(opts.transition_speed);$previous.fadeIn(opts.transition_speed)},function(){$next.fadeOut(opts.transition_speed);$previous.fadeOut(opts.transition_speed)})}function initiateInterval(){timer=setInterval(function(){rotate()},opts.display_time)}})}})(jQuery);
