/**
 * jGestures: a jQuery plugin for gesture events 
 * Copyright 2010, Neue Digitale / Razorfish GmbH

 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 * 
 * This is still a beta version, bugfixes and improvements appreciated.
 * @copyright Neue Digitale / Razorfish GmbH 
 * @author martin.krause@neue-digitale.de
 * @version 0.87
 * 
 * @requires 
 * jQuery JavaScript Library v1.4.2 - http://jquery.com/
 * 	Copyright 2010, John Resig
 * 	Dual licensed under the MIT or GPL Version 2 licenses.
 * 	http://jquery.org/license
 */
(function(b){b.jGestures={};b.jGestures.defaults={};b.jGestures.defaults.thresholdPinchopen=0.05;b.jGestures.defaults.thresholdPinchmove=0.05;b.jGestures.defaults.thresholdPinch=0.05;b.jGestures.defaults.thresholdPinchclose=0.05;b.jGestures.defaults.thresholdRotatecw=5;b.jGestures.defaults.thresholdRotateccw=5;b.jGestures.defaults.thresholdMove=20;b.jGestures.defaults.thresholdSwipe=100;b.jGestures.data={};b.jGestures.data.capableDevicesInUserAgentString=["iPad","iPhone","iPod","Mobile Safari"];b.jGestures.data.hasGestures=(function(){var j;for(j=0;j<b.jGestures.data.capableDevicesInUserAgentString.length;j++){if(navigator.userAgent.indexOf(b.jGestures.data.capableDevicesInUserAgentString[j])!==-1){return true}}return false})();b.hasGestures=b.jGestures.data.hasGestures;b.jGestures.events={touchstart:"jGestures.touchstart",touchendStart:"jGestures.touchend;start",touchendProcessed:"jGestures.touchend;processed",gesturestart:"jGestures.gesturestart",gestureendStart:"jGestures.gestureend;start",gestureendProcessed:"jGestures.gestureend;processed"};jQuery.each({orientationchange_orientationchange01:"orientationchange",gestureend_pinchopen01:"pinchopen",gestureend_pinchclose01:"pinchclose",gestureend_rotatecw01:"rotatecw",gestureend_rotateccw01:"rotateccw",gesturechange_pinch01:"pinch",gesturechange_rotate01:"rotate",touchstart_swipe13:"swipemove",touchstart_swipe01:"swipeone",touchstart_swipe02:"swipetwo",touchstart_swipe03:"swipethree",touchstart_swipe04:"swipefour",touchstart_swipe05:"swipeup",touchstart_swipe06:"swiperightup",touchstart_swipe07:"swiperight",touchstart_swipe08:"swiperightdown",touchstart_swipe09:"swipedown",touchstart_swipe10:"swipeleftdown",touchstart_swipe11:"swipeleft",touchstart_swipe12:"swipeleftup",touchstart_tap01:"tapone",touchstart_tap02:"taptwo",touchstart_tap03:"tapthree",touchstart_tap04:"tapfour"},function(k,j){jQuery.event.special[j]={setup:function(){var q=k.split("_");var n=q[0];var l=q[1].slice(0,q[1].length-2);var o=jQuery(this);if(!o.data("ojQueryGestures")||!o.data("ojQueryGestures")[n]){var p=o.data("ojQueryGestures")||{};var m={};m[n]=true;b.extend(true,p,m);o.data("ojQueryGestures",p);if(b.hasGestures){switch(l){case"orientationchange":o.get(0).addEventListener("orientationchange",a,false);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":o.get(0).addEventListener("touchstart",g,false);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":o.get(0).addEventListener("gesturestart",d,false);o.get(0).addEventListener("gestureend",h,false);break;case"pinch":case"rotate":o.get(0).addEventListener("gesturestart",d,false);o.get(0).addEventListener("gesturechange",e,false);break}}else{switch(l){case"tap":case"swipe":o.bind("mousedown",g);break;case"orientationchange":case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":case"pinch":case"rotate":break}}}return false},add:function(m){var l=jQuery(this);var n=l.data("ojQueryGestures");n[m.type]={originalType:m.type};return false},remove:function(m){var l=jQuery(this);var n=l.data("ojQueryGestures");n[m.type]=false;l.data("ojQueryGestures",n);return false},teardown:function(){var q=k.split("_");var n=q[0];var l=q[1].slice(0,q[1].length-2);var o=jQuery(this);if(!o.data("ojQueryGestures")||!o.data("ojQueryGestures")[n]){var p=o.data("ojQueryGestures")||{};var m={};m[n]=false;b.extend(true,p,m);o.data("ojQueryGestures",p);if(b.hasGestures){switch(l){case"orientationchange":o.get(0).removeEventListener("orientationchange",a,false);break;case"tap":case"swipe":case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":o.get(0).removeEventListener("touchstart",g,false);o.get(0).removeEventListener("touchmove",f,false);o.get(0).removeEventListener("touchend",i,false);break;case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":o.get(0).removeEventListener("gesturestart",d,false);o.get(0).removeEventListener("gestureend",h,false);break;case"pinch":case"rotate":o.get(0).removeEventListener("gesturestart",d,false);o.get(0).removeEventListener("gesturechange",e,false);break}}else{switch(l){case"tap":case"swipe":o.unbind("mousedown",g);o.unbind("mousemove",f);o.unbind("mouseup",i);break;case"orientationchange":case"pinchopen":case"pinchclose":case"rotatecw":case"rotateccw":case"pinch":case"rotate":break}}}return false}}});function c(j){j.startMove=(j.startMove)?j.startMove:{startX:null,startY:null,timestamp:null};var k=new Date().getTime();if(j.touches){var m=[{lastX:j.deltaX,lastY:j.deltaY,moved:null,startX:j.screenX-j.startMove.screenX,startY:j.screenY-j.startMove.screenY}];var l={vector:j.vector,orientation:window.orientation||null,lastX:((m[0].lastX>0)?+1:((m[0].lastX<0)?-1:0)),lastY:((m[0].lastY>0)?+1:((m[0].lastY<0)?-1:0)),startX:((m[0].startX>0)?+1:((m[0].startX<0)?-1:0)),startY:((m[0].startY>0)?+1:((m[0].startY<0)?-1:0))};m[0].moved=Math.sqrt(Math.pow(Math.abs(m[0].startX),2)+Math.pow(Math.abs(m[0].startY),2))}return{type:j.type||null,originalEvent:j.event||null,delta:m||null,direction:l||{orientation:window.orientation||null,vector:j.vector||null},duration:(j.startMove.timestamp)?k-j.timestamp:null,rotation:j.rotation||null,scale:j.scale||null,description:j.description||[j.type,":",j.touches,":",((m[0].lastX!=0)?((m[0].lastX>0)?"right":"left"):"steady"),":",((m[0].lastY!=0)?((m[0].lastY>0)?"down":"up"):"steady")].join("")}}function a(k){var j=["landscape:clockwise:","portrait:default:","landscape:counterclockwise:","portrait:upsidedown:"];b(window).triggerHandler("orientationchange",{direction:{orientation:window.orientation},description:["orientationchange:",j[((window.orientation/90)+1)],window.orientation].join("")})}function g(k){var j=jQuery(k.currentTarget);j.triggerHandler(b.jGestures.events.touchstart,k);if(b.hasGestures){k.currentTarget.addEventListener("touchmove",f,false);k.currentTarget.addEventListener("touchend",i,false)}else{j.bind("mousemove",f);j.bind("mouseup",i)}var m=j.data("ojQueryGestures");var l=(k.touches)?k.touches[0]:k;var n={};n.oLastSwipemove={screenX:l.screenX,screenY:l.screenY,timestamp:new Date().getTime()};n.oStartTouch={screenX:l.screenX,screenY:l.screenY,timestamp:new Date().getTime()};j.data("ojQueryGestures",b.extend(true,m,n))}function f(s){var u=jQuery(s.currentTarget);var r=u.data("ojQueryGestures");var p=!!s.touches;var k=(p)?s.changedTouches[0].screenX:s.screenX;var j=(p)?s.changedTouches[0].screenY:s.screenY;var q=r.oLastSwipemove;var n=k-q.screenX;var m=j-q.screenY;if(!!r.oLastSwipemove){var t=c({type:"swipemove",touches:(p)?s.touches.length:"1",screenY:j,screenX:k,deltaY:m,deltaX:n,startMove:q,event:s,timestamp:q.timestamp});u.triggerHandler(t.type,t)}var l={};var o=(s.touches)?s.touches[0]:s;l.oLastSwipemove={screenX:o.screenX,screenY:o.screenY,timestamp:new Date().getTime()};u.data("ojQueryGestures",b.extend(true,r,l))}function i(q){var u=jQuery(q.currentTarget);var w=!!q.changedTouches;var t=(w)?q.changedTouches.length:"1";var o=(w)?q.changedTouches[0].screenX:q.screenX;var n=(w)?q.changedTouches[0].screenY:q.screenY;u.triggerHandler(b.jGestures.events.touchendStart,q);if(b.hasGestures){q.currentTarget.removeEventListener("touchmove",f,false);q.currentTarget.removeEventListener("touchend",i,false)}else{u.unbind("mousemove",f);u.unbind("mouseup",i)}var l=u.data("ojQueryGestures");var x=(Math.abs(l.oStartTouch.screenX-o)>b.jGestures.defaults.thresholdMove||Math.abs(l.oStartTouch.screenY-n)>b.jGestures.defaults.thresholdMove)?true:false;var A=(Math.abs(l.oStartTouch.screenX-o)>b.jGestures.defaults.thresholdSwipe||Math.abs(l.oStartTouch.screenY-n)>b.jGestures.defaults.thresholdSwipe)?true:false;var z;for(z in l){var s=l.oStartTouch;var m={};var o=(w)?q.changedTouches[0].screenX:q.screenX;var n=(w)?q.changedTouches[0].screenY:q.screenY;var k=o-s.screenX;var j=n-s.screenY;var p=c({type:"swipe",touches:t,screenY:n,screenX:o,deltaY:j,deltaX:k,startMove:s,event:q,timestamp:s.timestamp});var v=["zero","one","two","three","four"];var r=false;switch(z){case"swipeone":if(w===false&&t==1&&x===false){break}if(w===false||(t==1&&x===true&&A===true)){r=true;p.type=["swipe",v[t]].join("");u.triggerHandler(p.type,p)}break;case"swipetwo":if((w&&t==2&&x===true&&A===true)){r=true;p.type=["swipe",v[t]].join("");u.triggerHandler(p.type,p)}break;case"swipethree":if((w&&t==3&&x===true&&A===true)){r=true;p.type=["swipe",v[t]].join("");u.triggerHandler(p.type,p)}break;case"swipefour":if((w&&t==4&&x===true&&A===true)){r=true;p.type=["swipe",v[t]].join("");u.triggerHandler(p.type,p)}break;case"swipeup":case"swiperightup":case"swiperight":case"swiperightdown":case"swipedown":case"swipeleftdown":case"swipeleft":case"swipeleftup":if(w&&x===true&&A===true){r=true;p.type=["swipe",((p.delta[0].lastX!=0)?((p.delta[0].lastX>0)?"right":"left"):""),((p.delta[0].lastY!=0)?((p.delta[0].lastY>0)?"down":"up"):"")].join("");u.triggerHandler(p.type,p)}break;case"tapone":case"taptwo":case"tapthree":case"tapfour":if((x!==true&&r!==true)&&(v[t]==z.slice(3))){p.description=["tap",v[t]].join("");p.type=["tap",v[t]].join("");u.triggerHandler(p.type,p)}break}var y={};u.data("ojQueryGestures",b.extend(true,l,y));u.data("ojQueryGestures",b.extend(true,l,y))}u.triggerHandler(b.jGestures.events.touchendProcessed,q)}function d(k){var j=jQuery(k.currentTarget);j.triggerHandler(b.jGestures.events.gesturestart,k);var l=j.data("ojQueryGestures");var m={};m.oStartTouch={timestamp:new Date().getTime()};j.data("ojQueryGestures",b.extend(true,l,m))}function e(k){var j=jQuery(k.currentTarget);var o,l,q,n;var p=j.data("ojQueryGestures");var m;for(m in p){switch(m){case"pinch":o=k.scale;if(((o<1)&&(o%1)<(1-b.jGestures.defaults.thresholdPinchclose))||((o>1)&&(o%1)>(b.jGestures.defaults.thresholdPinchopen))){l=(o<1)?-1:+1;n=c({type:"pinch",scale:o,touches:null,startMove:p.oStartTouch,event:k,timestamp:p.oStartTouch.timestamp,vector:l,description:["pinch:",l,":",((o<1)?"close":"open")].join("")});j.triggerHandler(n.type,n)}break;case"rotate":o=k.rotation;if(((o<1)&&(-1*(o)>b.jGestures.defaults.thresholdRotateccw))||((o>1)&&(o>b.jGestures.defaults.thresholdRotatecw))){l=(o<1)?-1:+1;n=c({type:"rotate",rotation:o,touches:null,startMove:p.oStartTouch,event:k,timestamp:p.oStartTouch.timestamp,vector:l,description:["rotate:",l,":",((o<1)?"counterclockwise":"clockwise")].join("")});j.triggerHandler(n.type,n)}break}}}function h(k){var j=jQuery(k.currentTarget);j.triggerHandler(b.jGestures.events.gestureendStart,k);var m;var n=j.data("ojQueryGestures");var l;for(l in n){switch(l){case"pinchclose":m=k.scale;if((m<1)&&(m%1)<(1-b.jGestures.defaults.thresholdPinchclose)){j.triggerHandler("pinchclose",c({type:"pinchclose",scale:m,vector:-1,touches:null,startMove:n.oStartTouch,event:k,timestamp:n.oStartTouch.timestamp,description:"pinch:-1:close"}))}break;case"pinchopen":m=k.scale;if((m>1)&&(m%1)>(b.jGestures.defaults.thresholdPinchopen)){j.triggerHandler("pinchopen",c({type:"pinchopen",scale:m,vector:+1,touches:null,startMove:n.oStartTouch,event:k,timestamp:n.oStartTouch.timestamp,description:"pinch:+1:open"}))}break;case"rotatecw":m=k.rotation;if((m>1)&&(m>b.jGestures.defaults.thresholdRotatecw)){j.triggerHandler("rotatecw",c({type:"rotatecw",rotation:m,vector:+1,touches:null,startMove:n.oStartTouch,event:k,timestamp:n.oStartTouch.timestamp,description:"rotate:+1:clockwise"}))}break;case"rotateccw":m=k.rotation;if((m<1)&&(-1*(m)>b.jGestures.defaults.thresholdRotateccw)){j.triggerHandler("rotateccw",c({type:"rotateccw",rotation:m,vector:-1,touches:null,startMove:n.oStartTouch,event:k,timestamp:n.oStartTouch.timestamp,description:"rotate:-1:counterclockwise"}))}break}}j.triggerHandler(b.jGestures.events.gestureendProcessed,k)}})(jQuery);(function(a){function p(b,c,d){var e=a('<div id="uGallery">').css({position:"fixed",top:0,left:0,width:"100%",height:"100%",overflow:"hidden"}).data("sources",b).appendTo("body");d.loadingIndicatorImageURL&&e.data("loadingIndicatorImageURL",d.loadingIndicatorImageURL);d.arrowNavigation&&e.data("hasArrows",!0);a('<div id="uGalleryOverlay">').css({position:"absolute",top:0,left:0,width:"100%",height:"100%",backgroundColor:d.background_color,opacity:d.background_alpha,zIndex:5}).appendTo(e);if(d.arrowNavigation){var g=
a('<div id="uGalleryArrowLeft">').css({position:"absolute",top:0,width:"2%",height:"100%",paddingLeft:"1.5%",paddingRight:"1.5%",textAlign:"center",display:"inline-block",clear:"both",zIndex:99999,opacity:0}),f=a(g).clone();a(g).css({left:0}).appendTo(e);var h=new Image;a(h).css({maxWidth:"100%",cursor:"pointer"});a(h).attr("src",d.arrowsImages.left);a(h).appendTo(g);a(h).load(i);a(f).attr("id","uGalleryArrowRight").css({right:0}).appendTo(e);g=a(h).clone();a(g).attr("src",d.arrowsImages.right);a(g).appendTo(f);
a(g).load(i)}b.each(function(c){var f=a('<div class="uGalleryImageHolder">').css({position:"absolute",top:0,left:0,width:"100%",height:"100%",backgroundPosition:"center center",backgroundRepeat:"no-repeat",textAlign:"center",display:"none",zIndex:10+c}).appendTo(e),g=new Image;a(g).attr("url",a.proxy(d.fullSizeImage,b.get(c))());a(g).load(q);a(g).css({maxHeight:"90%",maxWidth:"90%",height:"auto",width:"auto",display:"inline-block",opacity:0}).appendTo(f);d.showCaption&&(f=a('<div class="uGalleryImageTitle">').css({width:"90%",
height:"9%",paddingTop:"1%",textAlign:"center",display:"inline-block",clear:"both",color:d.text_color,opacity:0}).appendTo(f),c=a.proxy(d.getCaption,b.get(c))(),a(f).html(c))});l(c);d.arrowNavigation&&m()}function j(){var b=a("#uGallery").data("sources");try{b.removeClass("opened")}catch(c){}a(document).unbind("keydown",n);a("#uGallery .uGalleryImageHolder").unbind("click",j);a("#uGallery #uGalleryArrowLeft img").unbind("click");a("#uGallery #uGalleryArrowRight img").unbind("click");a("#uGallery").empty();
a("#uGallery").remove()}function i(b){var b=a(b.target),c=a(b).parent(),d=a(b).height(),c=a(c).height();if(d==0)d=a(b).scrollHeight;d=(c-d)/2;a(b).css({paddingTop:d+"px"})}function q(b){i(b);b=a(this).parents(".uGalleryImageHolder");o(b);a(this).animate({opacity:1},100,function(){a("#uGallery").data("hasArrows")&&r()});b.find(".uGalleryImageTitle").animate({opacity:1},200)}function l(b){b=typeof b=="number"?a("#uGallery .uGalleryImageHolder").eq(b):a(b);o(b);var c=b.find("img");c.attr("src",c.attr("url"));
b.css({display:"block"})}function o(b){if(a(b).css("backgroundImage")=="none"){var c=a("#uGallery").data("loadingIndicatorImageURL");c&&a(b).css("background-image","url('"+c+"')")}else a(b).css({backgroundImage:"none"})}function m(){var b=a("#uGallery #uGalleryArrowLeft"),c=a("#uGallery #uGalleryArrowRight");a(b).css("opacity")<1&&a(b).css({opacity:1});a(c).css("opacity")<1&&a(c).css({opacity:1});a("#uGallery #uGalleryArrowLeft").fadeOut(100);a("#uGallery #uGalleryArrowRight").fadeOut(100)}function r(){var b=
e();k(b,1).length>0&&a("#uGallery #uGalleryArrowLeft").fadeIn(100,function(){i({target:a(this).find("img")})});k(b,-1).length>0&&a("#uGallery #uGalleryArrowRight").fadeIn(100,function(){i({target:a(this).find("img")})})}function s(b){b=a(b).find("img");b.attr("src","");b.css({opacity:0});a(this).parents(".uGalleryImageHolder").find("uGalleryImageTitle").css({opacity:0})}function k(b,c){return c==1?a(b).prev(".uGalleryImageHolder"):a(b).next(".uGalleryImageHolder")}function f(b,c){c!=1&&c!=-1&&(c=
-1);k(b,c).length>0?(a("#uGallery").data("hasArrows")&&m(),a(b).animate({left:a(b).outerWidth()*c+"px"},{duration:100,complete:function(){a(this).css({display:"none"});s(this);var b=k(this,c);a(b).css({display:"block",left:0});l(b)}})):a(b).animate({left:a(b).outerWidth()*c/10+"px"},{duration:25,complete:function(){a(b).animate({left:0},{duration:50})}})}function e(){return a("#uGallery .uGalleryImageHolder:visible")}function n(a){if(a.keyCode==37)return f(e(),1),!1;if(a.keyCode==39)return f(e(),
-1),!1;a.keyCode==27&&j();return!1}function t(a,c){f(e(),c.direction.vector)}function u(){a("#uGallery .uGalleryImageHolder").live("click",j);a(document).bind("keydown",n);jQuery().jGestures&&(a("#uGallery").live("swipeone",t),a("#uGallery").live("tapone",j));a("#uGallery #uGalleryArrowLeft img").live("click",function(){f(e(),1)});a("#uGallery #uGalleryArrowRight img").live("click",function(){f(e(),-1)})}a.fn.uGallery=function(b){var b=a.extend({},a.fn.uGallery.defaults,b),c=this;this.live("click",
function(d){d.preventDefault();a(this).is(".opened")||(c.addClass("opened"),p(c,c.index(a(this)),b),u())});return this};a.fn.uGallery.defaults={fullSizeImage:function(){return a(this).attr("href")},showCaption:!1,getCaption:function(){return a(this).find("img").attr("alt")},background_color:"#000",background_alpha:1,text_color:"#FFF",arrowNavigation:!1}})(jQuery);
$(document).ready(function(){jQuery.get("device_aware/saveScreenResolution",{width:screen.width,height:screen.height})});
$(document).ready(function(){initImageGallery();initFeatureSlideShow()});
function initImageGallery(){$(".image_croper").length>0&&($(".image_croper").mousemove(function(a){var c=$(this).width(),b=$(this).offset().left,d=$(this).find("img:last").position().left,e=$(this).find("img:last").width(),a=(d+e-c+40)*(100/(c/(a.pageX-b)))/100;$(this).find(".image_slider").animate({left:-a},0)}),$(".image_slider a").uGallery({background_alpha:1,showCaption:!0,loadingIndicatorImageURL:"themes/ap/images/uGallery/loadingIndicator.gif",arrowNavigation:!0,arrowsImages:{left:"themes/ap/images/uGallery/left.gif",
right:"themes/ap/images/uGallery/right.gif"}}),$(".image .piece_pick a").uGallery({background_alpha:1,showCaption:!0,loadingIndicatorImageURL:"themes/ap/images/uGallery/loadingIndicator.gif",arrowNavigation:!0,arrowsImages:{left:"themes/ap/images/uGallery/left.gif",right:"themes/ap/images/uGallery/right.gif"},getCaption:function(){return $(this).attr("title")}}))}
function initFeatureSlideShow(){$(".featured.slideshow").length>0&&$(".featured.slideshow").each(function(){$(this).find(".project").each(function(a){$(this).css({zIndex:5+a})});$(this).find(".project.first").toggleClass("active");var a=$(this);setInterval(function(){featureSlideShow(a)},4E3)})}
function featureSlideShow(a){var c=$(a).find(".project").length,b=$(a).find(".active").next(".project");$(b).length<=0&&(b=$(a).find(".project.first"));$(b).css({zIndex:5+c});$(a).find(".active").css({zIndex:5});$(a).find(".active").find("h2").fadeOut(100);$(a).find(".active").find(".tags").fadeOut(100);$(b).css({left:0});$(b).find("h2").hide();$(b).find(".tags").hide();$(b).fadeIn(500,function(){$(this).find("h2").fadeIn(200);$(this).find(".tags").fadeIn(200);var a=$(this).parents(".slideshow").find(".active");
$(a).toggleClass("active");$(a).hide();$(this).toggleClass("active")})};

