/*
 * swapImage - $ plugin for swapping image(s)
 *
 * Copyright (c) 2010 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
 *
 * Includes patch for additional event and modifications to change it to a multi state engine
 * Copyright 2010 COMMUNITOR Internetservice GmbH
 *
 */
(function(a){a.swapImage=function(c,b,f,g,d,e){a.swapImage.files={};a.swapImage.data={};a.swapImage.uuid=0;a.swapImage.init=function(){var i=++a.swapImage.uuid;a(this).attr("swapImageId",i);var h=a(this).metadata();a.swapImage.data[i]=a.swapImage.data[i]||{};if(typeof h.src!="undefined"){if(a.isArray(h.src)){a.swapImage.data[i]["src"]=h.src[0];if(typeof e!="undefined"){a.swapImage.data[i]["src2"]=h.src[1];a.swapImage.files[h.src[1]]=false}}else{a.swapImage.data[i]["src"]=h.src}a.swapImage.data[i]["pointer"]="osrc";a.swapImage.files[a.swapImage.data[i]["src"]]=false}a.each(a.grep([[h.sin,"sin"],[h.sout,"sout"]],function(j){return(typeof j[0]!="undefined"&&j[0].length>0)}),function(){var k=this[0];var o=this[1];for(var m=0;m<k.length;m++){var j=h[o][m].indexOf(":");var n=h[o][m].substring(0,j);var l=h[o][m].substring(j+1);a.swapImage.data[i][o]=a.swapImage.data[i][o]||[];if(j>1){a.swapImage.data[i][o].push([n,l]);a.swapImage.files[l]=false}else{a.swapImage.data[i][o].push([l])}}})};a.swapImage.preload=function(){a.each(a.swapImage.files,function(j,i){if(i==false){a.swapImage.files[j]=true;var h=new Image();h.src=j}})};a.swapImage.swapIn=function(){a.swapImage.swap(this,"sin")};a.swapImage.swapIn2=function(){a.swapImage.swap(this,"in2")};a.swapImage.swapOut=function(){a.swapImage.swap(this,"sout")};a.swapImage.swap=function(k,h){var l=a(k).attr("swapImageId");if(typeof a.swapImage.data[l][h]!="undefined"){for(var j=0;j<a.swapImage.data[l][h].length;j++){if(a.swapImage.data[l][h][j].length>1){a(a.swapImage.data[l][h][j][0]).attr("src",a.swapImage.data[l][h][j][1])}else{a(a.swapImage.data[l][h][j][0]).each(a.swapImage._swap)}}}else{a.swapImage._swap.call(k,h)}};a.swapImage._swap=function(i){var j=a(this).attr("swapImageId");var h=a.swapImage.data[j];if(typeof h.src!="undefined"&&typeof h.pointer!="undefined"){if(typeof h.osrc=="undefined"){h.osrc=this.src}if(i=="in2"){if(typeof h.src2=="undefined"){return}if(h.pointer!="src2"){h.pointer="src2"}}else{h.pointer=(h.pointer=="osrc"&&i!="sout"?"src":"osrc")}this.src=h[h.pointer]}};a(document).ready(function(){if(typeof f=="undefined"){f=true}if(typeof b=="undefined"){b=true}a(c).each(a.swapImage.init);if(typeof g=="undefined"){g="mouseenter";d="mouseleave"}if(f){if(typeof d!="undefined"){if(typeof e!="undefined"){a(c).bind(g,a.swapImage.swapIn).bind(d,a.swapImage.swapOut).bind(e,a.swapImage.swapIn2)}else{a(c).bind(g,a.swapImage.swapIn).bind(d,a.swapImage.swapOut)}}else{a(c).bind(g,a.swapImage.swapIn)}}else{a(c).one(g,a.swapImage.swapIn)}if(b){a(c).each(a.swapImage.preload)}})}})(jQuery);
