/* 
 * flowplayer.js 3.2.4. The Flowplayer API
 * 
 * Copyright 2009 Flowplayer Oy
 * 
 * This file is part of Flowplayer.
 * 
 * Flowplayer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Flowplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Date: 2010-08-25 12:48:46 +0000 (Wed, 25 Aug 2010)
 * Revision: 551 
 */
(function(){function g(o){console.log("$f.fireEvent",[].slice.call(o))}function k(q){if(!q||typeof q!="object"){return q}var o=new q.constructor();for(var p in q){if(q.hasOwnProperty(p)){o[p]=k(q[p])}}return o}function m(t,q){if(!t){return}var o,p=0,r=t.length;if(r===undefined){for(o in t){if(q.call(t[o],o,t[o])===false){break}}}else{for(var s=t[0];p<r&&q.call(s,p,s)!==false;s=t[++p]){}}return t}function c(o){return document.getElementById(o)}function i(q,p,o){if(typeof p!="object"){return q}if(q&&p){m(p,function(r,s){if(!o||typeof s!="function"){q[r]=s}})}return q}function n(s){var q=s.indexOf(".");if(q!=-1){var p=s.slice(0,q)||"*";var o=s.slice(q+1,s.length);var r=[];m(document.getElementsByTagName(p),function(){if(this.className&&this.className.indexOf(o)!=-1){r.push(this)}});return r}}function f(o){o=o||window.event;if(o.preventDefault){o.stopPropagation();o.preventDefault()}else{o.returnValue=false;o.cancelBubble=true}return false}function j(q,o,p){q[o]=q[o]||[];q[o].push(p)}function e(){return"_"+(""+Math.random()).slice(2,10)}var h=function(t,r,s){var q=this,p={},u={};q.index=r;if(typeof t=="string"){t={url:t}}i(this,t,true);m(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var v="on"+this;if(v.indexOf("*")!=-1){v=v.slice(0,v.length-1);var w="onBefore"+v.slice(2);q[w]=function(x){j(u,w,x);return q}}q[v]=function(x){j(u,v,x);return q};if(r==-1){if(q[w]){s[w]=q[w]}if(q[v]){s[v]=q[v]}}});i(this,{onCuepoint:function(x,w){if(arguments.length==1){p.embedded=[null,x];return q}if(typeof x=="number"){x=[x]}var v=e();p[v]=[x,w];if(s.isLoaded()){s._api().fp_addCuepoints(x,r,v)}return q},update:function(w){i(q,w);if(s.isLoaded()){s._api().fp_updateClip(w,r)}var v=s.getConfig();var x=(r==-1)?v.clip:v.playlist[r];i(x,w,true)},_fireEvent:function(v,y,w,A){if(v=="onLoad"){m(p,function(B,C){if(C[0]){s._api().fp_addCuepoints(C[0],r,B)}});return false}A=A||q;if(v=="onCuepoint"){var z=p[y];if(z){return z[1].call(s,A,w)}}if(y&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(v)!=-1){i(A,y);if(y.metaData){if(!A.duration){A.duration=y.metaData.duration}else{A.fullDuration=y.metaData.duration}}}var x=true;m(u[v],function(){x=this.call(s,A,y,w)});return x}});if(t.onCuepoint){var o=t.onCuepoint;q.onCuepoint.apply(q,typeof o=="function"?[o]:o);delete t.onCuepoint}m(t,function(v,w){if(typeof w=="function"){j(u,v,w);delete t[v]}});if(r==-1){s.onCuepoint=this.onCuepoint}};var l=function(p,r,q,t){var o=this,s={},u=false;if(t){i(s,t)}m(r,function(v,w){if(typeof w=="function"){s[v]=w;delete r[v]}});i(this,{animate:function(y,z,x){if(!y){return o}if(typeof z=="function"){x=z;z=500}if(typeof y=="string"){var w=y;y={};y[w]=z;z=500}if(x){var v=e();s[v]=x}if(z===undefined){z=500}r=q._api().fp_animate(p,y,z,v);return o},css:function(w,x){if(x!==undefined){var v={};v[w]=x;w=v}r=q._api().fp_css(p,w);i(o,r);return o},show:function(){this.display="block";q._api().fp_showPlugin(p);return o},hide:function(){this.display="none";q._api().fp_hidePlugin(p);return o},toggle:function(){this.display=q._api().fp_togglePlugin(p);return o},fadeTo:function(y,x,w){if(typeof x=="function"){w=x;x=500}if(w){var v=e();s[v]=w}this.display=q._api().fp_fadeTo(p,y,x,v);this.opacity=y;return o},fadeIn:function(w,v){return o.fadeTo(1,w,v)},fadeOut:function(w,v){return o.fadeTo(0,w,v)},getName:function(){return p},getPlayer:function(){return q},_fireEvent:function(w,v,x){if(w=="onUpdate"){var z=q._api().fp_getPlugin(p);if(!z){return}i(o,z);delete o.methods;if(!u){m(z.methods,function(){var B=""+this;o[B]=function(){var C=[].slice.call(arguments);var D=q._api().fp_invoke(p,B,C);return D==="undefined"||D===undefined?o:D}});u=true}}var A=s[w];if(A){var y=A.apply(o,v);if(w.slice(0,1)=="_"){delete s[w]}return y}return o}})};function b(q,G,t){var w=this,v=null,D=false,u,s,F=[],y={},x={},E,r,p,C,o,A;i(w,{id:function(){return E},isLoaded:function(){return(v!==null&&v.fp_play!==undefined&&!D)},getParent:function(){return q},hide:function(H){if(H){q.style.height="0px"}if(w.isLoaded()){v.style.height="0px"}return w},show:function(){q.style.height=A+"px";if(w.isLoaded()){v.style.height=o+"px"}return w},isHidden:function(){return w.isLoaded()&&parseInt(v.style.height,10)===0},load:function(J){if(!w.isLoaded()&&w._fireEvent("onBeforeLoad")!==false){var H=function(){u=q.innerHTML;if(u&&!flashembed.isSupported(G.version)){q.innerHTML=""}if(J){J.cached=true;j(x,"onLoad",J)}flashembed(q,G,{config:t})};var I=0;m(a,function(){this.unload(function(K){if(++I==a.length){H()}})})}return w},unload:function(J){if(this.isFullscreen()&&/WebKit/i.test(navigator.userAgent)){if(J){J(false)}return w}if(u.replace(/\s/g,"")!==""){if(w._fireEvent("onBeforeUnload")===false){if(J){J(false)}return w}D=true;try{if(v){v.fp_close();w._fireEvent("onUnload")}}catch(H){}var I=function(){v=null;q.innerHTML=u;D=false;if(J){J(true)}};setTimeout(I,50)}else{if(J){J(false)}}return w},getClip:function(H){if(H===undefined){H=C}return F[H]},getCommonClip:function(){return s},getPlaylist:function(){return F},getPlugin:function(H){var J=y[H];if(!J&&w.isLoaded()){var I=w._api().fp_getPlugin(H);if(I){J=new l(H,I,w);y[H]=J}}return J},getScreen:function(){return w.getPlugin("screen")},getControls:function(){return w.getPlugin("controls")._fireEvent("onUpdate")},getLogo:function(){try{return w.getPlugin("logo")._fireEvent("onUpdate")}catch(H){}},getPlay:function(){return w.getPlugin("play")._fireEvent("onUpdate")},getConfig:function(H){return H?k(t):t},getFlashParams:function(){return G},loadPlugin:function(K,J,M,L){if(typeof M=="function"){L=M;M={}}var I=L?e():"_";w._api().fp_loadPlugin(K,J,M,I);var H={};H[I]=L;var N=new l(K,null,w,H);y[K]=N;return N},getState:function(){return w.isLoaded()?v.fp_getState():-1},play:function(I,H){var J=function(){if(I!==undefined){w._api().fp_play(I,H)}else{w._api().fp_play()}};if(w.isLoaded()){J()}else{if(D){setTimeout(function(){w.play(I,H)},50)}else{w.load(function(){J()})}}return w},getVersion:function(){var I="flowplayer.js 3.2.4";if(w.isLoaded()){var H=v.fp_getVersion();H.push(I);return H}return I},_api:function(){if(!w.isLoaded()){throw"Flowplayer "+w.id()+" not loaded when calling an API method"}return v},setClip:function(H){w.setPlaylist([H]);return w},getIndex:function(){return p},_swfHeight:function(){return v.clientHeight}});m(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),function(){var H="on"+this;if(H.indexOf("*")!=-1){H=H.slice(0,H.length-1);var I="onBefore"+H.slice(2);w[I]=function(J){j(x,I,J);return w}}w[H]=function(J){j(x,H,J);return w}});m(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled").split(","),function(){var H=this;w[H]=function(J,I){if(!w.isLoaded()){return w}var K=null;if(J!==undefined&&I!==undefined){K=v["fp_"+H](J,I)}else{K=(J===undefined)?v["fp_"+H]():v["fp_"+H](J)}return K==="undefined"||K===undefined?w:K}});w._fireEvent=function(Q){if(typeof Q=="string"){Q=[Q]}var R=Q[0],O=Q[1],M=Q[2],L=Q[3],K=0;if(t.debug){g(Q)}if(!w.isLoaded()&&R=="onLoad"&&O=="player"){v=v||c(r);o=w._swfHeight();m(F,function(){this._fireEvent("onLoad")});m(y,function(S,T){T._fireEvent("onUpdate")});s._fireEvent("onLoad")}if(R=="onLoad"&&O!="player"){return}if(R=="onError"){if(typeof O=="string"||(typeof O=="number"&&typeof M=="number")){O=M;M=L}}if(R=="onContextMenu"){m(t.contextMenu[O],function(S,T){T.call(w)});return}if(R=="onPluginEvent"||R=="onBeforePluginEvent"){var H=O.name||O;var I=y[H];if(I){I._fireEvent("onUpdate",O);return I._fireEvent(M,Q.slice(3))}return}if(R=="onPlaylistReplace"){F=[];var N=0;m(O,function(){F.push(new h(this,N++,w))})}if(R=="onClipAdd"){if(O.isInStream){return}O=new h(O,M,w);F.splice(M,0,O);for(K=M+1;K<F.length;K++){F[K].index++}}var P=true;if(typeof O=="number"&&O<F.length){C=O;var J=F[O];if(J){P=J._fireEvent(R,M,L)}if(!J||P!==false){P=s._fireEvent(R,M,L,J)}}m(x[R],function(){P=this.call(w,O,M);if(this.cached){x[R].splice(K,1)}if(P===false){return false}K++});return P};function B(){if($f(q)){$f(q).getParent().innerHTML="";p=$f(q).getIndex();a[p]=w}else{a.push(w);p=a.length-1}A=parseInt(q.style.height,10)||q.clientHeight;E=q.id||"fp"+e();r=G.id||E+"_api";G.id=r;t.playerId=E;if(typeof t=="string"){t={clip:{url:t}}}if(typeof t.clip=="string"){t.clip={url:t.clip}}t.clip=t.clip||{};if(q.getAttribute("href",2)&&!t.clip.url){t.clip.url=q.getAttribute("href",2)}s=new h(t.clip,-1,w);t.playlist=t.playlist||[t.clip];var I=0;m(t.playlist,function(){var K=this;if(typeof K=="object"&&K.length){K={url:""+K}}m(t.clip,function(L,M){if(M!==undefined&&K[L]===undefined&&typeof M!="function"){K[L]=M}});t.playlist[I]=K;K=new h(K,I,w);F.push(K);I++});m(t,function(K,L){if(typeof L=="function"){if(s[K]){s[K](L)}else{j(x,K,L)}delete t[K]}});m(t.plugins,function(K,L){if(L){y[K]=new l(K,L,w)}});if(!t.plugins||t.plugins.controls===undefined){y.controls=new l("controls",null,w)}y.canvas=new l("canvas",null,w);u=q.innerHTML;function J(L){var K=w.hasiPadSupport&&w.hasiPadSupport();if(/iPad|iPhone|iPod/i.test(navigator.userAgent)&&!/.flv$/i.test(F[0].url)&&!K){return true}if(!w.isLoaded()&&w._fireEvent("onBeforeClick")!==false){w.load()}return f(L)}function H(){if(u.replace(/\s/g,"")!==""){if(q.addEventListener){q.addEventListener("click",J,false)}else{if(q.attachEvent){q.attachEvent("onclick",J)}}}else{if(q.addEventListener){q.addEventListener("click",f,false)}w.load()}}setTimeout(H,0)}if(typeof q=="string"){var z=c(q);if(!z){throw"Flowplayer cannot access element: "+q}q=z;B()}else{B()}}var a=[];function d(o){this.length=o.length;this.each=function(p){m(o,p)};this.size=function(){return o.length}}window.flowplayer=window.$f=function(){var p=null;var o=arguments[0];if(!arguments.length){m(a,function(){if(this.isLoaded()){p=this;return false}});return p||a[0]}if(arguments.length==1){if(typeof o=="number"){return a[o]}else{if(o=="*"){return new d(a)}m(a,function(){if(this.id()==o.id||this.id()==o||this.getParent()==o){p=this;return false}});return p}}if(arguments.length>1){var t=arguments[1],q=(arguments.length==3)?arguments[2]:{};if(typeof t=="string"){t={src:t}}t=i({bgcolor:"#000000",version:[9,0],expressInstall:"http://static.flowplayer.org/swf/expressinstall.swf",cachebusting:true},t);if(typeof o=="string"){if(o.indexOf(".")!=-1){var s=[];m(n(o),function(){s.push(new b(this,k(t),k(q)))});return new d(s)}else{var r=c(o);return new b(r!==null?r:o,t,q)}}else{if(o){return new b(o,t,q)}}}return null};i(window.$f,{fireEvent:function(){var o=[].slice.call(arguments);var q=$f(o[0]);return q?q._fireEvent(o.slice(1)):null},addPlugin:function(o,p){b.prototype[o]=p;return $f},each:m,extend:i});if(typeof jQuery=="function"){jQuery.fn.flowplayer=function(q,p){if(!arguments.length||typeof arguments[0]=="number"){var o=[];this.each(function(){var r=$f(this);if(r){o.push(r)}});return arguments.length?o[arguments[0]]:new d(o)}return this.each(function(){$f(this,k(q),p?k(p):{})})}}})();(function(){var h=document.all,j="http://www.adobe.com/go/getflashplayer",c=typeof jQuery=="function",e=/(\d+)[^\d]+(\d+)[^\d]*(\d*)/,b={width:"100%",height:"100%",id:"_"+(""+Math.random()).slice(9),allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:[3,0],onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}function i(m,l){if(l){for(var f in l){if(l.hasOwnProperty(f)){m[f]=l[f]}}}return m}function a(f,n){var m=[];for(var l in f){if(f.hasOwnProperty(l)){m[l]=n(f[l])}}return m}window.flashembed=function(f,m,l){if(typeof f=="string"){f=document.getElementById(f.replace("#",""))}if(!f){return}if(typeof m=="string"){m={src:m}}return new d(f,i(i({},b),m),l)};var g=i(window.flashembed,{conf:b,getVersion:function(){var m,f;try{f=navigator.plugins["Shockwave Flash"].description.slice(16)}catch(o){try{m=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");f=m&&m.GetVariable("$version")}catch(n){try{m=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");f=m&&m.GetVariable("$version")}catch(l){}}}f=e.exec(f);return f?[f[1],f[3]]:[0,0]},asString:function(l){if(l===null||l===undefined){return null}var f=typeof l;if(f=="object"&&l.push){f="array"}switch(f){case"string":l=l.replace(new RegExp('(["\\\\])',"g"),"\\$1");l=l.replace(/^\s?(\d+\.?\d+)%/,"$1pct");return'"'+l+'"';case"array":return"["+a(l,function(o){return g.asString(o)}).join(",")+"]";case"function":return'"function()"';case"object":var m=[];for(var n in l){if(l.hasOwnProperty(n)){m.push('"'+n+'":'+g.asString(l[n]))}}return"{"+m.join(",")+"}"}return String(l).replace(/\s/g," ").replace(/\'/g,'"')},getHTML:function(o,l){o=i({},o);var n='<object width="'+o.width+'" height="'+o.height+'" id="'+o.id+'" name="'+o.id+'"';if(o.cachebusting){o.src+=((o.src.indexOf("?")!=-1?"&":"?")+Math.random())}if(o.w3c||!h){n+=' data="'+o.src+'" type="application/x-shockwave-flash"'}else{n+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'}n+=">";if(o.w3c||h){n+='<param name="movie" value="'+o.src+'" />'}o.width=o.height=o.id=o.w3c=o.src=null;o.onFail=o.version=o.expressInstall=null;for(var m in o){if(o[m]){n+='<param name="'+m+'" value="'+o[m]+'" />'}}var p="";if(l){for(var f in l){if(l[f]){var q=l[f];p+=f+"="+(/function|object/.test(typeof q)?g.asString(q):q)+"&"}}p=p.slice(0,-1);n+='<param name="flashvars" value=\''+p+"' />"}n+="</object>";return n},isSupported:function(f){return k[0]>f[0]||k[0]==f[0]&&k[1]>=f[1]}});var k=g.getVersion();function d(f,n,m){if(g.isSupported(n.version)){f.innerHTML=g.getHTML(n,m)}else{if(n.expressInstall&&g.isSupported([6,65])){f.innerHTML=g.getHTML(i(n,{src:n.expressInstall}),{MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title})}else{if(!f.innerHTML.replace(/\s/g,"")){f.innerHTML="<h2>Flash version "+n.version+" or greater is required</h2><h3>"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"</h3>"+(f.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='"+j+"'>here</a></p>");if(f.tagName=="A"){f.onclick=function(){location.href=j}}}if(n.onFail){var l=n.onFail.call(this);if(typeof l=="string"){f.innerHTML=l}}}}if(h){window[n.id]=document.getElementById(n.id)}i(this,{getRoot:function(){return f},getOptions:function(){return n},getConf:function(){return m},getApi:function(){return f.firstChild}})}if(c){jQuery.tools=jQuery.tools||{version:"3.2.4"};jQuery.tools.flashembed={conf:b};jQuery.fn.flashembed=function(l,f){return this.each(function(){$(this).data("flashembed",flashembed(this,l,f))})}}})();

/*
 * ipad.js 3.2.1. The Flowplayer API
 *
 * Copyright 2010 Flowplayer Oy
 * By Thomas Dubois <thomas@flowplayer.org>
 *
 * This file is part of Flowplayer.
 *
 * Flowplayer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Flowplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Date: 2010-08-25 17:40:08 +0000 (Wed, 25 Aug 2010)
 * Revision: 4219
 */
$f.addPlugin("ipad",function(r){var H=-1;var s=0;var t=1;var F=2;var w=3;var B=4;var f=5;var e=this;var J=1;var I=false;var y=false;var o=false;var m=0;var G=[];var c={accelerated:false,autoBuffering:false,autoPlay:true,baseUrl:null,bufferLength:3,connectionProvider:null,cuepointMultiplier:1000,cuepoints:[],controls:{},duration:0,extension:"",fadeInSpeed:1000,fadeOutSpeed:1000,image:false,linkUrl:null,linkWindow:"_self",live:false,metaData:{},originalUrl:null,position:0,playlist:[],provider:"http",scaling:"scale",seekableOnBegin:false,start:0,url:null,urlResolvers:[]};var q=H;var k=H;var n=/iPad|iPhone|iPod/i.test(navigator.userAgent);var b=null;function i(N,M,K){if(M){for(key in M){if(key){if(M[key]&&typeof M[key]=="function"&&!K){continue}if(M[key]&&typeof M[key]=="object"&&M[key].length==undefined){var L={};i(L,M[key]);N[key]=L}else{N[key]=M[key]}}}}}var u={simulateiDevice:false,controlsSizeRatio:1.5,controls:true,debug:false};i(u,r);function d(){if(u.debug){if(n){var K=[].splice.call(arguments,0).join(", ");console.log.apply(console,[K])}else{console.log.apply(console,arguments)}}}function h(K){switch(K){case -1:return"UNLOADED";case 0:return"LOADED";case 1:return"UNSTARTED";case 2:return"BUFFERING";case 3:return"PLAYING";case 4:return"PAUSED";case 5:return"ENDED"}return"UNKOWN"}function z(K){var L=$f.fireEvent(e.id(),"onBefore"+K,m);return L!==false}function D(K){K.stopPropagation();K.preventDefault();return false}function C(L,K){if(q==H&&!K){return}k=q;q=L;d(h(L))}function v(){b.fp_stop();I=false;y=false;o=false;C(t);C(t)}function x(){v();o=true;b.fp_seek(0)}function E(K){}function l(){function K(M){var L={};i(L,c);i(L,e.getCommonClip());i(L,M);if(L.ipadUrl){url=L.ipadUrl}else{if(L.url){url=L.url}}if(url&&url.indexOf("://")==-1&&L.baseUrl){url=L.baseUrl+"/"+url}L.originalUrl=L.url;L.completeUrl=url;L.extension=L.completeUrl.substr(L.completeUrl.lastIndexOf("."));L.type="video";delete L.index;d("fixed clip",L);return L}b.fp_play=function(O,M,Q){var L=null;var P=true;var N=true;d("Calling play() "+O,O);if(M){d("ERROR: inStream clips not yet supported");return}if(O!==undefined){if(typeof O=="number"){if(m>=G.length){return}m=O;O=G[m]}else{if(typeof O=="string"){O={url:O}}b.fp_setPlaylist(O.length!==undefined?O:[O])}O=G[m];L=O.completeUrl;if(O.autoBuffering!==undefined&&O.autoBuffering===false){P=false}if(O.autoPlay===undefined||O.autoPlay===true||Q===true){P=true;N=true}else{N=false}}else{d("clip was not given, simply calling video.play, if not already buffering");if(q!=F){b.play()}return}d("about to play "+L,P,N);v();if(L){d("Changing SRC attribute"+L);b.setAttribute("src",L)}if(P){if(!z("Begin")){return false}$f.fireEvent(e.id(),"onBegin",m);d("calling video.load()");b.load()}if(N){d("calling video.play()");b.play()}};b.fp_pause=function(){d("pause called");if(!z("Pause")){return false}b.pause()};b.fp_resume=function(){d("resume called");if(!z("Resume")){return false}b.play()};b.fp_stop=function(){d("stop called");if(!z("Stop")){return false}y=true;b.pause();try{b.currentTime=0}catch(L){}};b.fp_seek=function(L){d("seek called "+L);if(!z("Seek")){return false}var P=0;var L=L+"";if(L.charAt(L.length-1)=="%"){var M=parseInt(L.substr(0,L.length-1))/100;var O=b.duration;P=O*M}else{P=L}try{b.currentTime=P}catch(N){d("Wrong seek time")}};b.fp_getTime=function(){return b.currentTime};b.fp_mute=function(){d("mute called");if(!z("Mute")){return false}J=b.volume;b.volume=0};b.fp_unmute=function(){if(!z("Unmute")){return false}b.volume=J};b.fp_getVolume=function(){return b.volume*100};b.fp_setVolume=function(L){if(!z("Volume")){return false}b.volume=L/100};b.fp_toggle=function(){d("toggle called");if(e.getState()==f){x();return}if(b.paused){b.fp_play()}else{b.fp_pause()}};b.fp_isPaused=function(){return b.paused};b.fp_isPlaying=function(){return !b.paused};b.fp_getPlugin=function(M){if(M=="canvas"||M=="controls"){var L=e.getConfig();return L.plugins&&L.plugins[M]?L.plugins[M]:null}d("ERROR: no support for "+M+" plugin on iDevices");return null};b.fp_close=function(){C(H);b.parentNode.removeChild(b);b=null};b.fp_getStatus=function(){var M=0;var N=0;try{M=b.buffered.start();N=b.buffered.end()}catch(L){}return{bufferStart:M,bufferEnd:N,state:q,time:b.fp_getTime(),muted:b.muted,volume:b.fp_getVolume()}};b.fp_getState=function(){return q};b.fp_startBuffering=function(){if(q==t){b.load()}};b.fp_setPlaylist=function(M){d("Setting playlist");m=0;for(var L=0;L<M.length;L++){M[L]=K(M[L])}G=M;$f.fireEvent(e.id(),"onPlaylistReplace",M)};b.fp_addClip=function(M,L){M=K(M);G.splice(L,0,M);$f.fireEvent(e.id(),"onClipAdd",M,L)};b.fp_updateClip=function(M,L){i(G[L],M);return G[L]};b.fp_getVersion=function(){return"3.2.3"};b.fp_isFullscreen=function(){return false};b.fp_toggleFullscreen=function(){if(b.fp_isFullscreen()){b.webkitExitFullscreen()}else{b.webkitEnterFullscreen()}};$f.each(("toggleFullscreen,stopBuffering,reset,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled,addCuepoints,css,animate,showPlugin,hidePlugin,togglePlugin,fadeTo,invoke,loadPlugin").split(","),function(){var L=this;b["fp_"+L]=function(){d("ERROR: unsupported API on iDevices "+L);return false}})}function A(){var V=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"];var N=function(X){d("Got event "+X.type,X)};for(var P=0;P<V.length;P++){b.addEventListener(V[P],N)}var K=function(X){d("got onBufferEmpty event "+X.type);C(F);$f.fireEvent(e.id(),"onBufferEmpty",m)};b.addEventListener("emptied",K,false);b.addEventListener("waiting",K,false);var M=function(X){if(k==t||k==F){}else{d("Restoring old state "+h(k));C(k)}$f.fireEvent(e.id(),"onBufferFull",m)};b.addEventListener("canplay",M,false);b.addEventListener("canplaythrough",M,false);var L=function(X){b.fp_updateClip({duration:b.duration,metaData:{duration:b.duration}},m);G[m].duration=b.duration;$f.fireEvent(e.id(),"onMetaData",m,G[m])};b.addEventListener("loadedmetadata",L,false);b.addEventListener("durationchange",L,false);var U=function(X){if(q==B){if(!z("Resume")){d("Resume disallowed, pausing");b.fp_pause();return D(X)}$f.fireEvent(e.id(),"onResume",m)}C(w);if(!I){I=true;$f.fireEvent(e.id(),"onStart",m)}};b.addEventListener("playing",U,false);var R=function(X){if(!z("Finish")){if(G.length==1){d("Active playlist only has one clip, onBeforeFinish returned false. Replaying");x()}else{if(m!=(G.length-1)){d("Not the last clip in the playlist, but onBeforeFinish returned false. Returning to the beginning of current clip");b.fp_seek(0)}else{d("Last clip in playlist, but onBeforeFinish returned false, start again from the beginning");b.fp_play(0)}}return D(X)}C(f);$f.fireEvent(e.id(),"onFinish",m);if(G.length>1&&m<(G.length-1)){d("Not last clip in the playlist, moving to next one");b.fp_play(++m,false,true)}};b.addEventListener("ended",R,false);var Q=function(X){C(s,true);$f.fireEvent(e.id(),"onError",m,201);if(u.onFail&&u.onFail instanceof Function){u.onFail.apply(e,[])}};b.addEventListener("error",Q,false);var T=function(X){d("got pause event from player"+e.id());if(y){return}if(q==F&&k==t){d("forcing play");setTimeout(function(){b.play()},0);return}if(!z("Pause")){b.fp_resume();return D(X)}C(B);$f.fireEvent(e.id(),"onPause",m)};b.addEventListener("pause",T,false);var W=function(X){$f.fireEvent(e.id(),"onBeforeSeek",m)};b.addEventListener("seeking",W,false);var O=function(X){if(y){y=false;$f.fireEvent(e.id(),"onStop",m)}else{$f.fireEvent(e.id(),"onSeek",m)}d("seek done, currentState",h(q));if(o){o=false;b.fp_play()}else{if(q!=w){b.fp_pause()}}};b.addEventListener("seeked",O,false);var S=function(X){$f.fireEvent(e.id(),"onVolume",b.fp_getVolume())};b.addEventListener("volumechange",S,false)}function j(){b.fp_play(0)}function p(){}if(n||u.simulateiDevice){if(!window.flashembed.__replaced){var g=window.flashembed;window.flashembed=function(M,R,N){if(typeof M=="string"){M=document.getElementById(M.replace("#",""))}if(!M){return}var Q=window.getComputedStyle(M,null);var P=parseInt(Q.width);var K=parseInt(Q.height);while(M.firstChild){M.removeChild(M.firstChild)}var L=document.createElement("div");var O=document.createElement("video");L.appendChild(O);M.appendChild(L);L.style.height=K+"px";L.style.width=P+"px";L.style.display="block";L.style.position="relative";L.style.background="-webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.5)), to(rgba(0, 0, 0, 0.7)))";L.style.cursor="default";L.style.webkitUserDrag="none";O.style.height="100%";O.style.width="100%";O.style.display="block";O.id=R.id;O.name=R.id;O.style.cursor="pointer";O.style.webkitUserDrag="none";O.type="video/mp4";O.playerConfig=N.config;$f.fireEvent(N.config.playerId,"onLoad","player")};flashembed.getVersion=g.getVersion;flashembed.asString=g.asString;flashembed.isSupported=function(){return true};flashembed.__replaced=true}var a=e._fireEvent;e._fireEvent=function(K){if(K[0]=="onLoad"&&K[1]=="player"){b=e.getParent().querySelector("video");if(u.controls){b.controls="controls"}l();A();C(s,true);b.fp_setPlaylist(b.playerConfig.playlist);j();a.apply(e,[K])}var L=q!=H;if(q==H&&typeof K=="string"){L=true}if(L){return a.apply(e,[K])}};e._swfHeight=function(){return parseInt(b.style.height)};e.hasiPadSupport=function(){return true}}return e});

/**
 * jQuery Plugin to obtain touch gestures from iPhone, iPod Touch and iPad, should also work with Android mobile phones (not tested yet!)
 * Common usage: wipe images (left and right to show the previous or next image)
 * 
 * @author Andreas Waltl, netCU Internetagentur (http://www.netcu.de)
 * @version 1.1.1 (9th December 2010) - fix bug (older IE's had problems)
 * @version 1.1 (1st September 2010) - support wipe up and wipe down
 * @version 1.0 (15th July 2010)
 */
(function($) { 
   $.fn.touchwipe = function(settings) {
     var config = {
    		min_move_x: 20,
    		min_move_y: 20,
 			wipeLeft: function() { },
 			wipeRight: function() { },
 			wipeUp: function() { },
 			wipeDown: function() { },
			preventDefaultEvents: true
	 };
     
     if (settings) $.extend(config, settings);
 
     this.each(function() {
    	 var startX;
    	 var startY;
		 var isMoving = false;

    	 function cancelTouch() {
    		 this.removeEventListener('touchmove', onTouchMove);
    		 startX = null;
    		 isMoving = false;
    	 }	
    	 
    	 function onTouchMove(e) {
    		 if(config.preventDefaultEvents) {
    			 e.preventDefault();
    		 }
    		 if(isMoving) {
	    		 var x = e.touches[0].pageX;
	    		 var y = e.touches[0].pageY;
	    		 var dx = startX - x;
	    		 var dy = startY - y;
	    		 if(Math.abs(dx) >= config.min_move_x) {
	    			cancelTouch();
	    			if(dx > 0) {
	    				config.wipeLeft();
	    			}
	    			else {
	    				config.wipeRight();
	    			}
	    		 }
	    		 else if(Math.abs(dy) >= config.min_move_y) {
		    			cancelTouch();
		    			if(dy > 0) {
		    				config.wipeDown();
		    			}
		    			else {
		    				config.wipeUp();
		    			}
		    		 }
    		 }
    	 }
    	 
    	 function onTouchStart(e)
    	 {
    		 if (e.touches.length == 1) {
    			 startX = e.touches[0].pageX;
    			 startY = e.touches[0].pageY;
    			 isMoving = true;
    			 this.addEventListener('touchmove', onTouchMove, false);
    		 }
    	 }    	 
    	 if ('ontouchstart' in document.documentElement) {
    		 this.addEventListener('touchstart', onTouchStart, false);
    	 }
     });
 
     return this;
   };
 
 })(jQuery);


// emir haveric frontend application
// copyright (c) 2011 Matthias Kunze
// commissioned by SiteSeeing (www.siteseeing.de)

var eh = {};

// animation duration in ms
eh.speed = 800;

// animation delay in ms
eh.delay = 300;

// set width of content layout
eh.centerize = function () {
    if ($('#fplayer').length == 1) {
        $('#content').css('width', $('#fplayer').width());
    }
	$('#inner-wrap').css({
		width: $('#content').width() + $('#nav').outerWidth(true)
	});
};

//footer animation
eh.footer = function () {
	// on gallery view: move to bottom
	if ($('#wrapper').hasClass('gallery')) {
		$('footer').delay(eh.delay).animate({
			bottom: '2px'
		}, eh.speed).addClass('animated');
	} else {
		// only move if it has animated class
		if ($('footer').hasClass('animated')) {
			$('footer').delay(eh.delay).animate({
				bottom: '123px'
			}, eh.speed).removeClass('animated');
		}
	}
};

eh.gallery = function () {
	if ($('#fplayer').size()) {
		$('#wrapper').addClass('isvideo');
	} else {
		$('#wrapper').removeClass('isvideo');
	}
	
	$('#thumb-menu li').unbind('setCurrent').bind('setCurrent', function () {
		var animate = $(this).hasClass('current');
		
		$('#thumb-menu .current').removeClass('current').find('.schraffur').remove();
		$(this).addClass('current').append('<div class="schraffur">').find('.schraffur').css({
			width: $(this).find('img')[0].width
		});
		galleryScrollTo($(this).data('picture-id'), ! animate);
		
	}).unbind('click').bind('click', function () {
		$(this).trigger('setCurrent');
	}).eq(0).trigger('setCurrent');
	
	$(document).unbind('keyup keydown').bind('keyup keydown', function (e) {
		var $curr = $('#thumb-menu .current'),
			$target = $(e.target);
		
		if ( ! $target.is(':input')) {
			switch (e.which) {
				case 38:
					if ($curr.prev().size() && e.type == 'keyup') {
						$curr.prev().trigger('setCurrent');
					}
					e.preventDefault();
					break;
				case 40:
				case 32:
					if ($curr.next().size() && e.type == 'keyup') {
						$curr.next().trigger('setCurrent');
					}
					e.preventDefault();
					break;
			}
			
		}
	});
	
	$('.jspContainer').unbind('mousewheel.gallery').bind('mousewheel.gallery', function (e) {
		var $curr = $('#thumb-menu .current'),
			$dest = $curr.next(),
			delta = e.wheelDelta || -e.detail;

		if (delta > 0) {
			$dest = $curr.prev();
		}

		if ($dest.size()) {
			$dest.trigger('setCurrent');
		}
		
		e.preventDefault();
	});
};

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

//logo animation 
eh.logo = function () {
	if ( ! $.browser.ipad && ($('#wrapper').hasClass('contact') || $('#wrapper').hasClass('bio') || $('#wrapper').hasClass('news'))) {
		return;
	}
	
	if ($.browser.ipad && $('#wrapper').hasClass('category')) {
	    $('#logo').hide();
	    $('#logo-arrow').show();
		showLogo();
		return;
	}
	
	// on gallery view: logo fadeout, arrow fadein
	if ($('#wrapper').hasClass('gallery') || $('#wrapper').hasClass('contact') || $('#wrapper').hasClass('bio') || $('#wrapper').hasClass('news')) {
		showArrow();
	// on other views vice-versa
	} else {
		showLogo();
	}
};

function showArrow() {
   $('header span').delay(eh.delay).fadeOut(eh.speed, function () {
	  var newLeft = $.browser.ipad ? '-58px' : '-136px';
	  $(this).parents('header').animate({
		 left: newLeft
	  }, eh.speed, function () {
		 $(this).find('#logo-arrow').fadeIn(eh.speed);
	  });
   });
   $.cookie('logo', 'arrow');
}

function showLogo() {
   $('#logo-arrow').delay(eh.delay).fadeOut(eh.speed, function () {
	   $('header').animate({
		   left: '0px'
	   }, eh.speed, function () {
		   $(this).find('#logo').fadeIn(eh.speed);
	   });
   });
   $.cookie('logo', 'logo');
}

// maximise gallery image
eh.maximise = function () {
	var height = $(window).height() - (105 * 2);
	if ($.browser.ipad) {
		height = $(window).height() - (85 + 40);
	}
	
	var maxWidth = 0;
	
	$('#gallery-pictures img, #gallery-teaser img').each(function () {
		if ( ! $(this).parents('#fplayer').size()) {
			var img = $(this)[0],
				r = img.width / img.height;
			if (img.height > height) {
				$(this).attr({
					height: height,
					width: height * r
				});
			}
			$('#gallery-teaser').css({
				height: $(this).height(),
				width: $(this).width()
			});
			
			if (maxWidth < $(this)[0].width) {
			   maxWidth = $(this)[0].width;
			}
			
			if ($(this).parent().find('.pdf-selection')) {
				//$(this).parent().find('.pdf-selection span').css('width', $(this)[0].width);
			}
		}
	});
	$('#gallery-pictures li').css('width', maxWidth);
	
	var navHeight = $('#nav').height();
	if (navHeight > height) {
		$('#nav img').each(function () {
			var img = $(this)[0];
			if ( ! $(this).data('np')) {
				$(this).data('np', img.height / navHeight);
			}
			var r = img.width / img.height,
				newHeight = height * $(this).data('np');
			$(this).attr({
				height: newHeight,
				width: newHeight * r
			});
			
			var $schraffur = $(this).parents('li').find('.schraffur');
			if ($schraffur.size()) {
				$schraffur.css({
					width: $(this)[0].width
				});
			}
		});
	}
};

// menu fade in cycle
eh.menu = function (isPjax) {
	var items = $('.gallery-menu li, #thumb-menu li'),
		animate = (isPjax === false);

	if ( ! animate && ! items.parent().is('#thumb-menu')) {
		items.css('left', 0);
	} else {
		for (k = 0; k < items.length; k++ ) {
	        $(items[k]).css('opacity', 0).delay(k * 100).animate({
				opacity: 1,
				left: '0px'
	        }, eh.speed);
	    }
	}
};

eh.news = function () {
	$('.news-gallery').newsGallery();
};

var introResizeTimeout;
eh.intro = function () {
	if ( ! $('#intro-schraffur').size()) {
		var $schraffur = $('<div id="intro-schraffur" class="schraffur">').appendTo($('#intro-wrap'));
		$schraffur.css({
			width: $('#intro').width(),
			height: $('#intro').height(),
			cursor: 'pointer'
		}).one('click', function () {
			location.href = global.root + '/look/';
		});
		$('#intro-wrap').css({
			width: $('#intro').width(),
			height: $('#intro').height()
		});
		$('#intro-wrap ul').css('width', $('#intro').width());
	}
	clearTimeout(introResizeTimeout);
	introResizeTimeout = setTimeout(function () {
		var newWidth = $(window).width(),
			newHeight = $(window).height()/* - 32*/;
		
		$('#intro').each(function () {
			var maxWidth = newWidth,
				maxHeight = newHeight;
			
			if ( ! $(this).data('o')) {
				$(this).data('o', { w: $(this).width(), h: $(this).height() });
			}
			
			var ratioW = $(this).height() / $(this).width(),
				ratioH = $(this).width() / $(this).height(),
				newPlayerWidth = maxWidth,
				newPlayerHeight = maxWidth * ratioW;
			
			if (newPlayerHeight < maxHeight) {
				newPlayerHeight = maxHeight;
				newPlayerWidth = newPlayerHeight * ratioH;
			}
			
			/*if (newPlayerWidth > $(this).data('o').w) {
				newPlayerWidth = $(this).data('o').w;
				newPlayerHeight = $(this).data('o').h;
			}*/
			
			/*if (maxHeight < newPlayerHeight) {
				newPlayerHeight = maxHeight;
				newPlayerWidth = newPlayerHeight * ratioH;
			}*/
			
			$(this).css({
				width: newPlayerWidth,
				height: newPlayerHeight,
				marginLeft: -(newPlayerWidth / 2),
				marginTop: -(newPlayerHeight / 2)
			});
			
			$('#intro-schraffur, #intro-wrap').css({
				width: newPlayerWidth,
				height: newPlayerHeight
			});
			
			$('#intro-wrap ul').css('width', newPlayerWidth);
			
		});
	}, 50);
	
};

eh.resizeSelection = function () {
	var width = $(window).width() - ($('#nav').outerWidth() + 288 + 45),
		maxWidth = 673,
		$div = $('.selection #content'),
		news = false;
	
	if ($('.news #content').size()) {
		if ($.browser.ipad) {
			width = parseInt($('#content').css('width'));
		}
		$div = $('.news #content');
		news = true;
	}
	
	if (width > maxWidth) {
		width = maxWidth;
	}
	
	$div.css('width', width);
	
	if (news) {
		$('.news-gallery img, .fplayer').each(function () {
			if ( ! $(this).data('r')) {
				$(this).data('r', $(this).height() / $(this).width());
			}
			
			var height = width * $(this).data('r');
			
			if ($(this).is('img')) {
				this.width = width;
				this.height = height;
			} else {
				$(this).css({
					width: width,
					height: height
				});
			}
			
			if ($(this).parents('li').is('.current') && ! $(this).hasClass('poster')) {
				$(this).parents('.news-gallery').css('height', height);
			}
		});
	}
};

var playerResizeTimeout;
eh.resize = function () {
	var width = $('#inner-wrap').width(),
		newWidth = $(window).width() - (170 * 2),
		newHeight = $(window).height() - (105 * 2);
	
	if ($.browser.ipad) {
		newWidth += 110;
		newHeight = $(window).height() - (85 + 40);
	}
	
	$('#fplayer').each(function () {
		var $this = $(this);
		
			var maxWidth = $(window).width() - 150,
				maxHeight = $(window).height() - (105 + 195);
			
			if ($.browser.ipad) {
				maxWidth = $(window).width();
				maxHeight = $(window).height();
			}
			
			if ( ! $this.data('o')) {
				$this.data('o', { w: $this.width(), h: $this.height() });
			}
			
			var ratioW = $this.height() / $this.width(),
				ratioH = $this.width() / $this.height(),
				newPlayerWidth = maxWidth,
				newPlayerHeight = maxWidth * ratioW;
			
			if (newPlayerWidth > $this.data('o').w) {
				newPlayerWidth = $this.data('o').w;
				newPlayerHeight = $this.data('o').h;
			}
			
			if (maxHeight < newPlayerHeight) {
				newPlayerHeight = maxHeight;
				newPlayerWidth = newPlayerHeight * ratioH;
			}
			
			$this.css({
				width: newPlayerWidth,
				height: newPlayerHeight
			});
			
			var $img = $this.find('img');
			
			if ($img.size()) {
			
				if ( ! $img.data('r')) {
					$img.data('r', $img[0].width / $img[0].height);
				}
				
				$img.attr({
					height: newPlayerHeight,
					width: newPlayerHeight * $img.data('r')
				});
				
				$img.css('marginLeft', -($img[0].width / 2));
				
			}

	});
	
	var isLook = false;
	if ($('.category #content').size()) {
		newWidth = $(window).width() - (290 + $('#nav').outerWidth(true));
		isLook = true;
		if ($.browser.ipad) {
			newWidth += 160;
		}
	}
	
	$('.r').each(function () {
		var $img = $(this);
		
		if ( ! $img.data('r')) {
			$img.data('r', $img.attr('width') / $img.attr('height'));
			$img.data('o', {
				width: $img.attr('width'),
				height: $img.attr('height')
			});
			$img.data('p', $img.attr('width') / ($('#content').width() + $('#nav').outerWidth(true)));
		}
		
		var newImgWidth = (isLook ? newWidth : (newWidth * $img.data('p'))),
			newImgHeight = newImgWidth * ($img.data('o').height / $img.data('o').width);
		
		if ($img.data('o').width < newImgWidth) {
			newImgWidth = $img.data('o').width;
			newImgHeight = newImgWidth * ($img.data('o').height / $img.data('o').width);
		}
		
		$img.attr({
			width: newImgWidth,
			height: newImgHeight
		});
		
		var $schraffur = $img.parents('li').find('.schraffur');
		if ($schraffur.size()) {
			$schraffur.css({
				width: $img[0].width
			});
		}
		
	});
	
	eh.maximise();

	eh.resizeSelection();
	
	$('#thumb-menu .current').trigger('setCurrent');
	eh.centerize();
	
};

//adjust width and height of scrollable content
eh.scrollbar = function () {
	$('#wrapper').css({
		height: $(window).height() - parseInt($('#wrapper').css('marginTop'))
	});
	
	$('#gallery-pictures li').css('height', $('#wrapper').height()).last().css('margin-bottom', 0);
	
	if ( ! $.browser.ipad) {
		if ( ! $('#wrapper').data('jsp')) {
			$('#wrapper').doScrollbar();
		} else {
			$('#wrapper').data('jsp').reinitialise();
		}
	}
	
	$('#wrapper').unbind('jsp-scroll-y').bind('jsp-scroll-y', function (event, scrollPositionY, isAtTop, isAtBottom) {
		if ($('#nav').find('#thumb-menu').size()) {
			$('#nav').css('marginTop', scrollPositionY);
		}
	});
};

eh.teaserInterval = 300;
eh.teaserIds = [];

// teaser switch on hover
eh.teaser = function () {
	for (var i in eh.teaserInterval) {
		clearInterval(eh.teaserInterval[i]);
	}
	
	if ($('#gallery-teaser').size()) {
		$('#gallery-teaser li:first').addClass('current');
		
		if ( ! $.browser.ipad) {
			$('.gallery-menu li:not(.pdf-selection-link)').bind('mouseenter', function () {
				$('.gallery-menu .current').removeClass('current');
				$(this).addClass('current');
				$('#gallery-teaser')
					.find('.current').removeClass('current').end()
					.find('#gallery-' + $(this).data('gallery-id')).addClass('current');
			});
		}
		
		$('.teaser-sequenz').each(function () {
			var $div = $(this),
				$imgs = $('img', $div);
			
			if ($imgs.size() > 1) {
				eh.teaserIds.push(setInterval(function () {
					var $curr = $imgs.filter('.active'),
						$next = $curr.next();
					if ( ! $next.size()) {
						$next = $imgs.eq(0);
					}
					$curr.removeClass('active');
					$next.addClass('active');
				}, eh.teaserInterval));
			} else {
				$imgs.addClass('active');
			}
		});
	}
};

eh.video = function () {
	if ($('#fplayer img').size()) {
		var w = $('#fplayer img')[0].width;
		$('#fplayer img').css({
			marginLeft: -(w / 2)
		});
	}
};

eh.selection = function () {
	if ($('#selection-box').size()) {
		$('#selection-box').appendTo($('body')).find(':input').attr('readonly', 'true').click(function () {
			this.select();
		});
		
		$('.open-link').click(function (e) {
			if ($('#selection-box').toggleClass('show').hasClass('show')) {
				$(':input', $('#selection-box')).select();
			}
			e.preventDefault();
		});
		
		$('#selection-box .close').click(function () {
			$('#selection-box').removeClass('show');
		});
	}
};

eh.addpdf = function () {
	$('.pdf-selection span').hover(function () {
		if ($(this).hasClass('added') && ! $(this).parents('#selection-overview').size()) {
			$(this).text('remove image');
		}
	}, function () {
		if ($(this).hasClass('added') && ! $(this).parents('#selection-overview').size()) {
			$(this).text('safe');
		}
	}).click(function () {
        var id = $(this).parent().parent().attr('id').replace('pic-', ''),
        	isOverview = $(this).parents('#selection-overview').size() > 0,        
	        isAdded = $(this).hasClass('added'),
	        $link = $(this);
        
        if ( ! isOverview) {
        	if (isAdded) {
                $link.removeClass('added').text('save image to pdf');
            } else {
                $link.addClass('added').text('safe').fadeOut(400).fadeIn(200, function(){
                    $(this).text('safe');
                });
            }
        } else {
        	$(this).parents('li').fadeOut('fast', function () {
        		$(this).remove();
        	});
        }
        
        $.post(global.root + '/selection/add/' + id, function (rsp) {
            if (rsp == 0) {
                $('#pdf').hide();
                $('footer').removeClass('selection');
                $('.pdf-selection-link').hide();
            } else {
            	$('footer').addClass('selection');
                $('#pdf').addClass('current').show();
                /*
                setTimeout(function () {
                	$('#pdf').removeClass('current');
                }, 1500);
                */
            }
            $('#pdf .icon-text p').text(rsp + ' image' + (rsp != 1 ? 's' : '') + ' saved');
        });
    });
};

function touchScroll (id) {
	var el=document.getElementById(id);
	var scrollStartPos=0;
	
	if (el) {
	  el.addEventListener("touchstart", function(event) {
			scrollStartPos=this.scrollTop+event.touches[0].pageY;
			//event.preventDefault();
		}, false);
	
		el.addEventListener("touchmove", function(event) {
			this.scrollTop=scrollStartPos-event.touches[0].pageY;
			event.preventDefault();
		}, false);
	}

	
}

eh.ipad = function () {
	if ($('#wrapper.gallery').length) {
		$('#content').css('height', $(window).height() - 85);
		$('#gallery-pictures li').css('height', $('#wrapper').height()).last().css('margin-bottom', 0);
		$('#content').touchwipe({
			wipeUp: function () {
				$('#thumb-menu .current').prev().trigger('setCurrent');
			},
			wipeDown: function () {
				$('#thumb-menu .current').next().trigger('setCurrent');
			},
			min_move_y: 100
		});
	} else {
		touchScroll('wrapper');
	}
	
	window.onorientationchange = function() {
		eh.orientation();
	};
};

eh.orientation = function () {
	var orientation = window.orientation;
	switch (orientation) {
	    case 0:
	    	$('#content').removeClass('landscape');
	    	break;
	    default:
	    	$('#content').addClass('landscape');
	    	break;
	}
	eh.resize();
};

//all in one handler
eh.onready = function () {
	if ($.browser.ipad) {
		eh.orientation();
	}
	eh.news();
	eh.resize();
	if ( ! $.browser.ipad) {
		eh.scrollbar();
	}
	eh.teaser();
	eh.logo();
	eh.footer();
	eh.gallery();
	eh.video();
	eh.addpdf();
	eh.selection();
	if ($.browser.ipad) {
		eh.ipad();
	}
};

//success handler for pjax calls
eh.pjax = function (data) {
	$('#wrapper')
		.removeClass('category')
		.removeClass('gallery')
		.removeClass('selection')
		.removeClass('news')
		.removeClass('contact')
		.removeClass('bio')
		
		.addClass(data.template);

	eh.menu(true);
	eh.onready();
};

// dom ready
$(function () {
	if ( ! $('.jspPane').size()) {
		$('#inner-wrap').wrap('<div class="jspPane" style="position:static;">');
	}
	// pjax support
	$('a:not([href^=http])').pjax('.jspPane', {
		dataType: 'json',
		success: eh.pjax,
		timeout: 30000
	});
	eh.menu(false);
	eh.onready();
});

$(window).resize(function () {
	eh.resize();
	eh.scrollbar();
});



(function ($) {
	$.extend(jQuery.browser, {
		ipad : navigator.userAgent.toLowerCase().indexOf('ipad') > -1
	});
	
	$.fn.doScrollbar = function () {
		if ($('#fplayer, #intro').size()) {
			return this;
		}
		return $(this).jScrollPane({
			verticalDragMinHeight: 35,
			verticalDragMaxHeight: 35,
			hideFocus: true,
			animateScroll: true
		}).css('overflow', 'visible');
	};
	
	$.fn.newsGallery = function () {
		
		return this.each(function () {

			// seperator for nav numbers
			var sep = '|',
				next = '&gt;',
				prev = '&lt;',
				// set gallery to relative
				$gal = $(this).css('position', 'relative'),
				$lis = $('li', $(this));
			
			$('li', $(this)).css('position', 'absolute').not(':first-child').css({
					/*display: 'none',*/
					visibility: 'hidden'/*,
					cursor: 'pointer'*/
				})/*.click(showNextImage)*/;
			
			// show next image
			function showNextImage() {
				var $next = $('.current', $gal).next();
				if ( ! $next.length) {
					$next = $lis.first();
				}
				setNewCurrent($next);
			}
			
			// show previous image
			function showPrevImage() {
				var $prev = $('.current', $gal).prev();
				if (!$prev.length) {
					$prev = $lis.last();
				}
				setNewCurrent($prev);
			}
			
			// show specified image on nav click
			function showThisImage() {
				var num = parseInt($(this).text()),
					$li = $lis.eq(num - 1);
				if ($li.length) {
					setNewCurrent($li);
				}
			}
			
			// set given $element to current image to show
			function setNewCurrent($element) {
				var $current = $('.current', $gal);
				// reset the height of the gallery
				$gal.css('height', $element.height());
				$current.hide()/*.fadeOut('fast')*/.removeClass('current');
				$element.css({
					display: 'none',
					visibility: 'visible'
				}).show()/*.fadeIn('fast', function () {
					//$('#wrapper').doScrollbar();
				})*/.addClass('current');
				updateGalleryNavigation();
			}
			
			// rebuild gallery navigation on every image switch
			function updateGalleryNavigation() {
				var max = $lis.length,
					curIndex = $('.current', $gal).index(),
					$navi = $('.galnav', $gal.parent());
				
				if (max == 1) {
					return;
				}
				
				if ( ! $navi.length) {
					$navi = $('<div\/>').addClass('galnav').insertAfter($gal);
				}
				// remove all children
				$navi.children().remove();
				// build the nav numbers
				for (i = 0; i < max; i++) {
					var $span = $('<span\/>').text(i + 1).addClass('num').css('cursor', 'pointer').click(showThisImage);
					// tag current image in nav
					if (curIndex == i) {
						$span.addClass('curimg');
					}
					$span.appendTo($navi);
					// add the seperator
					if (i < (max - 1)) {
						$('<span\/>').addClass('sep').html(sep).appendTo($navi);
					}
				}
				// build prev and next span
				$('<span\/>').addClass('prev').css('cursor', 'pointer').html(prev).click(showPrevImage).prependTo($navi);
				$('<span\/>').addClass('next').css('cursor', 'pointer').html(next).click(showNextImage).appendTo($navi);
			}
			
			// show galleries when everything's loaded
			//$(window).unbind('load.news').bind('load.news', function () {
				// switch to first image
				showNextImage();
			//});
			
		});
		
	};
	
})(jQuery);

function galleryScrollTo(id, animate) {
	var $element = $('#gallery-pictures #pic-' + id),
		index = $element.index();

	if (animate) {
		$('#gallery-pictures .pdf-selection').fadeOut('fast');
		$element.find('.pdf-selection').fadeIn('fast');
	}
	
	if ($element.size()) {
		if ( ! $.browser.ipad) {
			var api = $('#wrapper').data('jsp');
			api.scrollToY($element[0].offsetTop, animate);
			
		} else {
			var height = $element.parent().find('li:first-child').outerHeight(true);
			$('#gallery-pictures').css('margin-top', -(height) * index);
		}
	}
}
$(function () {
	var footerTimer;
	$('footer li').bind('mouseenter', function (e) {
		var $text = $(this).find('.icon-text'),
			$current = $(this).parent().find('.current'),
			height = 0;
		
		if ($text.is($current)) {
			clearTimeout(footerTimer);
			return;
		}
		
		$text.show().children().each(function () {
			height += parseInt($(this).outerHeight(true));
		});
		
		$text.addClass('current').stop(true, true).animate({
			height: height
		}, 'fast');
		$(this).addClass('current');
	}).bind('mouseleave', function (e) {
		var $li = $(this),
			$text = $('.icon-text', $li);
		footerTimer = setTimeout(function () {
			$text.removeClass('current').css({
				height: 0,
				display: 'none'
			});
			if ( ! $li.hasClass('stay')) {
				$li.removeClass('current');
			}
		}, 50);
	});
	
	$('footer .icon-text').mouseenter(function () {
		clearTimeout(footerTimer);
	});
	
	
	$('#newsletter form').submit(function (e) {
		e.preventDefault();
		var $form = $(this),
			url = $form.attr('action'),
			$input = $('input', $form);
		// send input data
		$.post(url, $form.serialize(), function (rsp) {
			if (rsp == 1) {
				$input.val('Adresse wurde gespeichert!');
				setTimeout(function () {
					$input.val('');
				}, 2000);
			}
		});
	});
	
	$('#facebook').click(function () {
		var url = location.href,
			title = document.title;
		window.open('http://www.facebook.com/sharer.php?u=' + url + '&t=' + title, "Share on Facebook", "width=400,height=300");
	});
	
	$('#twitter').click(function () {
		var url = location.href,
			title = document.title + ': ' + url;
		window.open('http://twitter.com/intent/tweet?status=' + title + '&url=' + url, "Tweet this", "width=400,height=300");
	});
	
});
