/*
 * Flip! jQuery Plugin (http://lab.smashup.it/flip/)
 * @author Luca Manno (luca@smashup.it) [http://i.smashup.it]
 * 		[Original idea by Nicola Rizzo (thanks!)]
 * 
 * @version 0.5
 * 
 * @changelog
 * v 0.5	->  Added patch to make it work with Opera (thanks to Peter Siewert), Added callbacks [Feb. 1, 2008]
 * v 0.4.1 	->	Fixed a regression in Chrome and Safari caused by getTransparent [Oct. 1, 2008]
 * v 0.4 	->	Fixed some bugs with transparent color. Now Flip! works on non-white backgrounds | Update: jquery.color.js plugin or jqueryUI still needed :( [Sept. 29, 2008]
 * v 0.3 	->	Now is possibile to define the content after the animation.
 * 				(jQuery object or text/html is allowed) [Sept. 25, 2008]
 * v 0.2 	->	Fixed chainability and buggy innertext rendering (xNephilimx thanks!)
 * v 0.1 	->	Starting release [Sept. 11, 2008]
 * 
 */
(function(c){var e,b,d;e=function(f){for(var g=0;g<f.parents().length;g++){b=f.parents().get(g);d=c.browser.safari?c(b).css("background"):c(b).css("background-color");if(d!=""&&d!="transparent"){return d}}};function a(f){f.elem.style[f.prop]=parseInt(f.now)+f.unit}jQuery.extend(jQuery.fx.step,{borderTopWidth:a,borderBottomWidth:a,borderLeftWidth:a,borderRightWidth:a});jQuery.fn.flip=function(f){return this.each(function(){var m,i,l,k,h,j;m=c(this);if(m.data("flipLock")){return false}else{m.data("flipLock",1)}i={width:m.width(),height:m.height(),bgColor:f.bgColor||m.css("background-color"),fontSize:m.css("font-size")||"12px",direction:f.direction||"tb",toColor:f.color||"#f00",speed:f.speed||500,top:m.offset().top,left:m.offset().left,target:f.content||null,transparent:e(m)||"#fff",onBefore:f.onBefore||function(){},onEnd:f.onEnd||function(){},onAnimation:f.onAnimation||function(){}};l="flipClone_"+(new Date()).getTime();m.css("visibility","hidden").clone(true).appendTo("body").html("").css({visibility:"visible",position:"absolute",left:i.left,top:i.top,margin:0,zIndex:9999}).attr("id",l);k={tb:{start:{fontSize:"0px",lineHeight:"0px",borderTopWidth:i.height,borderLeftWidth:"0px",borderRightWidth:"0px",borderBottomWidth:"0px",borderTopColor:i.bgColor,borderBottomColor:i.transparent,borderLeftColor:i.transparent,borderRightColor:i.transparent,borderStyle:"solid",height:"0px",width:i.width},first:{borderTopWidth:"0px",borderLeftWidth:(i.height/100)*15,borderRightWidth:(i.height/100)*15,borderBottomWidth:"0px",borderTopColor:"#999",borderBottomColor:"#999",borderLeftColor:i.transparent,borderRightColor:i.transparent,top:(i.top+(i.height/2)),left:(i.left-(i.height/100)*15)},second:{borderBottomWidth:i.height,borderTopWidth:"0px",borderLeftWidth:"0px",borderRightWidth:"0px",borderTopColor:i.transparent,borderBottomColor:i.toColor,borderLeftColor:i.transparent,borderRightColor:i.transparent,top:i.top,left:i.left}},bt:{start:{fontSize:"0px",lineHeight:"0px",borderTopWidth:"0px",borderLeftWidth:"0px",borderRightWidth:"0px",borderBottomWidth:i.height,borderTopColor:i.transparent,borderBottomColor:i.bgColor,borderLeftColor:i.transparent,borderRightColor:i.transparent,borderStyle:"solid",height:"0px",width:i.width},first:{borderTopWidth:"0px",borderLeftWidth:(i.height/100)*15,borderRightWidth:(i.height/100)*15,borderBottomWidth:"0px",borderTopColor:"#999",borderBottomColor:"#999",borderLeftColor:i.transparent,borderRightColor:i.transparent,top:(i.top+(i.height/2)),left:(i.left-(i.height/100)*15)},second:{borderTopWidth:i.height,borderLeftWidth:"0px",borderRightWidth:"0px",borderBottomWidth:"0px",borderTopColor:i.toColor,borderBottomColor:i.transparent,borderLeftColor:i.transparent,borderRightColor:i.transparent,top:i.top,left:i.left}},lr:{start:{width:"0px",fontSize:"0px",lineHeight:"0px",borderTopWidth:"0px",borderLeftWidth:i.width,borderRightWidth:"0px",borderBottomWidth:"0px",borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:i.bgColor,borderRightColor:i.transparent,borderStyle:"solid",height:i.height},first:{borderTopWidth:(i.height/100)*10,borderLeftWidth:"0px",borderRightWidth:"0px",borderBottomWidth:(i.height/100)*10,borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:"#999",borderRightColor:"#999",top:i.top-(i.height/100)*10,left:i.left+(i.width/2)},second:{borderTopWidth:"0px",borderLeftWidth:"0px",borderRightWidth:i.width,borderBottomWidth:"0px",borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:i.transparent,borderRightColor:i.toColor,top:i.top,left:i.left}},rl:{start:{width:"0px",fontSize:"0px",lineHeight:"0px",borderTopWidth:"0px",borderLeftWidth:"0px",borderRightWidth:i.width,borderBottomWidth:"0px",borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:i.transparent,borderRightColor:i.bgColor,borderStyle:"solid",height:i.height},first:{borderTopWidth:(i.height/100)*10,borderLeftWidth:"0px",borderRightWidth:"0px",borderBottomWidth:(i.height/100)*10,borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:"#999",borderRightColor:"#999",top:i.top-(i.height/100)*10,left:i.left+(i.width/2)},second:{borderTopWidth:"0px",borderLeftWidth:i.width,borderRightWidth:"0px",borderBottomWidth:"0px",borderTopColor:i.transparent,borderBottomColor:i.transparent,borderLeftColor:i.toColor,borderRightColor:i.transparent,top:i.top,left:i.left}}};h=m;j=function(){var n=i.target;return n&&n.jquery?n.html():n};function g(o,n){o.queue(function(){i.onBefore();o.html("").css(k[i.direction].start);o.dequeue()});o.animate(k[i.direction].first,i.speed);o.queue(function(){i.onAnimation();o.dequeue()});o.animate(k[i.direction].second,i.speed);o.queue(function(){n.css({backgroundColor:i.toColor,visibility:"visible"});var p=j();if(p){n.html(p)}o.remove();i.onEnd();n.removeData("flipLock");o.dequeue()})}g(c("#"+l),h)})}})(jQuery);