/*
 * jQuery UI Effects 1.8.9
 *
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Effects/
 */
jQuery.effects||function(f,j){function n(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10)];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],
16),parseInt(a[2],16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];if(/rgba\(0, 0, 0, 0\)/.exec(c))return o.transparent;return o[f.trim(c).toLowerCase()]}function s(c,a){var b;do{b=f.curCSS(c,a);if(b!=""&&b!="transparent"||f.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return n(b)}function p(){var c=document.defaultView?document.defaultView.getComputedStyle(this,null):this.currentStyle,
a={},b,d;if(c&&c.length&&c[0]&&c[c[0]])for(var e=c.length;e--;){b=c[e];if(typeof c[b]=="string"){d=b.replace(/\-(\w)/g,function(g,h){return h.toUpperCase()});a[d]=c[b]}}else for(b in c)if(typeof c[b]==="string")a[b]=c[b];return a}function q(c){var a,b;for(a in c){b=c[a];if(b==null||f.isFunction(b)||a in t||/scrollbar/.test(a)||!/color/i.test(a)&&isNaN(parseFloat(b)))delete c[a]}return c}function u(c,a){var b={_:0},d;for(d in a)if(c[d]!=a[d])b[d]=a[d];return b}function k(c,a,b,d){if(typeof c=="object"){d=
a;b=null;a=c;c=a.effect}if(f.isFunction(a)){d=a;b=null;a={}}if(typeof a=="number"||f.fx.speeds[a]){d=b;b=a;a={}}if(f.isFunction(b)){d=b;b=null}a=a||{};b=b||a.duration;b=f.fx.off?0:typeof b=="number"?b:b in f.fx.speeds?f.fx.speeds[b]:f.fx.speeds._default;d=d||a.complete;return[c,a,b,d]}function m(c){if(!c||typeof c==="number"||f.fx.speeds[c])return true;if(typeof c==="string"&&!f.effects[c])return true;return false}f.effects={};f.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor",
"borderTopColor","borderColor","color","outlineColor"],function(c,a){f.fx.step[a]=function(b){if(!b.colorInit){b.start=s(b.elem,a);b.end=n(b.end);b.colorInit=true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],10),255),0)+")"}});var o={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,
0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,
211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]},r=["add","remove","toggle"],t={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};f.effects.animateClass=function(c,a,b,
d){if(f.isFunction(b)){d=b;b=null}return this.queue("fx",function(){var e=f(this),g=e.attr("style")||" ",h=q(p.call(this)),l,v=e.attr("className");f.each(r,function(w,i){c[i]&&e[i+"Class"](c[i])});l=q(p.call(this));e.attr("className",v);e.animate(u(h,l),a,b,function(){f.each(r,function(w,i){c[i]&&e[i+"Class"](c[i])});if(typeof e.attr("style")=="object"){e.attr("style").cssText="";e.attr("style").cssText=g}else e.attr("style",g);d&&d.apply(this,arguments)});h=f.queue(this);l=h.splice(h.length-1,1)[0];
h.splice(1,0,l);f.dequeue(this)})};f.fn.extend({_addClass:f.fn.addClass,addClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{add:c},a,b,d]):this._addClass(c)},_removeClass:f.fn.removeClass,removeClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{remove:c},a,b,d]):this._removeClass(c)},_toggleClass:f.fn.toggleClass,toggleClass:function(c,a,b,d,e){return typeof a=="boolean"||a===j?b?f.effects.animateClass.apply(this,[a?{add:c}:{remove:c},b,d,e]):this._toggleClass(c,
a):f.effects.animateClass.apply(this,[{toggle:c},a,b,d])},switchClass:function(c,a,b,d,e){return f.effects.animateClass.apply(this,[{add:a,remove:c},b,d,e])}});f.extend(f.effects,{version:"1.8.9",save:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.data("ec.storage."+a[b],c[0].style[a[b]])},restore:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.css(a[b],c.data("ec.storage."+a[b]))},setMode:function(c,a){if(a=="toggle")a=c.is(":hidden")?"show":"hide";return a},getBaseline:function(c,
a){var b;switch(c[0]){case "top":b=0;break;case "middle":b=0.5;break;case "bottom":b=1;break;default:b=c[0]/a.height}switch(c[1]){case "left":c=0;break;case "center":c=0.5;break;case "right":c=1;break;default:c=c[1]/a.width}return{x:c,y:b}},createWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent();var a={width:c.outerWidth(true),height:c.outerHeight(true),"float":c.css("float")},b=f("<div></div>").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",
border:"none",margin:0,padding:0});c.wrap(b);b=c.parent();if(c.css("position")=="static"){b.css({position:"relative"});c.css({position:"relative"})}else{f.extend(a,{position:c.css("position"),zIndex:c.css("z-index")});f.each(["top","left","bottom","right"],function(d,e){a[e]=c.css(e);if(isNaN(parseInt(a[e],10)))a[e]="auto"});c.css({position:"relative",top:0,left:0,right:"auto",bottom:"auto"})}return b.css(a).show()},removeWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent().replaceWith(c);
return c},setTransition:function(c,a,b,d){d=d||{};f.each(a,function(e,g){unit=c.cssUnit(g);if(unit[0]>0)d[g]=unit[0]*b+unit[1]});return d}});f.fn.extend({effect:function(c){var a=k.apply(this,arguments),b={options:a[1],duration:a[2],callback:a[3]};a=b.options.mode;var d=f.effects[c];if(f.fx.off||!d)return a?this[a](b.duration,b.callback):this.each(function(){b.callback&&b.callback.call(this)});return d.call(this,b)},_show:f.fn.show,show:function(c){if(m(c))return this._show.apply(this,arguments);
else{var a=k.apply(this,arguments);a[1].mode="show";return this.effect.apply(this,a)}},_hide:f.fn.hide,hide:function(c){if(m(c))return this._hide.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="hide";return this.effect.apply(this,a)}},__toggle:f.fn.toggle,toggle:function(c){if(m(c)||typeof c==="boolean"||f.isFunction(c))return this.__toggle.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="toggle";return this.effect.apply(this,a)}},cssUnit:function(c){var a=this.css(c),
b=[];f.each(["em","px","%","pt"],function(d,e){if(a.indexOf(e)>0)b=[parseFloat(a),e]});return b}});f.easing.jswing=f.easing.swing;f.extend(f.easing,{def:"easeOutQuad",swing:function(c,a,b,d,e){return f.easing[f.easing.def](c,a,b,d,e)},easeInQuad:function(c,a,b,d,e){return d*(a/=e)*a+b},easeOutQuad:function(c,a,b,d,e){return-d*(a/=e)*(a-2)+b},easeInOutQuad:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a+b;return-d/2*(--a*(a-2)-1)+b},easeInCubic:function(c,a,b,d,e){return d*(a/=e)*a*a+b},easeOutCubic:function(c,
a,b,d,e){return d*((a=a/e-1)*a*a+1)+b},easeInOutCubic:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a+b;return d/2*((a-=2)*a*a+2)+b},easeInQuart:function(c,a,b,d,e){return d*(a/=e)*a*a*a+b},easeOutQuart:function(c,a,b,d,e){return-d*((a=a/e-1)*a*a*a-1)+b},easeInOutQuart:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a+b;return-d/2*((a-=2)*a*a*a-2)+b},easeInQuint:function(c,a,b,d,e){return d*(a/=e)*a*a*a*a+b},easeOutQuint:function(c,a,b,d,e){return d*((a=a/e-1)*a*a*a*a+1)+b},easeInOutQuint:function(c,
a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a*a+b;return d/2*((a-=2)*a*a*a*a+2)+b},easeInSine:function(c,a,b,d,e){return-d*Math.cos(a/e*(Math.PI/2))+d+b},easeOutSine:function(c,a,b,d,e){return d*Math.sin(a/e*(Math.PI/2))+b},easeInOutSine:function(c,a,b,d,e){return-d/2*(Math.cos(Math.PI*a/e)-1)+b},easeInExpo:function(c,a,b,d,e){return a==0?b:d*Math.pow(2,10*(a/e-1))+b},easeOutExpo:function(c,a,b,d,e){return a==e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(c,a,b,d,e){if(a==0)return b;if(a==
e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b},easeInCirc:function(c,a,b,d,e){return-d*(Math.sqrt(1-(a/=e)*a)-1)+b},easeOutCirc:function(c,a,b,d,e){return d*Math.sqrt(1-(a=a/e-1)*a)+b},easeInOutCirc:function(c,a,b,d,e){if((a/=e/2)<1)return-d/2*(Math.sqrt(1-a*a)-1)+b;return d/2*(Math.sqrt(1-(a-=2)*a)+1)+b},easeInElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=
g/(2*Math.PI)*Math.asin(d/h);return-(h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g))+b},easeOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return h*Math.pow(2,-10*a)*Math.sin((a*e-c)*2*Math.PI/g)+d+b},easeInOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e/2)==2)return b+d;g||(g=e*0.3*1.5);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/
h);if(a<1)return-0.5*h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)+b;return h*Math.pow(2,-10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)*0.5+d+b},easeInBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;return d*(a/=e)*a*((g+1)*a-g)+b},easeOutBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;return d*((a=a/e-1)*a*((g+1)*a+g)+1)+b},easeInOutBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;if((a/=e/2)<1)return d/2*a*a*(((g*=1.525)+1)*a-g)+b;return d/2*((a-=2)*a*(((g*=1.525)+1)*a+g)+2)+b},easeInBounce:function(c,
a,b,d,e){return d-f.easing.easeOutBounce(c,e-a,0,d,e)+b},easeOutBounce:function(c,a,b,d,e){return(a/=e)<1/2.75?d*7.5625*a*a+b:a<2/2.75?d*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?d*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:d*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},easeInOutBounce:function(c,a,b,d,e){if(a<e/2)return f.easing.easeInBounce(c,a*2,0,d,e)*0.5+b;return f.easing.easeOutBounce(c,a*2-e,0,d,e)*0.5+d*0.5+b}})}(jQuery);
;

/* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 *
 * Requires: 1.2.2+
 */
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);


/*
 * touchSwipe - jQuery Plugin
 * http://plugins.jquery.com/project/touchSwipe
 * http://labs.skinkers.com/touchSwipe/
 *
 * Copyright (c) 2010 Matt Bryson (www.skinkers.com)
 * Licensed under the GNU GPL license
 *
 * $version: 1.1.0
 *
 * Changelog
 * $Date: 2010-12-12 (Wed, 12 Dec 2010) $
 * $version: 1.0.0
 * $version: 1.0.1 - removed multibyte comments
 *
 * $Date: 2011-21-02 (Mon, 21 Feb 2011) $
 * $version: 1.1.0 	- added allowPageScroll property to allow swiping and scrolling of page
 *					- changed handler signatures so one handler can be used for multiple events
 *
 *
 * A jQuery plugin to capture left, right, up and down swipes on touch devices.
 * You can capture 2 finger or 1 finger swipes, set the threshold and define either a catch all handler, or individual direction handlers.
 * Options:
 * 		fingers 	int 		Default 1. 	The number of fingers to trigger the swipe, 1 or 2.
 * 		threshold 	int  		Default 75.	The number of pixels that the user must move their finger by before it is considered a swipe.
 * 		swipe 		Function 	A catch all handler that is triggered for all swipe directions. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeLeft	Function 	A handler that is triggered for "left" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeRight	Function 	A handler that is triggered for "right" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeUp		Function 	A handler that is triggered for "up" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 * 		swipeDown	Function 	A handler that is triggered for "down" swipes. Handler is passed 3 arguments, the original event object, the direction of the swipe : "left", "right", "up", "down" and the distance of the swipe.
 *		swipeStatus Function 	A handler triggered for every phase of the swipe. Handler is passed 4 arguments: event : The original event object, phase:The current swipe face, either "start�, "move�, "end� or "cancel�. direction : The swipe direction, either "up�, "down�, "left " or "right�.distance : The distance of the swipe.
 *		triggerOnTouchEnd Boolean Default true If true, the swipe events are triggered when the touch end event is received (user releases finger).  If false, it will be triggered on reaching the threshold, and then cancel the touch event automatically.
 *		allowPageScroll String Default "auto". How the browser handles page scrolls when the user is swiping on a touchSwipe object.
 *										"auto" : all undefined swipes will cause the page to scroll in that direction.
 *										"none" : the page will not scroll when user swipes.
 *										"horizontal" : will force page to scroll on horizontal swipes.
 *										"vertical" : will force page to scroll on vertical swipes.
 *
 * This jQuery plugin will only run on devices running Mobile Webkit based browsers (iOS 2.0+, android 2.2+)
 */

(function($){$.fn.swipe=function(options){if(!this)return false;var defaults={fingers:1,threshold:75,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,triggerOnTouchEnd:true,allowPageScroll:"auto"};var LEFT="left";var RIGHT="right";var UP="up";var DOWN="down";var NONE="none";var HORIZONTAL="horizontal";var VERTICAL="vertical";var AUTO="auto";var phase="start";var PHASE_START="start";var PHASE_MOVE="move";var PHASE_END="end";var PHASE_CANCEL="cancel";if(options.allowPageScroll==undefined&&(options.swipe!=undefined||options.swipeStatus!=undefined))options.allowPageScroll=NONE;var options=$.extend(defaults,options);if(options.debug)options.swipe=function(event,direction){console.log("swiped "+direction);};return this.each(function(){var triggerElementID=null;var fingerCount=0;var start={x:0,y:0};var end={x:0,y:0};var delta={x:0,y:0};function touchStart(event){phase=PHASE_START;fingerCount=event.touches.length;if(fingerCount==defaults.fingers){start.x=event.touches[0].pageX;start.y=event.touches[0].pageY;if(defaults.swipeStatus)triggerHandler(event,phase);}else
{touchCancel(event);}}function touchMove(event){if(phase==PHASE_END||phase==PHASE_CANCEL)return;phase=PHASE_MOVE;end.x=event.touches[0].pageX;end.y=event.touches[0].pageY;direction=caluculateDirection();validateDefaultEvent(event,direction);if(event.touches.length==defaults.fingers){var distance=null;if(defaults.swipeStatus){distance=caluculateDistance();triggerHandler(event,phase,direction,distance);}if(!defaults.triggerOnTouchEnd){if(!distance)distance=caluculateDistance();if(distance>=defaults.threshold){phase=PHASE_END;triggerHandler(event,phase,direction,distance);touchCancel(event);}}}else
{phase=PHASE_CANCEL;triggerHandler(event,phase);touchCancel(event);}}function touchEnd(event){event.preventDefault();if(defaults.triggerOnTouchEnd){phase=PHASE_END;if(fingerCount==defaults.fingers&&end.x!=0){var distance=caluculateDistance();direction=caluculateDirection();if(distance>=defaults.threshold){triggerHandler(event,phase,direction,distance);touchCancel(event);}else
{phase=PHASE_CANCEL;triggerHandler(event,phase,direction,distance);touchCancel(event);}}else
{phase=PHASE_CANCEL;triggerHandler(event,phase);touchCancel(event);}}else if(phase==PHASE_MOVE){phase=PHASE_CANCEL;triggerHandler(event,phase);touchCancel(event);}}function touchCancel(event){fingerCount=0;start.x=0;start.y=0;end.x=0;end.y=0;delta.x=0;delta.y=0;}function caluculateDistance(){return Math.round(Math.sqrt(Math.pow(end.x-start.x,2)+Math.pow(end.y-start.y,2)));}function caluculateAngle(){var X=start.x-end.x;var Y=end.y-start.y;var r=Math.atan2(Y,X);var angle=Math.round(r*180/Math.PI);if(angle<0)angle=360-Math.abs(angle);return angle;}function caluculateDirection(){var angle=caluculateAngle();if((angle<=45)&&(angle>=0))return LEFT;else if((angle<=360)&&(angle>=315))return LEFT;else if((angle>=135)&&(angle<=225))return RIGHT;else if((angle>45)&&(angle<135))return DOWN;else
return UP;}function triggerHandler(event,phase,direction,distance){if(defaults.swipeStatus)defaults.swipeStatus(event,phase,direction||null,distance||0);if(phase==PHASE_END){if(defaults.swipe)defaults.swipe(event,direction,distance);switch(direction){case LEFT:if(defaults.swipeLeft)defaults.swipeLeft(event,direction,distance);break;case RIGHT:if(defaults.swipeRight)defaults.swipeRight(event,direction,distance);break;case UP:if(defaults.swipeUp)defaults.swipeUp(event,direction,distance);break;case DOWN:if(defaults.swipeDown)defaults.swipeDown(event,direction,distance);break;}}}function validateDefaultEvent(event,direction){if(defaults.allowPageScroll==NONE){event.preventDefault();}else
{var auto=defaults.allowPageScroll==AUTO;switch(direction){case LEFT:if((defaults.swipeLeft&&auto)||(!auto&&defaults.allowPageScroll!=HORIZONTAL))event.preventDefault();break;case RIGHT:if((defaults.swipeRight&&auto)||(!auto&&defaults.allowPageScroll!=HORIZONTAL))event.preventDefault();break;case UP:if((defaults.swipeUp&&auto)||(!auto&&defaults.allowPageScroll!=VERTICAL))event.preventDefault();break;case DOWN:if((defaults.swipeDown&&auto)||(!auto&&defaults.allowPageScroll!=VERTICAL))event.preventDefault();break;}}}this.addEventListener("touchstart",touchStart,false);this.addEventListener("touchmove",touchMove,false);this.addEventListener("touchend",touchEnd,false);this.addEventListener("touchcancel",touchCancel,false);});};})(jQuery);

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
;
//var saveContext = null;

function launcher(context) {
	$('html').addClass('beforeLoading hasIMG');

	// Detect if image enabled
	var img = $('<img>');
	img.error(function() {
		$('html').removeClass('hasIMG').addClass('noIMG');
	});
	img.attr('src', '/sites/all/themes/sfr/js/pixel.jpg');

    if (!context) {
        context = document.body;
        context = $(context);
//		saveContext = context;
    }

    new SplitHome();
    context.find(".fakeSelect").fakeSelect();
    //context.find(".fakeSelect ul").fakeTab({fakeTabContent:'.fakeTabContent'});
    context.find(".actusOptions").fakeTab({fakeTabContent:'.carouselCtn', resize:true});
    context.find(".toggle").toggle();
    context.find(".ek_carouselPlayer").ekCarousel({
        pagination: true,
        duration: 1500,
        fx: "easeOutExpo",
        scroll: 1
    });
    context.find(".ek_carousel").ekCarousel({
        pagination: true,
        duration: 750,
        fx: "easeOutExpo",
        fixIE: true
    });
    context.find(".ek_cubes").ekCube({
        pagination: true,
        duration: 750,
        fx: "easeOutExpo",
        scroll: 1
    });
    context.find(".resizeBlocks").resizeBlocks();
    context.find(".clickableBlock").clickableBlock();
    if (context.find(".openSearch").length > 0) {
        context.find(".pageOptions").displayTopOptionsBlock({destination:'#headerMediaBox .content', allReadyOpened:'#search'});
    } else {
        context.find(".pageOptions").displayTopOptionsBlock({destination:'#headerMediaBox .content'});
    }

    context.find("#commentForm, #registerForm, #searchCareer").interactiveForm();
    context.find(".backToTop").backToTop();
    context.find("#nav").menuManagement();

    context.find(".txtPlus, .txtMoins").changeFontSize();
    context.find("#opt0").allChecked();

    // Deactivate link on diseable arrow
    context.find(".arrows .diseable").click(function() {
        return false;
    });

    context.find(".sfrLogo").logoPage();
}

function launcherLoad(context) {
    if (!context) {
        context = document.body;
        context = $(context);
    }

    context.find(".resizeBlocks").resizeBlocks();
}






$(window).load(function() {
    $('#opt2').attr('checked', 'checked'); // Check the second checkbox on subscribe template

    setTimeout(function () {
        $('#postOptions .social').each(injectSocialScript);
    }, 1000);
});


$(document).ready(function () {launcher();});
$(window).load(function () {launcherLoad();});


var F6 = {
    debug: true
}


/**
 * CrossBrowser error free logger
 * @function
 * @params {mix} whatever you want, display result could vary from browsers
 */
var Log = function (/* mix */) {
    if (window.console && console.log && F6.debug) {
        try {
            console.log.apply(console, arguments);
        } catch(e) {
            console.log(Array.prototype.slice(arguments));
        }
    }
};

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

jQuery.extend(jQuery.expr[':'],
{
    focusable: function (elm) {
        var elm = $(elm), type = elm.attr("tagName"), isFocusable = false;
        switch (true) {
            case type == "A":
            case type == "AREA":
            case type == "INPUT" && elm.attr("type") != "hidden":
            case type == "SELECT":
            case type == "TEXTAREA":
            case type == "BUTTON":
            case type == "LABEL":
            case elm.attr("tabindex") && parseInt(elm.attr("tabindex"),10) != -1:
                isFocusable = true;
                break;
        }


        return isFocusable;
    }
});;
function launchSocialFeed() {
    //$('li.social').show();
}

var interactiveForm = function() {
    this.initialize.apply(this, arguments);
}
interactiveForm.prototype = {
    constructor: "interactiveForm",

    options:{},

    initialize: function(el, options) {
        var _this = this;
        this.options = $.extend(interactiveForm.prototype.options, options);
        this.elm = $(el);
        this.fields = this.elm.find(".interactiveForm input, .interactiveForm textarea");
        this.selectFields = this.elm.find(".interactiveForm select");
        this.requiredFields = this.elm.find(".required");
        this.requiredMailFields = this.elm.find(".requiredMail");
        this.requiredSameFields = this.elm.find(".requiredSame");
        this.requiredOneChecked = this.elm.find(".requiredOneChecked");
        this.errorLabel = this.elm.find(".errorLabel");
        this.showChecked = this.elm.find(".playerBlock");
        this.addressForm = this.elm.find("#addressSubscription");

        _this.showChecked.each(function() {
             if ($(this).attr('checked'))
             {
                 _this.addressForm.removeClass('hidden');
             }

                  $(_this.addressForm.find('input.required').each(function() {
                       this.disabled = 'disabled';
                  }));
            
                 $(this).change(function() {
                    if ($(this).attr('checked'))
                    {
                        _this.addressForm.removeClass('hidden');
                        if (_this.addressForm.find('input.required')){
                            $(_this.addressForm.find('input.required').each(function() {
                               _this.addressForm.find('input.required').removeAttr("disabled")
                          }));
                        }
                    }
                     else
                    {
                        _this.addressForm.addClass('hidden');
                         if (_this.addressForm.find('input.required')){
                            $(_this.addressForm.find('input.required').each(function() {
                               this.disabled = 'disabled';
                          }));
                        }
                    }
                });
            });

        this.fields.each(function (o) {
            if ($(this).val() == "") {
                $(this).keypress(function () {
                    $(this).prev("label").css({color:'white'});
                    $(this).parent("p").removeClass("error");
                });
            }
            else {
                $(this).prev("label").css({color:'white'});
            }

            $(this).blur(function () {
                if ($(this).val() == "") {
                    $(this).prev("label").css({color:'#CED0D3'});
                }
            });
        });

          this.selectFields.each(function(o) {
              if ($(this).val() != '')
                {
                    $(this).css({color:'#4B525D'});
                }
               $(this).change(function () {
                if ($(this).val() == '')
                {
                     $(this).css({color:'#CED0D3'});
                }
                else
                {
                     $(this).css({color:'#4B525D'});
                }
          });
         });

        this.elm.submit(function(e) {
            _this.errorLabel.each(function() {
                $(this).css({visibility: 'hidden'});
            });
            var error = 0;
            if (!_this.verifVal(_this.elm, _this.requiredFields, _this.errorLabel)) {
                error ++;
            }
            if (!_this.verifMail(_this.elm, _this.requiredMailFields, _this.errorLabel)) {
                error ++;
            }

            if (!_this.verifSame(_this.elm, _this.requiredSameFields, _this.errorLabel)) {
                error ++;
            }

            if (_this.requiredOneChecked.length > 0 && !_this.verifOneChecked(_this.elm, _this.requiredOneChecked, _this.errorLabel)) {
                error ++;
            }

            if (error > 0) {
                return false;
            } else {
                return true;
            }
        });
    },

    verifVal : function(el, fields, errorLabel) {
        var error = 0;
        $(fields).each(function() {

            if ($(this).val() == ''&& !($(this).attr('disabled'))) {
                $(this).parent('p').addClass('error');
                el.find('.errorLabel#err' + $(this).attr('id')).css({visibility: 'visible'});
                error ++;
            }
        });

        if (error > 0) {
            return false;
        } else {
            return true;
        }
    },

    verifSame : function(el, fields, errorLabel) {
        sameValue = $(el).find('.verifySame').val();
        myValue = fields.val();

        if (sameValue != myValue) {
            el.find('.errorLabel#err' + fields.attr('id')).css({visibility: 'visible'});
            return false;
        }
        else {
            return true;
        }
    },

    verifMail : function(el, fields, errorLabel) {
        var error = 0;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        $(fields).each(function() {
            if ($(this).val() != '') {
                if (!emailReg.test($(this).val())) {
                    $(this).parent('p').addClass('error');
                    el.find('.errorLabel#err' + $(this).attr('id')).css({visibility: 'visible'});
                    error ++;
                }
            } else {
                $(this).parent('p').addClass('error');
                el.find('.errorLabel#err' + $(this).attr('id')).css({visibility: 'visible'});
                error ++;
            }
        });

        if (error > 0) {
            return false;
        } else {
            return true;
        }
    },

    verifOneChecked : function(el, fields, errorLabel) {
        var checkBox = $(fields).find('input[type=checkbox]');
		console.log(checkBox);
        var unCheckedMax = $(checkBox).size();
        var unChecked = 0;
        $(checkBox).each(function(o) {
            if (!$(this).attr('checked')) {
                unChecked += 1;
            }
        });

        if (unChecked == unCheckedMax) {
//         el.find('.errorLabel#err' + $(checkBox[0]).attr('name')).css({visibility: 'visible'});

			//custom correction SUPPORTFRONT-3
			var errorLabel = el.find('#errtheme');
      if(errorLabel.length){
			errorLabel.css({visibility: 'visible'});
			var errorLabelP = errorLabel.offset();
			$.scrollTo(errorLabelP.top, 500, { axis:'y' });
      }

			//enf of custom correction SUPPORTFRONT-3
            return false;
        } else {
            return true;
        }
    }
}

/* Affichage des block profil et recherche */
var displayTopOptionsBlock = function() {
    this.initialize.apply(this, arguments);
}
displayTopOptionsBlock.prototype = {
    constructor: "displayTopOptionsBlock",

    options:{
        oppenedClass: 'oppened',
        allReadyOpened: ''
    },

    initialize: function(el, options) {
        var _this = this;
        displayTopOptionsBlock.instances.push(this);
        this.options = $.extend(displayTopOptionsBlock.prototype.options, options);
        this.elm = $(el);
        this.oppened = false;
        this.oppenedId = '';
        this.links = this.elm.find("a").add($('.listOptions .search'));
        this.isRunning = false;

		this.oldTitle = '';
		this.activeTitle = ' - Rubrique active';
		
        if (this.options.allReadyOpened != '') {
            _this.isRunning = true;
            _this.moveInDom(_this.options.allReadyOpened, _this.options.destination, 'top', function() {
                _this.showPanel(_this.options.allReadyOpened, _this.options.oppenedClass, function() {
                    _this.isRunning = false;
                });
            });

            $(_this.links).each(function(e) {
                if ($(this).attr('href') == _this.options.allReadyOpened) {
					_this.oldTitle = $(this).attr('title');
                    $(this).addClass('current').attr('title', _this.oldTitle + _this.activeTitle);
                    /* Specific for SFR */
                    if (_this.options.allReadyOpened == '#profil') {
                        _this.elm.find("span").addClass('current');
                    }
                    /* End of specific for SFR */
                }
            });

            _this.oppenedId = _this.options.allReadyOpened;
            _this.oppened = true;
        }

        this.links.click(function(o) {
            if (_this.isRunning) {
                return false;
            } else {
                var blockId = $(this).attr("href");
                var clickedLink = $(this);
                //Log('ID precedent stocke: '+_this.oppenedId);
                switch (true) {
                    case (_this.oppenedId != blockId && !_this.oppened):
                        //console.log('case 1');
                        _this.isRunning = true;
                        _this.moveInDom(blockId, _this.options.destination, 'top', function() {
                            _this.showPanel(blockId, _this.options.oppenedClass, function() {
                                _this.isRunning = false;
                                if("#search" == blockId){
                                    $("input[name=search]").focus();
                                }
                            });
                        });
						_this.oldTitle = clickedLink.attr('title');
                        clickedLink.addClass('current').attr('title',  _this.oldTitle + _this.activeTitle);
                        /* Specific for SFR */
                        if (blockId == '#profil') {
                            _this.elm.find("span").addClass('current');
                        }
                        /* End of specific for SFR */
                        _this.oppenedId = blockId;
                        _this.oppened = true;
                        break;

                    case (_this.oppenedId != blockId && _this.oppened):
                        //console.log('case 2');
                        _this.isRunning = true;

                        _this.hidePanel(_this.oppenedId, _this.options.oppenedClass, function () {
                            _this.moveInDom(_this.oppenedId, 'body', 'bottom');
                            _this.moveInDom(blockId, _this.options.destination, 'top', function() {
                                _this.showPanel(blockId, _this.options.oppenedClass, function() {
                                    _this.isRunning = false;


                                });
                            });
                        });

						// Remove active title
						_this.links.each(function(){
							$(this).removeClass('current').attr('title', $(this).attr('title').replace(_this.activeTitle, ''));
						});

						_this.oldTitle = clickedLink.attr('title');
                        clickedLink.addClass('current').attr('title', _this.oldTitle + _this.activeTitle);
                        /* Specific for SFR */
                        if (blockId == '#profil') {
                            _this.elm.find("span").addClass('current');
                        } else {
                            _this.elm.find("span").removeClass('current');
                        }
                        /* End of specific for SFR */
                        _this.oppenedId = blockId;
                        break;

                    case (_this.oppenedId == blockId && _this.oppened):
                        //console.log('case 3');

                        _this.isRunning = true;
                        _this.hidePanel(_this.oppenedId, _this.options.oppenedClass, function() {
                            _this.moveInDom(_this.oppenedId, 'body', 'bottom', function() {
                                _this.isRunning = false;
                            });
                        });
						_this.links.each(function(){
							$(this).removeClass('current').attr('title', $(this).attr('title').replace(_this.activeTitle, ''));
						});
                        /* Specific for SFR */
                        _this.elm.find("span").removeClass('current');
                        /* End of specific for SFR */
                        _this.oppenedId = '';
                        _this.oppened = false;

                        break;
                }
//					Log('ID stocke: '+_this.oppenedId+', Id demande: '+blockId+', Block ouvert: '+ _this.oppened);


                //
                

                return false;
            }
        });

    },

    showPanel: function(el, oppenedClass, fn) {
        if (MenuManagement.testOpened()) {
            MenuManagement.closeAll(function() {

                $(el).slideDown(1100, 'easeOutQuint', fn || function () {

                }).addClass(oppenedClass);

            });
        } else {
            $(el).slideDown(1100, 'easeOutQuint', fn || function () {
            }).addClass(oppenedClass);
        }
    },

    hidePanel: function(el, oppenedClass, fn) {
        //console.log('hidePanel');
        $(el).slideUp(1100, 'easeOutQuint', fn || function () {
        }).removeClass(oppenedClass);
    },

    moveInDom: function(el, destination, moveOption, fn) {
        if (moveOption == 'top') {
            //console.log('moveInDom top');
            $(el).appendTo(destination);
            $(el).removeClass('hidden').addClass('displayN').attr('tabindex', '0');
            if (typeof fn == 'function') {
                fn();
            }
        } else if (moveOption == 'bottom') {
            //console.log('moveInDom bottom');
            $(el).appendTo(destination);
            $(el).removeClass('displayN').addClass('hidden').removeAttr('tabindex');
            if (typeof fn == 'function') {
                fn();
            }
        }
    },

    hidePanelFromNav: function(el, obj, fn) {
        var _this = obj;
        _this.isRunning = true;
        _this.hidePanel(_this.oppenedId, _this.options.oppenedClass, function() {
            _this.moveInDom(_this.oppenedId, 'body', 'bottom', function() {
                _this.isRunning = false;
                fn();
            });
        });
        _this.links.removeClass('current');
        /* Specific for SFR */
        _this.elm.find("span").removeClass('current');
        /* End of specific for SFR */
        _this.oppenedId = '';
        _this.oppened = false;
    }
};
displayTopOptionsBlock.instances = [];
displayTopOptionsBlock.closeAll = function(fn) {
    for (var i = 0; i < displayTopOptionsBlock.instances.length; i++) {
        $(displayTopOptionsBlock.instances[i]).each(function(i, inst) {
            displayTopOptionsBlock.prototype.hidePanelFromNav.call(inst, $(inst.elm), inst, fn);
        });
    }
};
displayTopOptionsBlock.testOpened = function() {
    var openMenu = 0;
    for (var i = 0; i < displayTopOptionsBlock.instances.length; i++) {
        $(displayTopOptionsBlock.instances[i]).each(function(i, inst) {
            if (this.oppened != false) {
                openMenu += 1;
            }
        });
    }

    if (openMenu > 0) {
        Log('un des menu est ouvert')
        return true;
    } else {
        Log('aucun menu sont ouvert')
        return false;
    }
};

var FakeTab = function() {
    this.initialize.apply(this, arguments);
}
FakeTab.prototype = {
    constructor: "FakeTab",

    options:{
		resize:false
	},

    initialize: function(el, options) {
        var _this = this;
        this.options = $.extend(FakeTab.prototype.options, options);
        this.elm = $(el);
        this.elm.a = this.elm.find('a').not(".noTabs");
        this.content = $(this.options.fakeTabContent);

		if (_this.options.resize){
			this.content.height(this.content.find('> *:first-child').height());
		}
        if (jQuery.browser.msie) {
            this.elm.a.click(function() {
                var clickThis = $(this);
				_this.elm.a.removeClass("current");
				clickThis.addClass("current");
				if (_this.options.resize){
					_this.content.animate({
						height:_this.content.find(clickThis.attr('href')).height()
					});
				}
                _this.content.find('.opened').removeClass('opened');
                _this.content.find(clickThis.attr('href')).addClass('opened');
                return false;
            });
        } else {
			this.content.find('.opened').fadeIn('slow');
            this.elm.a.click(function() {
                var clickThis = $(this);
				_this.elm.a.removeClass("current");
                _this.content.find('.opened').fadeOut('slow',
                        function() {
							if (_this.options.resize){
								_this.content.animate({
									height:_this.content.find(clickThis.attr('href')).height()
								}, function(){
									_this.content.find(clickThis.attr('href')).addClass('opened').fadeIn('slow');
								});
							}else{
								_this.content.find(clickThis.attr('href')).addClass('opened').fadeIn('slow');
							}

                            clickThis.addClass("current");
                        }).removeClass('opened');
                return false;
            });
        }
    }
}

/* Clickable block */
var clickableBlock = function() {
    this.initialize.apply(this, arguments);
}
clickableBlock.prototype = {
    constructor: "clickableBlock",

    options:{},

    initialize: function(el, options) {
        var _this = this;
        this.options = $.extend(clickableBlock.prototype.options, options);
        this.elm = $(el);
        this.link = this.elm.find("a");

        if (this.link) {

            this.title = this.link.attr("title");

            /* enleve le focus sur le a et le rajoute sur le li, ajoute le title sur le block */
            this.link.attr('tabindex', -1);
            this.elm.attr('title', this.title).attr('tabindex', 0);

            /* Ajoute l'action au click */
            this.elm.click(function(e) {
                // si ctrl presses -> _blank
                // sinon soit target value soit "_self"
                var target = (!e.ctrlKey) ? _this.link.attr("target") || "_self" : "_blank";
                window.open(_this.link.attr("href"), target);
                return false;
            });
        }
    }
}

/* Resize des blocks */
var resizeBlocks = function() {
    this.initialize.apply(this, arguments);
};
resizeBlocks.prototype = {
    constructor: "resizeBlocks",

    options:{},

    initialize: function(el, options) {
        var _this = this;
        this.options = $.extend(resizeBlocks.prototype.options, options);
        this.elm = $(el);
        this.li = this.elm.find("> li:not(.unresizable) ul");
        this.size = 0;
        this.li.each(function(o) {
            if ($(this).height() > _this.size) {
                _this.size = $(this).height();
            }
        });
        this.resize(this.size, this.li);
    },

    resize: function(size, els) {
        els.each(function(o) {
            $(this).height(size + 25);
        });
    }
}

/* LOGO SFR */
var logoPage = function() {
    this.initialize.apply(this, arguments);
};
logoPage.prototype = {
    constructor: "logoPage",

    options:{},

    initialize: function(el, options) {
        $(el).focus(function(e) {
            $(this.children).css("marginTop",'2px');
            $(this.children).css("marginLeft",'-2px');
        });
        $(el).blur(function(e) {
            $(this.children).css("marginTop",'0');
            $(this.children).css("marginLeft",'0');
        });
    }
}

var EkCarousel = function () {
    if (arguments.length) {
        this.initialize.apply(this, arguments);
    }
};

EkCarousel.prototype = {
    constructor : "EkCarousel",

    options: {
        scroll: 3,
        pagination: false,
        paginationContainer: ".paginate",
        paginationElementPattern: '<li><a href="#@@id@@" title="" index="@@item@@">@@item@@</a></li>', // page 1 / 4

        fixIE: false,
        scrollMode: true,

        /* events */
        onScroll: function () {
        },
        onMinimum: function () {
        },
        onMaximum: function () {
        },
        onInstanciate: function () {
        },
        onRefresh: function () {
        },

        duration: 500,
        fx: "linear"
    },

    /**
     *  constructeur
     * @member EkCarousel.prototype
     * @param elm
     * @param options
     */
    initialize: function(el, options) {
        var self = this;
        this.setOptions(options);
        this.elm = $(el);


        this.elm.attr("tabindex", "0");
        // grab vars

        this.mask = this.elm.find(".ek_carousel_mask");

        this.ul = this.mask.find('ul:first');
        this.id = this.elm.get(0).id || this.generateId();
        this.items = this.ul.find(" > li");
        this.itemWidth = this.items.eq(0).outerWidth();
        if (this.options.fixIE && jQuery.browser.msie && jQuery.browser.version == "7.0") {
            this.ul.width(this.items.length * this.itemWidth);
        }
        this.maskWidth = this.mask.width();
        this.maxWidth = this.itemWidth * this.items.length;
        this.initialScroll = 0;

        // if no scroll, stop it, it's useless...
        if (!this.options.fixIE && this.options.scrollMode && this.mask.attr("scrollWidth") <= this.ul.attr("offsetWidth")) return false;

        // clean DOM (to make inline-block square)
        $(this.ul.get(0).childNodes).each(function (i, el) {
            if (el.nodeType == 3) $(el).remove();
        });

        // place id everywhere
        this.items.each(function (i, el) {
            if (!el.id) {
                el.id = self.id + "_" + i;
            }
        });


        // events
        this.prev = this.elm.find('.ek_carousel_prev');
        this.prev.bind("click", function (o) {
            return function () {
                o.move(-1);
            }
        }(this));

        this.next = this.elm.find('.ek_carousel_next');
        this.next.bind("click", function (o) {
            return function () {
                o.move(1);
            }
        }(this));

        // mousewheel
        this.ul.hover(
                        function (o) {
                            return function (e, delta) {
                                o.TO = setTimeout(function () {
                                    o.isHovered = true;
                                }, 500);

                            }
                        }(this),
                        function (o) {
                            return function (e, delta) {
                                clearTimeout(o.TO);
                                o.isHovered = false;
                            }
                        }(this)
                );
        this.ul.mousewheel(function (o) {
            return function (e, delta) {
                if (o.isHovered) {
                    e.stopPropagation();
                    e.preventDefault();
                    o.move(delta);
                }
            }
        }(this));


        // touch event
        // thrown error on ie, quick & dirty solution
        if (!$.browser.msie) {
            this.ul.swipe({
                debug: true,
                allowPageScroll: "vertical",
                swipeStatus: function (e, phase, dir, distance) {
                    //e.stopPropagation();
                    $("#test").html(distance);
                    if (phase == "start") {
                        self.initialScroll = self.mask.scrollLeft();
                    }
                    else if (phase == "move") {
                        var s = dir == "left" ? 1 : -1;
                        self.mask.attr("scrollLeft", self.initialScroll + (s * distance));
                    }
                    else {
                        var step = self.itemWidth;
                        var scroll = self.mask.attr("scrollLeft");
                        var mod = scroll % step;
                        (dir == "left") ? self.doScroll(scroll + step - mod) : self.doScroll(scroll - mod);
                    }
                }
            });
        }

        // pagination

        if (this.options.pagination) {

            var lis = [];
            this.ulpagination = $("<ul />");
            this.items.each(function (i, el) {
                if (i % self.options.scroll == 0) {
                    var t = self.options.paginationElementPattern;
                    t = t.replace(/@@id@@/g, el.id);
                    t = t.replace(/@@item@@/g, i);
                    t = t.replace(/@@total@@/g, self.items.length);
                    self.ulpagination.append(t);
                }
            });
            this.ulpagination.find('a').click(function (e) {
                e.stopPropagation();
                e.preventDefault();
                self.step(e.target.getAttribute('index') * 1);
            });
            this.elm.find(this.options.paginationContainer).append(this.ulpagination);

        }

        // check
        this.check();
    },


    // move to prev or to next
    move: function (direction /* -1 -> gauche ou bas, 1 -> droite ou haut*/) {
        var val = this.mask.scrollLeft() + (this.itemWidth * this.options.scroll * direction);
        this.doScroll(val);
    },

    step: function (index) {
        var val = (index * this.itemWidth);
        this.doScroll(val);
    },

    // TODO ne plus passer la diff mais la valeur finale du scroll, facilitateur
    doScroll: function (val) {
		if (this.isRunning) return;
        var self = this;
        this.isRunning = true;
        this.mask.animate({"scrollLeft": val}, this.options.duration, this.options.fx, function (e) {
            self.check();
            self.options.onScroll.apply(this, [this]);
            self.isRunning = false;
        });
    },

    check: function () {
        //
        this.ulpagination.find(".current").removeClass('current');
        var i = Math.ceil((this.mask.scrollLeft() / this.itemWidth) / this.options.scroll);
        this.ulpagination.find("li").eq(i).addClass("current");
//        this.ulpagination.find("li a").eq(i).focus();


        // btns
        var where = this.mask.attr("scrollLeft");
        // total left
        if (where == 0) {
            this.prev.addClass("inactive");
            this.next.removeClass("inactive");
        }
        //total right
        else if (where + this.maskWidth == this.maxWidth) {
            this.next.addClass("inactive");
            this.prev.removeClass("inactive");
        }
        else {
            this.prev.removeClass("inactive");
            this.next.removeClass("inactive");
        }

        this.updateTitles(i);
    },

    generateId: function () {
        return "ekID_" + (new Date()).getTime() + "_" + Math.round(Math.random() * 1000000);
    },

    setOptions : function (options) {
        if (!options) {
            return;
        }
        var savedOpt = this.options;
        this.options = {};
        for (i in savedOpt) this.options[i] = savedOpt[i];
        for (i in options) this.options[i] = options[i];
    },

    updateTitles: function (currentIndex){
        var lis = this.ulpagination.find("li");
        var _this = this;
        lis.each(function (i, li){
            var end = (i+1) * _this.options.scroll;
            var start = end - (_this.options.scroll) + 1;
            if(i != currentIndex){
                var title = "Afficher les actualit\u00e9s de "+start+" \u00e0 " + end;

            }
            else {
                   title = "Actualit\u00e9s "+start+" \u00e0 "+end+", affich\u00e9s"
            }
            li.title = title;
        })
    }

}

jQuery.fn.ekCarousel = function (options) {
    $(this).each(function (i, el) {
        new EkCarousel(el, options);
    });
};

jQuery.fn.ekCube = function (options) {
    $(this).each(function (i, el) {
        new EkCube(el, options || {});
    });
};

var EkCube = function(el, options) {
    EkCarousel.call(this, el, options || {});
};
EkCube.prototype = new EkCarousel();

EkCube.prototype.options = {
    scroll: 1,
    pagination: false,
    paginationContainer: ".paginate",
    paginationElementPattern: '<li><a href="#@@id@@" title="" index="@@item@@">@@item@@</a></li>', // page 1 / 4

    fixIE: false,
    scrollMode: false,

    /* events */
    onScroll: function () {
    },
    onMinimum: function () {
    },
    onMaximum: function () {
    },
    onInstanciate: function () {
    },
    onRefresh: function () {
    },

    duration: 500,
    fx: "linear"

};

EkCube.prototype.initialize = function(el, options) {
    EkCarousel.prototype.initialize.call(this, el, options);
    var self = this;
    // pagination

    var lis = [];

    // touch event
    // thrown error on ie, quick & dirty solution
    if (!$.browser.msie) {
        this.ul.swipe({
            debug: true,
            allowPageScroll: "vertical",
            swipeStatus: function (e, phase, dir, distance) {
                //e.stopPropagation();
                if (phase == "start") {

                }
                else if (phase == "move") {
                    if (self.running || self.swipeIsStarted) return;
                    self.swipeIsStarted = true;
                    var s = dir == "left" ? self.currentIndex - 1 : self.currentIndex + 1;
                    self.step(s);
                }
                else {
                    self.swipeIsStarted = false;
                    /*var step = self.itemWidth;
                     var scroll = self.mask.attr("scrollLeft");
                     var mod = scroll % step;
                     (dir == "left") ? self.doScroll(scroll + step - mod) : self.doScroll(scroll - mod);*/
                }
            }
        });
    }

    this.items.each(function (i, el) {
        el = $(el);

        el.css({
            position: "absolute",
            width: el.width(),
            height: el.height()
        });
        self.doScroll(el, false);
    });
    this.step(0);
}

EkCube.prototype.move = function () {
    /* do nothing */
}

EkCube.prototype.step = function (index) {
    if (index < 0) {
        index = this.items.length - 1;
    }
    else if (index > this.items.length - 1) {
        index = 0;
    }


    if (typeof this.currentIndex == "number" && index == this.currentIndex) {
        return;
    }
    if (typeof this.currentIndex == "number") {
        this.doScroll(this.items.eq(this.currentIndex), false);
    }
    this.currentIndex = index;
    this.doScroll(this.items.eq(index), true);
}


// TODO ne plus passer la diff mais la valeur finale du scroll, facilitateur
EkCube.prototype.doScroll = function (li, show) {
    this.isRunning = true;
    var self = this;
    var meth = show ? 'fadeIn' : 'fadeOut';
    var img = li.find(".cubeMask img");
    var txt = li.find(".bd");
    li[meth](function () {
        self.running = false;
    });
    this.check();
}

EkCube.prototype.check = function () {
    //
    this.ulpagination.find(".current").removeClass('current');
    this.ulpagination.find("li").eq(this.currentIndex).addClass("current");
//    this.ulpagination.find("li a").eq(this.currentIndex).focus();
    this.items.removeClass("current");
    this.items.eq(this.currentIndex).addClass("current");
    this.updateTitles(this.currentIndex);
}

EkCube.prototype.updateTitles = function (currentIndex){
    var lis = this.ulpagination.find("li");
    var _this = this;
    lis.each(function (i, li){
        var start = _this.options.scroll * (i+1);
        var ext = (i == 0) ? "er" : "\u00e8me";

        if(i != currentIndex){
            var title = "Afficher le " +start + ext +" projet";
        }
        else {
            title = "Projet "+start+", affich\u00e9"
        }
        li.title = title;
    })
}

jQuery.fn.logoPage = function (options) {
    $(this).each(function (i, el) {
        new logoPage(el, options);
    });
};

jQuery.fn.resizeBlocks = function (options) {
    $(this).each(function (i, el) {
        new resizeBlocks(el, options);
    });
};

jQuery.fn.clickableBlock = function (options) {
    $(this).each(function (i, el) {
        new clickableBlock(el, options);
    });
};

jQuery.fn.displayTopOptionsBlock = function (options) {
    $(this).each(function (i, el) {
        new displayTopOptionsBlock(el, options);
    });
};

jQuery.fn.interactiveForm = function (options) {
    $(this).each(function (i, el) {
        new interactiveForm(el, options);
    });
};

jQuery.fn.fakeTab = function (options) {
    $(this).each(function (i, el) {
        new FakeTab(el, options);
    });
};

jQuery.fn.changeFontSize = function (options) {
    var settings = {
        less : 'txtMoins',
        more : 'txtPlus',
        boxToPasteClass : '.article',
        state : 0
    };
    options = options || {};
    $.extend(settings, options);
    if (!readCookie("accessFont")) {
        createCookie("accessFont", settings.state);
    }

    settings.state = parseInt(readCookie("accessFont"));
    $('body').addClass('accessFont_' + settings.state);

    return $(this).each(function (i, el) {
        var _this = this;
        var el = $(el);

        el.click(function() {
            switch (true) {
                case ($(this).attr('class') == settings.less):
                    if (settings.state > 0) {
                        decrement();
                    }
                    break;

                case ($(this).attr('class') == settings.more):
                    if (settings.state < 4) {
                        increment();
                    }
                    break;
            }
            return false;
        });

        function increment() {
            settings.state += 2;
            document.body.className = document.body.className.replace(/accessFont_[0-9]+/g, "accessFont_" + settings.state);
            createCookie("accessFont", settings.state);
        }

        function decrement() {
            settings.state -= 2;
            document.body.className = document.body.className.replace(/accessFont_[0-9]+/g, "accessFont_" + settings.state);
            createCookie("accessFont", settings.state);
        }
    });
};


var MenuManagement = function() {
    this.initialize.apply(this, arguments);
};
MenuManagement.prototype = {
    constructor: "MenuManagement",

    options:{
        blockToDisplay: '#navMenu',
        cursor: '.selection3d'
    },

    initialize: function(el, options) {
        var _this = this;
        MenuManagement.instances.push(this);
        this.options = $.extend(MenuManagement.prototype.options, options);
        this.el = $(el);
        this.links = this.el.find("a:not('.directLink')");
        this.currentLink = this.el.find("a.current");
        this.blockToDisplay = this.options.blockToDisplay;
        this.cursor = $(this.options.blockToDisplay).find(this.options.cursor);
        this.opened = this.options.opened || false;
        this.whosOpened = null;
        this.whosOpen = null;
        this.openedMenu = null;
        this.newOpenedMenu = null;

        $(this.blockToDisplay).removeClass('hidden').addClass('displayN');
        $(this.blockToDisplay).find('.hidden').each(function() {
            $(this).removeClass('hidden').addClass('displayN');
        });

        if (this.currentLink.length > 0) {
            _this.cursor.animate({left:$(_this.currentLink).position().left}, 200, 'easeOutQuint');
            _this.cursor.find('span').animate({width:$(_this.currentLink).width()}, 200, 'easeOutQuint');
        } else {
            if ($.browser.msie) {
                _this.cursor.css({visibility:'hidden'});
            } else {
                _this.cursor.css({opacity:0});
            }
        }

        $('.currentShow').live("keydown", function (e){
            if (e.which == '9' && e.shiftKey) {
                e.preventDefault();
                e.stopPropagation();
                _this.openedMenu.find('a:last').focus();
                _this.comeFromMySpecificEvent = true;
            }
        });

        this.links.click(function(e) {
            _this.links.each(function() {
                $(this).removeClass('currentShow');
                var oldTitle = $(this).attr("title");
                var newTitle = oldTitle.split('-')[0];
                $(this).attr({title: newTitle});
            });
            _this.whosOpen = _this.links.index(this);
            switch (true) {
                case(!_this.opened):
                    _this.open($(this), _this);
                    break;

                case(_this.opened && _this.whosOpened == _this.whosOpen):
                    _this.close($(this), _this);
                    break;

                case(_this.opened && _this.whosOpened != _this.whosOpen):
                    _this.changeContent($(this), _this);
                    break;
            }
            return false;
        });
    },

    close: function(el, obj, fn, directClose) {
        var _this = obj;
        if (!directClose) {
            directClose = true;
        }
        if (typeof fn != 'function') {
            fn = function() {
                return true;
            }
        }
        if (obj.currentLink.length > 0) {
            $(_this.cursor).animate({left:$(obj.currentLink).position().left}, 600, 'easeOutQuint');
            $(_this.cursor).find('span').animate({width:$(obj.currentLink).width()}, 600, 'easeOutQuint', function() {
                el.parents('ul').removeClass('currentAction');
                $(_this.blockToDisplay).slideUp('slow', 'easeOutQuint',
                        function() {
                            $(_this.openedMenu).hide().removeClass('opened');
                            if (!directClose) {
                                $(el).focus();
                            }
                            fn();
                        }).removeClass('opened');
            });
        } else {
            _this.cursor.css({left:$(el).position().left});
            _this.cursor.find('span').css({width:$(el).width()});
            if ($.browser.msie) {
                _this.cursor.css({visibility:'hidden'});
                $(el).parents('ul').removeClass('currentAction');
                $(_this.blockToDisplay).slideUp('slow', 'easeOutQuint',
                        function() {
                            // patch ie temporaire
                            $("#headerMediaBox .content").css('position', "relative");
                            _this.openedMenu.hide();
                            fn();
                        }).removeClass('opened');
            } else {
                _this.cursor.animate({opacity:0}, function() {
                    el.parents('ul').removeClass('currentAction');
                    $(_this.blockToDisplay).slideUp('slow', 'easeOutQuint',
                            function() {
                                // patch ie
                                $("#headerMediaBox .content").css('position', "relative");
                                $(_this.openedMenu).hide();
                                fn();
                            }).removeClass('opened');
                });
            }
        }
        /* Changements des etats */
        this.whosOpened = null;
        this.whosOpen = null;
        this.opened = false;
        //Log('End close, whosOpened: '+this.whosOpened+', whosOpen: '+this.whosOpen+', opened: '+this.opened)
    },

    open: function(el, obj) {
        var _this = obj;

        /* Affiche le menu voulu */
        _this.openedMenu = $(this.blockToDisplay).find($(el).attr('href'));
        _this.openedMenu.show();

        /* Ouvre le slider */
        if (displayTopOptionsBlock.testOpened()) {
            displayTopOptionsBlock.closeAll(function() {
                $(_this.blockToDisplay).slideDown('slow', 'easeOutQuint',
                        function() {
                            // patch ie temporaire
                            $("#headerMediaBox .content").css('position', "relative");
                            $(el).parents('ul').addClass('currentAction');
                            _this.openedMenu.find('a:first').focus().keydown(function(e) {
                                if (e.which == '9' && e.shiftKey) {
                                    $(el).focus();          
                                    return false;
                                }
                            });



                            /* Place le curseur */
                            if (_this.currentLink.length > 0) {
                                $(_this.cursor).animate({left:$(el).position().left}, 600, 'easeOutQuint');
                                $(_this.cursor).find('span').animate({width:$(el).width()}, 600, 'easeOutQuint');
                            } else {
                                $(_this.cursor).css({left:$(el).position().left});
                                $(_this.cursor).find('span').css({width:$(el).width()});
                                if ($.browser.msie) {
                                    $(_this.cursor).css({visibility:'visible'});
                                } else {
                                    $(_this.cursor).animate({opacity:1});
                                }
                            }


                        }).addClass('opened');

            });
        } else {
            $(this.blockToDisplay).slideDown('slow', 'easeOutQuint',
                    function() {
                        // patch ie temporaire
                        $("#headerMediaBox .content").css('position', "relative");
                        $(el).parents('ul').addClass('currentAction');
                        _this.openedMenu.find('a:first').focus().keydown(function(e) {
                            if (e.which == '9' && e.shiftKey) {
                                $(el).focus();
                                return false;
                            }
                        });

                        /* Place le curseur */
                        if (_this.currentLink.length > 0) {
                            $(_this.cursor).animate({left:$(el).position().left}, 600, 'easeOutQuint');
                            $(_this.cursor).find('span').animate({width:$(el).width()}, 600, 'easeOutQuint');
                        } else {
                            $(_this.cursor).css({left:$(el).position().left});
                            $(_this.cursor).find('span').css({width:$(el).width()});
                            if ($.browser.msie) {
                                $(_this.cursor).css({visibility:'visible'});
                            } else {
                                $(_this.cursor).animate({opacity:1});
                            }
                        }

                        _this.openedMenu.find('a:last').blur(function(e) {
                            if(!_this.comeFromMySpecificEvent){
                                _this.el.find(".currentShow").focus();
                            }
                            else {
                                _this.comeFromMySpecificEvent = false;
                            }

                        });

                    }).addClass('opened');


        }
//		var elWidth = $(this).width();

        this.links.last().blur(function(e){
            if(!$(this).hasClass('currentShow')){
                $(_this.blockToDisplay).next().find(':focusable')[0].focus();
            }
        });

        /* Changements des etats */
        this.whosOpened = this.whosOpen;
        this.whosOpen = null;
        this.opened = true;
        $(el).addClass('currentShow');
        var oldTitle = $(el).attr("title");
        $(el).attr({title: oldTitle + ' - Rubrique s\u00e9lectionn\u00e9e'});
        //Log('whosOpened ' + _this.whosOpened, 'whosOpen ' + _this.whosOpen);
    },

    changeContent: function(el, obj) {
        var _this = obj;
        /* Place le curseur */
        $(_this.cursor).animate({left:$(el).position().left}, 600, 'easeOutQuint');
        $(_this.cursor).find('span').animate({width:$(el).width()}, 600, 'easeOutQuint');

        /* Cache le menu present  Affiche le menu voulu */
        this.newOpenedMenu = $(this.blockToDisplay).find($(el).attr('href'));
        this.openedMenu.fadeOut('slow', function() {
            $(_this.newOpenedMenu).fadeIn('slow');
            $(_this.newOpenedMenu).find('a:first').focus().keydown(function(e) {
                if (e.which == '9' && e.shiftKey) {
                    $(el).focus();
                    return false;
                }
            });
            $(_this.newOpenedMenu).find('a:last').blur(function(e) {
                if(!_this.comeFromMySpecificEvent){
                    _this.el.find(".currentShow").focus();
                }
                else {
                    _this.comeFromMySpecificEvent = false;
                }

            });
        });
        this.openedMenu = this.newOpenedMenu;
        /* Changements des etats */
        this.whosOpened = this.whosOpen;
        $(el).addClass('currentShow');
        var oldTitle = $(el).attr("title");
        $(el).attr({title: oldTitle + ' - Rubrique s\u00e9lectionn\u00e9e'});
        //Log('whosOpened ' + _this.whosOpened, 'whosOpen ' + _this.whosOpen);
    }
};
MenuManagement.instances = [];
MenuManagement.closeAll = function (fn) {
    for (var i = 0; i < MenuManagement.instances.length; i++) {
        $(MenuManagement.instances[i]).each(function(i, inst) {
            MenuManagement.prototype.close.call(inst, $(inst.links).filter('.currentShow'), inst, fn, false);
        });
    }
};
MenuManagement.testOpened = function() {
    var openMenu = 0;
    for (var i = 0; i < MenuManagement.instances.length; i++) {
        $(MenuManagement.instances[i]).each(function() {
            if (this.opened != false) {
                openMenu += 1;
            }
        });
    }

    if (openMenu > 0) {
        return true;
    } else {
        return false;
    }
};


jQuery.fn.menuManagement = function (options) {
    $(this).each(function (i, el) {
        new MenuManagement(el, options);
    });
};


jQuery.fn.backToTop = function(options) {
    var settings = {};

    //extending options
    options = options || {};
    $.extend(settings, options);

    var sht = $(window).height();

    return $(this).each(function(i, el) {
        var el = $(el);
        var displayed = false;
		$(window).load(function(){
			var scht = $(this).scrollTop();
            if (scht >= sht / 3 && !displayed) {
                el.animate({
                    top: sht / 3
                }, 'slow', 'easeOutQuint');
                displayed = true;
            }
		});
        $(window).scroll(function() {
            var scht = $(this).scrollTop();
            if (scht >= sht / 3 && !displayed) {
                el.animate({
                    top: sht / 3
                }, 'slow', 'easeOutQuint');
                displayed = true;
            }
            if (scht <= sht / 3 && displayed) {
                el.animate({
                    top: '3000px'
                }, 'slow', 'linear');
                displayed = false;
            }
        });

		el.click(function(e){
			$.scrollTo('0px', 500, { axis:'y' });
		});
    });
};


jQuery.fn.fakeSelect = function (options) {
    $(document.body).click(FakeSelect.closeAll);

    $(this).each(function (i, el) {
        new FakeSelect(el, options);
    });
};

var FakeSelect = function() {
    this.initialize.apply(this, arguments);
}
FakeSelect.prototype = {
    constructor: "FakeSelect",

    options:{},

    initialize: function(el, options) {
        FakeSelect.instances.push(this);
        var _this = this;
        this.options = $.extend(FakeSelect.prototype.options, options);
        this.elm = $(el);
        this.elm.btn = this.elm.find('> a');
        this.elm.list = this.elm.find('> ul');
        this.elm.opened = false;
        if (this.elm.btn.length > 0) {
            $(this.elm.btn).click(function() {
                if (!_this.elm.opened) {
                    _this.open(_this.elm.list);
                    _this.elm.opened = true;
                } else {
                    _this.close(_this.elm.list);
                    _this.elm.opened = false;
                }
                return false;
            });
        }
    },

    open: function(el) {
        $(el).slideDown('easeOutQuint');
    },

    close: function(el) {
        $(el).slideUp('easeOutQuint');
    }
};
FakeSelect.instances = [];
FakeSelect.closeAll = function () {
    for (var i = 0; i < FakeSelect.instances.length; i++) {
        $(FakeSelect.instances[i]).each(function() {
            FakeSelect.prototype.close(this.elm.list);
            this.elm.opened = false;
        });
    }
};

jQuery.fn.allChecked = function (options) {
    var settings = {};
    //extending options
    options = options || {};
    $.extend(settings, options);

    return $(this).each(function(i, el) {
        var el = $(el);
        var otherEl = $('.allChoice input[type=checkbox]');
        el.change(function() {
            if (this.checked) {
                otherEl.each(function(e) {
                    $(this).attr('checked', 'checkeds');
                });
            } else {
                otherEl.each(function(e) {
                    $(this).removeAttr('checked');
                });
            }
        });

        otherEl.change(function() {
            if (!this.checked) {
                el.removeAttr('checked');
            }
        });
    });
};


var SplitHome = function () {
    this.initialize.apply(this, arguments);
}

SplitHome.prototype = {
    constructor: SplitHome,

    initialize: function () {
        if(!$("#headerMediaBox").length) return;
        this.imgs = $("#headerMediaBox .imgList li");
        this.texts = $("#headerMediaBox .txtList li");//.removeClass("currentSplit");
        this.texts.find(":focusable").attr("tabindex", -1);
        this.tops = $("#headerTopImg li");
        this.length = this.tops.length - 1;
        this.oldIndex = 0;
        this.currentIndex = Math.round(Math.random() * this.length);

        this.duration = 750;
        this.fx = "easeOutSine";


        this.prevBtn = $("#headerMediaBox .arrows .prev")
        this.nextBtn = $("#headerMediaBox .arrows .next")

        var self = this;
        this.prevBtn.click(function () {
            self.move(-1);
        });
        this.nextBtn.click(function () {
            self.move(1);
        });

        if (!$.browser.msie) {
        $("#headerMediaBox").swipe({
            debug: true,
            allowPageScroll: "vertical",
            swipeStatus: function (e, phase, dir, distance) {
                //e.stopPropagation();
                if (phase == "start") {

                }
                else if (phase == "move") {
                    if (self.running || self.swipeIsStarted) return;
                    self.swipeIsStarted = true;
                    var s = dir == "left" ?  1 :  -1;
                    self.move(s);
                }
                else {
                    self.swipeIsStarted = false;
                    /*var step = self.itemWidth;
                     var scroll = self.mask.attr("scrollLeft");
                     var mod = scroll % step;
                     (dir == "left") ? self.doScroll(scroll + step - mod) : self.doScroll(scroll - mod);*/
                }
            }
        });
    }


        this.doMove((this.currentIndex%2) == 0 ? -1 : 1);


    },

    move: function (direction) {
    Log(this.running);
        if (this.running) {

            return;
        }
        this.oldIndex = this.currentIndex;
        this.currentIndex += direction;
        //this.currentIndex = this.currentIndex%this.length;


        if (this.currentIndex > this.length) {
            this.currentIndex = 0;
        }
        else if (this.currentIndex < 0) {
            this.currentIndex = this.length;
        }


        this.doMove(direction);
    },

    doMove: function (dir) {

        // if futur current is already the current one or if it's already animated
        if (this.currentIndex == this.oldIndex || this.running) {
            return;
        }
        this.running  = true;
        var oAnimCurrentFrom, oAnimCurrentTo,oAnimOldFrom, oAnimOldTo;
        switch (dir) {
            case 1:
                oAnimCurrentFrom = "100%";
                oAnimCurrentTo = "0%";
                oAnimOldFrom = "0%";
                oAnimOldTo = "-50%";
                break;
            case -1:

                oAnimCurrentFrom = "-100%";
                oAnimCurrentTo = "0%";
                oAnimOldFrom = "0";
                oAnimOldTo = "50%";
                break;
        }


        var self = this;


        // tops
        this.tops.eq(this.currentIndex).css({left:oAnimCurrentFrom}).css("z-index", 50).animate({left:oAnimCurrentTo}, this.duration, this.fx);
        this.tops.eq(this.oldIndex).css({left:oAnimOldFrom}).css("z-index", 49).animate({left:oAnimOldTo}, this.duration, this.fx);


        // bigs
        this.imgs.eq(this.currentIndex).css({left:oAnimCurrentFrom}).css("z-index", 50).animate({left:oAnimCurrentTo}, this.duration, this.fx);
        this.imgs.eq(this.oldIndex).css({left:oAnimOldFrom}).css("z-index", 49).animate({left:oAnimOldTo}, this.duration, this.fx, function (){
            self.setCurrent()
        });

        // bigs
        this.texts.eq(this.currentIndex).animate({opacity: '1'}, this.duration, this.fx);
        this.texts.eq(this.oldIndex).animate({opacity: '0'}, this.duration, this.fx);

        
        

    },

    setCurrent: function () {

        this.tops.eq(this.oldIndex).removeClass("currentSplit").css("left", "100%").attr('aria-hidden', true);
        this.imgs.eq(this.oldIndex).removeClass("currentSplit").css("left", "100%").attr('aria-hidden', true);
        this.texts.eq(this.oldIndex).removeClass("currentSplit").attr('aria-hidden', true);
        this.texts.eq(this.oldIndex).find(":focusable").attr("tabindex", -1);
        this.tops.eq(this.currentIndex).addClass("currentSplit").attr('aria-hidden', false);
        this.imgs.eq(this.currentIndex).addClass("currentSplit").attr('aria-hidden', false);
        this.texts.eq(this.currentIndex).addClass("currentSplit").attr('aria-hidden', false);
        this.texts.eq(this.currentIndex).find(":focusable").attr("tabindex", "");
        this.running  = false;

    }
}

function injectSocialScript() {
    if ($(this).hasClass('twitter')) {
        $(this).html('<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-lang="fr">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>')
    }
    if ($(this).hasClass('facebook')) {
        $(this).html('<script src="http://connect.facebook.net/fr_FR/all.js#xfbml=1"></script><fb:like href="www.google.com" layout="button_count" show_faces="true" action="like"></fb:like>')
    }
    if ($(this).hasClass('linkedIn')) {
        $(this).html('<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share" data-counter="right"></script>');
    }
}
;

