// VERSION: 1.6 LAST UPDATE: 21.08.2010
/*
 * THIS IS FREE SCRIPT BUT LEAVE THIS COMMENT IF
 * YOU WANT USE THIS CODE ON YOUR SITE
 * 
 * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
 * http://wilq32.blogspot.com
 * 
 */
(function(f){for(var g,j=document.getElementsByTagName("head")[0].style,i="transformProperty WebkitTransform OTransform".split(" "),h=0;h<i.length;h++)if(j[i[h]]!==undefined)g=i[h];var IE = "v"=="\v";jQuery.fn.extend({ImageRotate:function(b){if(!(this.Wilq32&&this.Wilq32.PhotoEffect)){b=f.extend(true,{},b);return(new Wilq32.PhotoEffect(this.get(0),b))._temp}},rotate:function(b){if(!(this.length===0||typeof b=="undefined")){if(typeof b=="number")b={angle:b};for(var a=[],c=0,d=this.length;c<
d;c++){var e=this.get(c);typeof e.Wilq32=="undefined"?a.push(f(f(e).ImageRotate(b))):e.Wilq32.PhotoEffect._rotate(b.angle)}return a}},rotateAnimation:function(b){if(!(this.length===0||typeof b=="undefined")){if(typeof b=="number")b={animateAngle:b};for(var a=[],c=0,d=this.length;c<d;c++){var e=this.get(c);typeof e.Wilq32=="undefined"?a.push(f(f(e).ImageRotate(b))):e.Wilq32.PhotoEffect.rotateAnimation(b)}return a}}});Wilq32=window.Wilq32||{};Wilq32.PhotoEffect=function(){function b(a,c){this._img=
a;this._parameters=c||{};this._parameters.angle=this._angle=c.angle||0;this._parameters.animateAngle=typeof c.animateAngle=="number"?c.animateAngle:this._angle}return g?function(a,c){b.call(this,a,c);a.Wilq32={PhotoEffect:this};this._temp=this._img;this._BindEvents(a,this._parameters.bind);this._rotate(this._parameters.angle);this._parameters.angle!=this._parameters.animateAngle&&this.rotateAnimation(this._parameters)}:function(a,c){b.call(this,a,c);this._parameters.className=a.className;this._parameters.id=
a.getAttribute("id");this._temp=document.createElement("span");this._temp.style.display="inline-block";this._temp.Wilq32={PhotoEffect:this};a.parentNode.insertBefore(this._temp,a);if(a.complete)this._Loader();else{var d=this;jQuery(this._img).bind("load",function(){d._Loader()})}}}();Wilq32.PhotoEffect.prototype={rotateAnimation:function(b){this._parameters.animateAngle=b.animateAngle;this._parameters.callback=b.callback||this._parameters.callback||function(){};this._animateStart()},_BindEvents:function(b,
a){if(a)for(var c in a)if(a.hasOwnProperty(c))for(var d in a[c])a[c].hasOwnProperty(d)&&jQuery(b).bind(d,a[c][d])},_Loader:function(){function b(){this._rotate(this._parameters.angle);this._parameters.angle!=this._parameters.animateAngle&&this.rotateAnimation(this._parameters)}return IE?function(){var a=this._img.width,c=this._img.height;this._img.parentNode.removeChild(this._img);this._vimage=this.createVMLNode("image");this._vimage.src=this._img.src;this._vimage.style.height=c+"px";this._vimage.style.width=
a+"px";this._vimage.style.position="absolute";this._vimage.style.top="0px";this._vimage.style.left="0px";this._container=this.createVMLNode("group");this._container.style.width=a;this._container.style.height=c;this._container.style.position="absolute";this._container.setAttribute("coordsize",a-1+","+(c-1));this._container.appendChild(this._vimage);this._temp.appendChild(this._container);this._temp.style.position="relative";this._temp.style.width=a+"px";this._temp.style.height=c+"px";this._temp.setAttribute("id",
this._parameters.id);this._temp.className=this._parameters.className;this._BindEvents(this._temp,this._parameters.bind);b.call(this)}:function(){this._temp.setAttribute("id",this._parameters.id);this._temp.className=this._parameters.className;this._width=this._img.width;this._height=this._img.height;this._widthHalf=this._width/2;this._heightHalf=this._height/2;var a=Math.sqrt(this._height*this._height+this._width*this._width);this._widthAdd=a-this._width;this._heightAdd=a-this._height;this._widthAddHalf=
this._widthAdd/2;this._heightAddHalf=this._heightAdd/2;this._img.parentNode.removeChild(this._img);this._canvas=document.createElement("canvas");this._canvas.setAttribute("width",this._width);this._canvas.style.position="relative";this._canvas.style.left=-this._widthAddHalf+"px";this._canvas.style.top=-this._heightAddHalf+"px";this._canvas.Wilq32=this._temp.Wilq32;this._temp.appendChild(this._canvas);this._temp.style.width=this._width+"px";this._temp.style.height=this._height+"px";this._BindEvents(this._canvas,
this._parameters.bind);this._cnv=this._canvas.getContext("2d");b.call(this)}}(),_animateStart:function(){this._timer&&clearTimeout(this._timer);this._animate()},_animate:function(){var b=!!Math.round(this._angle*100-this._parameters.animateAngle*100)==0&&!!this._timer;this._parameters.callback&&b&&this._parameters.callback();if(b&&!this._parameters.animatedGif)clearTimeout(this._timer);else{if(this._canvas||this._vimage||this._img){this._angle-=(this._angle-this._parameters.animateAngle)*0.1;if(typeof this._parameters.minAngle!=
"undefined")this._angle=Math.max(this._angle,this._parameters.minAngle);if(typeof this._parameters.maxAngle!="undefined")this._angle=Math.min(this._angle,this._parameters.maxAngle);this._rotate(~~(this._angle*10)/10)}var a=this;this._timer=setTimeout(function(){a._animate.call(a)},10)}},_rotate:function(){var b=Math.PI/180;return IE?function(a){this._container.style.rotation=a+"deg"}:g?function(a){this._img.style[g]="rotate("+a+"deg)"}:function(a){if(!(!this._img.width||typeof a!="number")){a=a%360*
b;this._canvas.width=this._width+this._widthAdd;this._canvas.height=this._height+this._heightAdd;this._cnv.translate(this._widthAddHalf,this._heightAddHalf);this._cnv.translate(this._widthHalf,this._heightHalf);this._cnv.rotate(a);this._cnv.translate(-this._widthHalf,-this._heightHalf);this._cnv.drawImage(this._img,0,0)}}}()};if(IE)Wilq32.PhotoEffect.prototype.createVMLNode=function(){document.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{!document.namespaces.rvml&&document.namespaces.add("rvml",
"urn:schemas-microsoft-com:vml");return function(a){return document.createElement("<rvml:"+a+' class="rvml">')}}catch(b){return function(a){return document.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}}()})(jQuery);
