/*
 * Wowwindow, version 0.6.0 beta (2011-02-10)
 * (c) Copyright 2010 Abel Mohler
 * http://wayfarerweb.com/jquery/plugins/wowwindow/
 * Licensed under the MIT license
 * http://wayfarerweb.com/mit.php
 */
(function(f){f.fn.wowwindow=function(l){var k={testMode:false,draggable:false,fixedWindow:false,width:350,height:500,overlay:{background:"#fff",opacity:0.6,zIndex:1000,fixed:true,clickToClose:true,destroyOnClose:false},before:function(){},after:function(){},onclose:function(){},zoom:true,rotate:false,rotations:1,clockwise:true,speed:800,autoplay:true,videoIframe:true,showRelated:true,autoYouTubeThumb:null,closeButton:'<a class="wowwindow-close" title="close" href="javascript:jQuery(document.body).overlayPlayground(\'close\');void(0)">Close</a>',wrapHTML:'<div id="wowwindow-inner"></div>',beforeHTML:'<div class="wowwindow-controlbar">{%close%} <span class="wowwindow-title">{%title%}</span></div>',afterHTML:"",verticalCenter:true,forceImageFade:false,yabbadabbadoo:false};l=l||{};if(l.overlay===false){l.overlay={};l.overlay.overlay=false}if(l.overlay){l.overlay=f.extend(k.overlay,l.overlay)}l=f.extend(k,l);l.overlay.playgroundFixed=l.fixedWindow;l.overlay.onclose=l.onclose;if(l.testMode){if(!window.console){window.console={};window.console.log=function(){}}f.fn.wowwindow.ii=0}var n=a(),i=[],h=Math.round(Math.random()*10000),j=l.clockwise?"+":"-";function m(r){if(this.title){r=r.replace(/\{\%title\%\}/,this.title)}else{if(f(this).find("img").length==1&&f(this).find("*").length==1){var p=f(this).find("img")[0];var q=p.alt||"";r=r.replace(/\{\%title\%\}/,q)}else{r=r.replace(/\{\%title\%\}/,"")}}var o=l.closeButton||"";r=r.replace(/\{\%close\%\}/,o);return r}return this.each(function(){if(f(this).attr("href").match(/\/\/www\.youtube\.com\/watch\?/)&&l.autoYouTubeThumb&&f(this).find(">img").length>0){var o=(document.location.protocol=="https:")?"https://":"http://";f(this).find(">img").eq(0).attr("src",o+"img.youtube.com/vi/"+this.href.split("v=")[1].split("&")[0]+"/"+l.autoYouTubeThumb+".jpg")}f(this).click(function(q){q.preventDefault();var A=this,s=f(this).attr("href").slice(-4);var r=(s==".jpg"||s==".png"||s==".gif"||s==".bmp");var x=false;if(f(this).attr("href").indexOf("#")===0){l.overlay.html='<div id="wowwindow">'+m.call(this,f(f(this).attr("href")).html())+"</div>"}else{if(r){if(i[this.href]&&!l.forceImageFade){l.overlay.html='<div id="wowwindow"><div id="wowwindow-image"><img src="'+this.href+"?"+h+'"></div></div>'}else{l.overlay.html='<div id="wowwindow"><div id="wowwindow-image"><div id="wowwindow-image-loading">&nbsp;</div></div></div>'}}else{x=true;var F="",v;if(this.href.match(/\/\/www\.youtube\.com\/watch\?/)){F="youtube";v=this.href.split("v=")[1].split("&")[0]}else{if(this.href.match(/\/\/vimeo\.com\/([0-9]+)$/)||this.href.match(/\/\/www\.vimeo\.com\/([0-9]+)$/)){F="vimeo";v=this.href.split("//")[1].split("/")[1]}}l.overlay.html='<div id="wowwindow-image"><div id="wowwindow-image-loading">&nbsp;</div></div>';l.overlay.html='<div id="wowwindow">'+l.overlay.html+"</div>"}}if(typeof l.before=="function"){l.before.call(this)}if(x&&F!=""){l.overlay.onclose=function(){f("#wowwindow iframe, #wowwindow-video-flash").remove()}}f(document.body).overlayPlayground(l.overlay);if(x){var p=this.href,C="";switch(F){case"youtube":p="//www.youtube.com/embed/"+v+"?rel="+(l.showRelated?"1":"0")+(l.autoplay?"&autoplay=1":"");C="wowwindow-video wowwindow-video-youtube";if(!l.videoIframe){f('<div id="wowwindow-video-flash"><object width="'+l.width+'" height="'+l.height+'"><param name="movie" value="http://www.youtube.com/v/'+v+"?fs=1&rel="+(l.showRelated?"1":"0")+(l.autoplay?"&autoplay=1":"")+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+v+"?fs=1&rel="+(l.showRelated?"1":"0")+(l.autoplay?"&autoplay=1":"")+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+l.width+'" height="'+l.height+'"></embed></object></div>').appendTo("#wowwindow")}break;case"vimeo":p="http://player.vimeo.com/video/"+v+"?title=0&byline=0&portrait=0"+(l.autoplay?"&autoplay=1":"");C="wowwindow-video wowwindow-video-vimeo";if(!l.videoIframe){f('<div id="wowwindow-video-flash"><object width="'+l.width+'" height="'+l.height+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+v+"&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1"+(l.autoplay?"&autoplay=1":"&autoplay=0")+'&loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+v+"&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00adef&fullscreen=1"+(l.autoplay?"&autoplay=1":"&autoplay=0")+'&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+l.width+'" height="'+l.height+'"></embed></object></div>').appendTo("#wowwindow")}break}if(F==""||l.videoIframe){f(document.createElement("iframe")).attr({id:"wowwindow-iframe",className:C,src:p,height:l.height,width:l.width,type:"text/html",frameBorder:"0"}).css({display:"none"}).load(function(){f(this).fadeIn(300,function(){if(F=="youtube"){f(this).parent().html(f(this).parent().html())}})}).appendTo("#wowwindow")}}if(!l.fixedWindow){f("body > .overlayPlaygroundPlayground").css({top:f(window).scrollTop()+"px"})}f("#wowwindow").click(function(){f.fn.wowwindow.overLayClickDefault=false});if(l.overlay.clickToClose&&!f.fn.wowwindow.overLayClickEventSet){f(document.body).click(function(){if(f.fn.wowwindow.overLayClickDefault){f(document.body).overlayPlayground("close")}f.fn.wowwindow.overLayClickDefault=true});f.fn.wowwindow.overLayClickEventSet=true}f("#wowwindow >*").wrapAll(l.wrapHTML);f("#wowwindow").prepend(m.call(this,l.beforeHTML));f("#wowwindow").append(m.call(this,l.afterHTML));if(x){f("#wowwindow-iframe").parent().height(l.height)}if(l.zoom){f("#wowwindow").scale(0)}if(x){f("#wowwindow").width(l.width+20)}else{if(!r){f("#wowwindow").width(l.width)}else{var w=l.forceImageFade;if(f("#wowwindow-image-loading").length==1||l.forceImageFade){f("#wowwindow").width(f("#wowwindow-image-loading").width()+20);f("#wowwindow-image-loading").parent().height(f("#wowwindow-image-loading").height());w=true}else{var u=f("#wowwindow-image img").width();var E=f("#wowwindow-image img").height();if(l.testMode){f.fn.wowwindow.ii+=1;console.log("!"+f.fn.wowwindow.ii+". "+u+","+E)}if(u){f("#wowwindow").width(u+20)}}}}function B(){f("#wowwindow")[0].style.MozTransform="none";f("#wowwindow")[0].style.WebkitTransform="none";f("#wowwindow")[0].style.transform="none"}function D(){if(!l.draggable||f("#wowwindow .wowwindow-controlbar").length==0){return}var L=true,I,H,G,K,J=false;f("#wowwindow .wowwindow-controlbar").mousedown(function(M){if(L){I=M.pageX;H=M.pageY;if(f("#wowwindow")[0].style.top&&f("#wowwindow")[0].style.left){G=Math.round(parseFloat(f("#wowwindow").css("left").replace(/px/,"")));K=Math.round(parseFloat(f("#wowwindow").css("top").replace(/px/,"")))}else{G=Math.round(f("body > .overlayPlaygroundPlayground").width()/2);K=Math.round(f("body > .overlayPlaygroundPlayground").height()/2)}J=true}L=true});f("#wowwindow .wowwindow-controlbar .wowwindow-close").mousedown(function(){L=false});f(document.body).mousemove(function(Q){if(J){var P=Q.pageX-I,O=Q.pageY-H,N=G+P,M=K+O;f("#wowwindow").css({left:N+"px",top:M+"px"})}});f(window).mouseup(function(){J=false});f("#wowwindow .wowwindow-controlbar").mouseup(function(){J=false})}function z(){if(l.zoom){f(document.body).overlayPlayground("open");f("#wowwindow").animate({scale:"+=1.00"},{queue:false,duration:l.speed,complete:function(){if(n){B();if(typeof l.after=="function"){l.after.call(A)}D.call(this)}}})}else{f(document.body).overlayPlayground("open")}if(l.rotate){f("#wowwindow").animate({rotate:j+"="+(360*l.rotations)+"deg"},{queue:false,duration:l.speed,complete:function(){if(n&&!l.zoom){B();if(!l.zoom&&typeof l.after=="function"){l.after.call(A)}D.call(this)}}})}f("#wowwindow").css({marginTop:"-"+(f("#wowwindow").outerHeight()/2)+"px",marginLeft:"-"+(f("#wowwindow").outerWidth()/2)+"px"});if(n){f("#wowwindow").css({left:q.clientX+"px",top:q.clientY+"px"}).animate({left:(f("body > .overlayPlaygroundPlayground").width()/2)+"px",top:(f("body > .overlayPlaygroundPlayground").height()/2)+"px"},l.speed)}}if(!r||u||w){z.call(this)}else{var t=setInterval(function(){var H=f("#wowwindow-image img").width();var G=f("#wowwindow-image img").height();if(l.testMode){f.fn.wowwindow.ii+=1;console.log("!"+f.fn.wowwindow.ii+". "+H+","+G)}if(H){f("#wowwindow").width(H+20);z.call(A);clearInterval(t)}},1)}if(w){var y=new Image();f(y).attr({id:"wowwindow-loaded-image",src:f(A).attr("href")+"?"+h}).css({position:"absolute",top:"-999em",bottom:"-999em"});f(y).load(function(){var G=this;f(this).appendTo("#wowwindow-image");var H=setInterval(function(){var I=f(G).height();var J=f(G).width();if(l.testMode){f.fn.wowwindow.ii+=1;console.log(f.fn.wowwindow.ii+". "+J+","+I)}if(J){f("#wowwindow").animate({width:(J+20)+"px",marginTop:"-"+((I+20)/2)+"px",marginLeft:"-"+((J+20)/2)+"px"},{queue:l.yabbadabbadoo,duration:300,complete:function(){f("#wowwindow-loaded-image").css({top:"10px",left:"10px",display:"none"}).fadeIn(300)}});f("#wowwindow-loaded-image").parent().animate({height:I+"px"});f(y).unbind("load");clearInterval(H)}},1);i[A.href]=true})}if(!l.zoom&&!l.rotate&&n&&typeof l.after=="function"){B();l.after.call(this);D.call(this)}if(!n&&typeof l.after=="function"){B();l.after.call(this);D.call(this)}return false})})};f.fn.wowWindow=f.fn.WowWindow=f.fn.wowwindow;f.fn.wowwindow.overLayClickEventSet=false;f.fn.wowwindow.overLayClickDefault=true;f.fn.overlayPlayground=function(k){var j={background:"#000",opacity:0.75,zIndex:1000,fixed:true,playgroundFixed:false,html:"",overlay:true,open:true,destroyOnClose:false,onclose:null};var h=true;if(k=="close"){k={open:false}}if(k=="open"){k={open:true};h=false}k=f.extend(j,k);if(typeof k.onclose=="function"){f.fn.overlayPlayground.onclose=k.onclose}else{if(typeof f.fn.overlayPlayground.onclose=="function"){k.onclose=f.fn.overlayPlayground.onclose}}var i=(typeof document.body.style.maxWidth=="undefined")?true:false;return this.each(function(){if(k.open){var n=false;if(f(this).find("> .overlayPlaygroundOverlay, > .overlayPlaygroundPlayground").length>0){n=true;f(this).find("> .overlayPlaygroundOverlay, > .overlayPlaygroundPlayground").show()}f("html,body").css({height:"100%"});if(!h){return}if(k.overlay){var o={opacity:k.opacity,filter:"alpha(opacity="+(k.opacity*100)+")",background:k.background,zIndex:k.zIndex,padding:0,margin:0,height:f(document).height()+"px",width:"100%",left:0,top:0,position:"absolute"};if(n){f(this).find("> .overlayPlaygroundOverlay").css(o)}else{f('<div class="overlayPlaygroundOverlay">&nbsp;</div>').css(o).appendTo(this)}}var l={zIndex:k.zIndex+10,padding:0,margin:0,height:"100%",width:"100%",left:0,top:0,position:(i||!k.playgroundFixed)?"absolute":"fixed"};if(n){f(this).find("> .overlayPlaygroundPlayground").css(l).html(k.html)}else{f('<div class="overlayPlaygroundPlayground"></div>').css(l).html(k.html).appendTo(this);if(i&&k.playgroundFixed){var m=this;f(window).scroll(function(){f(m).find("> .overlayPlaygroundPlayground").css("top",f(window).scrollTop()+"px")});f(window).scroll()}}}else{if(!k.destroyOnClose){f(this).find(".overlayPlaygroundOverlay,.overlayPlaygroundPlayground").hide()}else{f(this).find(".overlayPlaygroundOverlay,.overlayPlaygroundPlayground").remove()}if(typeof k.onclose=="function"){k.onclose.call(this)}}})};function a(){var h=["transform","WebkitTransform","MozTransform","msTransform","OTransform"],i;while(i=h.shift()){if(typeof document.body.style[i]!="undefined"){return true}}return false}function g(i){var h=["transform","WebkitTransform","MozTransform","msTransform","OTransform"];var j;while(j=h.shift()){if(typeof i!="undefined"&&typeof i.style[j]!="undefined"){return j}}return"transform"}var d=f.fn.css;f.fn.css=function(h,i){if(typeof f.props.transform=="undefined"&&(h=="transform"||(typeof h=="object"&&typeof h.transform!="undefined"))){f.props.transform=g(this.get(0))}if(f.props.transform!="transform"){if(h=="transform"){h=f.props.transform;if(typeof i=="undefined"&&jQuery.style){return jQuery.style(this.get(0),h)}}else{if(typeof h=="object"&&typeof h.transform!="undefined"){h[f.props.transform]=h.transform;delete h.transform}}}return d.apply(this,arguments)};var e="deg";f.fn.rotate=function(j){var i=f(this).css("transform")||"none";if(typeof i=="undefined"){return this}if(typeof j=="undefined"){if(i){var h=i.match(/rotate\(([^)]+)\)/);if(h&&h[1]){return h[1]}}return 0}var h=j.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/);if(h){if(h[3]){e=h[3]}f(this).css("transform",i.replace(/none|rotate\([^)]*\)/,"")+"rotate("+h[1]+e+")")}return this};f.fn.scale=function(l,k,i){var j=f(this).css("transform");if(typeof j=="undefined"){return this}if(typeof l=="undefined"){if(j){var h=j.match(/scale\(([^)]+)\)/);if(h&&h[1]){return h[1]}}return 1}f(this).css("transform",j.replace(/none|scale\([^)]*\)/,"")+"scale("+l+")");return this};var c=f.fx.prototype.cur;f.fx.prototype.cur=function(){if(this.prop=="rotate"){return parseFloat(f(this.elem).rotate())}else{if(this.prop=="scale"){return parseFloat(f(this.elem).scale())}}return c.apply(this,arguments)};f.fx.step.rotate=function(h){f(h.elem).rotate(h.now+e)};f.fx.step.scale=function(h){f(h.elem).scale(h.now)};var b=f.fn.animate;f.fn.animate=function(i){if(typeof i!="undefined"&&typeof i.rotate!="undefined"){var h=i.rotate.toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/);if(h&&h[5]){e=h[5]}i.rotate=h[1]}return b.apply(this,arguments)}})(jQuery);
