/**
 * swapImage - jQuery plugin for swapping image
 *
 * Copyright (c) 2008 tszming (tszming@gmail.com)
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
(function(jQuery){jQuery.swapImage=function(i,preload,repeat,swapInEvent,swapOutEvent){jQuery.swapImage.files={};jQuery.swapImage.data={};jQuery.swapImage.init=function(){var id=jQuery.data(this);var data=jQuery(this).metadata();jQuery.swapImage.data[id]=jQuery.swapImage.data[id]||{};if(typeof data.src!="undefined"){jQuery.swapImage.data[id]["src"]=data.src;jQuery.swapImage.files[data.src]=false}jQuery.each(jQuery.grep([[data.sin,"sin"],[data.sout,"sout"]],function(n){return(typeof n[0]!="undefined"&&n[0].length>0)}),function(){var arr=this[0];var vname=this[1];for(var i=0;i<arr.length;i++){var idx=data[vname][i].indexOf(":");var selection=data[vname][i].substring(0,idx);var file=data[vname][i].substring(idx+1);jQuery.swapImage.data[id][vname]=jQuery.swapImage.data[id][vname]||[];if(idx>1){jQuery.swapImage.data[id][vname].push([selection,file]);jQuery.swapImage.files[file]=false}else{jQuery.swapImage.data[id][vname].push([file])}}})};jQuery.swapImage.preload=function(){jQuery.each(jQuery.swapImage.files,function(k,v){if(v==false){jQuery.swapImage.files[k]=true;var img=new Image();img.src=k}})};jQuery.swapImage.swapIn=function(){jQuery.swapImage.swap(this,"sin")};jQuery.swapImage.swapOut=function(){jQuery.swapImage.swap(this,"sout")};jQuery.swapImage.swap=function(obj,a){var id=jQuery.data(obj);if(typeof jQuery.swapImage.data[id][a]!="undefined"){for(var i=0;i<jQuery.swapImage.data[id][a].length;i++){if(jQuery.swapImage.data[id][a][i].length>1){jQuery(jQuery.swapImage.data[id][a][i][0]).attr("src",jQuery.swapImage.data[id][a][i][1])}else{jQuery(jQuery.swapImage.data[id][a][i][0]).each(jQuery.swapImage._swap)}}}else{jQuery.swapImage._swap.call(obj)}};jQuery.swapImage._swap=function(obj){var id=jQuery.data(this);var data=jQuery.swapImage.data[id];if(typeof data.src!="undefined"){var tmp=data.src;data.src=this.src;this.src=tmp}};jQuery(document).ready(function(){if(typeof repeat=="undefined"){repeat=true}if(typeof preload=="undefined"){preload=true}jQuery(i).each(jQuery.swapImage.init);if(typeof swapInEvent=="undefined"&&typeof swapInEvent=="undefined"){swapInEvent="mouseenter";swapOutEvent="mouseleave"}if(repeat){if(typeof swapOutEvent!="undefined"){jQuery(i).bind(swapInEvent,jQuery.swapImage.swapIn).bind(swapOutEvent,jQuery.swapImage.swapOut)}else{jQuery(i).bind(swapInEvent,jQuery.swapImage.swapIn)}}else{jQuery(i).one(swapInEvent,jQuery.swapImage.swapIn)}if(preload){jQuery(i).each(jQuery.swapImage.preload)}})}})(jQuery);
