﻿//Jquery Rotate
// VERSION: 1.8 LAST UPDATE: 9.03.2011
/* 
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 * 
 * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009
 * Website: http://code.google.com/p/jqueryrotate/ 
 */
 (function(g){for(var d,j=document.getElementsByTagName("head")[0].style,h="transformProperty WebkitTransform OTransform msTransform MozTransform".split(" "),e=0;e<h.length;e++)j[h[e]]!==void 0&&(d=h[e]);var i="v"=="\v";jQuery.fn.extend({ImageRotate:function(a){if(!this.Wilq32||!this.Wilq32.PhotoEffect)return a=g.extend(!0,{},a),(new Wilq32.PhotoEffect(this.get(0),a))._rootObj},rotate:function(a){if(!(this.length===0||typeof a=="undefined")){typeof a=="number"&&(a={angle:a});for(var c=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                [],b=0,d=this.length;b<d;b++){var f=this.get(b);typeof f.Wilq32=="undefined"?c.push(g(g(f).ImageRotate(a))):f.Wilq32.PhotoEffect._handleRotation(a)}return c}}});Wilq32=window.Wilq32||{};Wilq32.PhotoEffect=function(){return d?function(a,c){a.Wilq32={PhotoEffect:this};this._img=this._rootObj=this._eventObj=a;this._handleRotation(c)}:function(a,c){this._img=a;this._rootObj=document.createElement("span");this._rootObj.style.display="inline-block";this._rootObj.Wilq32={PhotoEffect:this};a.parentNode.insertBefore(this._rootObj,
     a);if(a.complete)this._Loader(c);else{var b=this;jQuery(this._img).bind("load",function(){b._Loader(c)})}}}();Wilq32.PhotoEffect.prototype={_setupParameters:function(a){this._parameters=this._parameters||{};if(typeof this._angle!=="number")this._angle=0;if(typeof a.angle==="number")this._angle=a.angle;this._parameters.animateTo=typeof a.animateTo==="number"?a.animateTo:this._angle;this._parameters.easing=a.easing||this._parameters.easing||function(a,b,d,f,e){return-f*((b=b/e-1)*b*b*b-1)+d};this._parameters.duration=
     a.duration||this._parameters.duration||1E3;this._parameters.callback=a.callback||this._parameters.callback||function(){};a.bind&&a.bind!=this._parameters.bind&&this._BindEvents(a.bind)},_handleRotation:function(a){this._setupParameters(a);this._angle==this._parameters.animateTo?this._rotate(this._angle):this._animateStart()},_BindEvents:function(a){if(a&&this._eventObj){if(this._parameters.bind){var c=this._parameters.bind,b;for(b in c)c.hasOwnProperty(b)&&jQuery(this._eventObj).unbind(b,c[b])}this._parameters.bind=
         a;for(b in a)a.hasOwnProperty(b)&&jQuery(this._eventObj).bind(b,a[b])}},_Loader:function(){return i?function(a){var c=this._img.width,b=this._img.height;this._img.parentNode.removeChild(this._img);this._vimage=this.createVMLNode("image");this._vimage.src=this._img.src;this._vimage.style.height=b+"px";this._vimage.style.width=c+"px";this._vimage.style.position="absolute";this._vimage.style.top="0px";this._vimage.style.left="0px";this._container=this.createVMLNode("group");this._container.style.width=
         c;this._container.style.height=b;this._container.style.position="absolute";this._container.setAttribute("coordsize",c-1+","+(b-1));this._container.appendChild(this._vimage);this._rootObj.appendChild(this._container);this._rootObj.style.position="relative";this._rootObj.style.width=c+"px";this._rootObj.style.height=b+"px";this._rootObj.setAttribute("id",this._img.getAttribute("id"));this._rootObj.className=this._img.className;this._eventObj=this._rootObj;this._handleRotation(a)}:function(a){this._rootObj.setAttribute("id",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   this._img.getAttribute("id"));this._rootObj.className=this._img.className;this._width=this._img.width;this._height=this._img.height;this._widthHalf=this._width/2;this._heightHalf=this._height/2;var c=Math.sqrt(this._height*this._height+this._width*this._width);this._widthAdd=c-this._width;this._heightAdd=c-this._height;this._widthAddHalf=this._widthAdd/2;this._heightAddHalf=this._heightAdd/2;this._img.parentNode.removeChild(this._img);this._aspectW=(parseInt(this._img.style.width,10)||this._width)/
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       this._img.width;this._aspectH=(parseInt(this._img.style.height,10)||this._height)/this._img.height;this._canvas=document.createElement("canvas");this._canvas.setAttribute("width",this._width);this._canvas.style.position="relative";this._canvas.style.left=-this._widthAddHalf+"px";this._canvas.style.top=-this._heightAddHalf+"px";this._canvas.Wilq32=this._rootObj.Wilq32;this._rootObj.appendChild(this._canvas);this._rootObj.style.width=this._width+"px";this._rootObj.style.height=this._height+"px";this._eventObj=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           this._canvas;this._cnv=this._canvas.getContext("2d");this._handleRotation(a)}}(),_animateStart:function(){this._timer&&clearTimeout(this._timer);this._animateStartTime=+new Date;this._animateStartAngle=this._angle;this._animate()},_animate:function(){var a=+new Date,c=a-this._animateStartTime>this._parameters.duration;if(c&&!this._parameters.animatedGif)clearTimeout(this._timer);else{(this._canvas||this._vimage||this._img)&&this._rotate(~~(this._parameters.easing(0,a-this._animateStartTime,this._animateStartAngle,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               this._parameters.animateTo-this._animateStartAngle,this._parameters.duration)*10)/10);var b=this;this._timer=setTimeout(function(){b._animate.call(b)},10)}if(this._parameters.callback&&c)this._angle=this._parameters.animateTo,this._rotate(this._angle),this._parameters.callback.call(this._rootObj)},_rotate:function(){var a=Math.PI/180;return i?function(a){this._angle=a;this._container.style.rotation=a%360+"deg"}:d?function(a){this._angle=a;this._img.style[d]="rotate("+a%360+"deg)"}:function(c){this._angle=
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   c;c=c%360*a;this._canvas.width=this._width+this._widthAdd;this._canvas.height=this._height+this._heightAdd;this._cnv.translate(this._widthAddHalf,this._heightAddHalf);this._cnv.translate(this._widthHalf,this._heightHalf);this._cnv.rotate(c);this._cnv.translate(-this._widthHalf,-this._heightHalf);this._cnv.scale(this._aspectW,this._aspectH);this._cnv.drawImage(this._img,0,0)}}()};if(i)Wilq32.PhotoEffect.prototype.createVMLNode=function(){document.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               try{return!document.namespaces.rvml&&document.namespaces.add("rvml","urn:schemas-microsoft-com:vml"),function(a){return document.createElement("<rvml:"+a+' class="rvml">')}}catch(a){return function(a){return document.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}}()})(jQuery);



//MouseWheel
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * 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.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.4
 * 
 * Requires: 1.2.2+
 */

(function($) {

var types = ['DOMMouseScroll', 'mousewheel'];

$.event.special.mousewheel = {
    setup: function() {
        if ( this.addEventListener ) {
            for ( var i=types.length; i; ) {
                this.addEventListener( types[--i], handler, false );
            }
        } else {
            this.onmousewheel = handler;
        }
    },
    
    teardown: function() {
        if ( this.removeEventListener ) {
            for ( var i=types.length; i; ) {
                this.removeEventListener( types[--i], handler, false );
            }
        } else {
            this.onmousewheel = null;
        }
    }
};

$.fn.extend({
    mousewheel: function(fn) {
        return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
    },
    
    unmousewheel: function(fn) {
        return this.unbind("mousewheel", fn);
    }
});


function handler(event) {
    var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
    event = $.event.fix(orgEvent);
    event.type = "mousewheel";
    
    // Old school scrollwheel delta
    if ( event.wheelDelta ) { delta = event.wheelDelta/120; }
    if ( event.detail     ) { delta = -event.detail/3; }
    
    // New school multidimensional scroll (touchpads) deltas
    deltaY = delta;
    
    // Gecko
    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
        deltaY = 0;
        deltaX = -1*delta;
    }
    
    // Webkit
    if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
    if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
    
    // Add event and delta to the front of the arguments
    args.unshift(event, delta, deltaX, deltaY);
    
    return $.event.handle.apply(this, args);
}

})(jQuery);


//Improve the MouseWheel Plugin
/**
 * @author trixta
 * @version 1.2
 */
(function($){

var mwheelI = {
			pos: [-260, -260]
		},
	minDif 	= 3,
	doc 	= document,
	root 	= doc.documentElement,
	body 	= doc.body,
	longDelay, shortDelay
;

function unsetPos(){
	if(this === mwheelI.elem){
		mwheelI.pos = [-260, -260];
		mwheelI.elem = false;
		minDif = 3;
	}
}

$.event.special.mwheelIntent = {
	setup: function(){
		var jElm = $(this).bind('mousewheel', $.event.special.mwheelIntent.handler);
		if( this !== doc && this !== root && this !== body ){
			jElm.bind('mouseleave', unsetPos);
		}
		jElm = null;
        return true;
    },
	teardown: function(){
        $(this)
			.unbind('mousewheel', $.event.special.mwheelIntent.handler)
			.unbind('mouseleave', unsetPos)
		;
        return true;
    },
    handler: function(e, d){
		var pos = [e.clientX, e.clientY];
		if( this === mwheelI.elem || Math.abs(mwheelI.pos[0] - pos[0]) > minDif || Math.abs(mwheelI.pos[1] - pos[1]) > minDif ){
            mwheelI.elem = this;
			mwheelI.pos = pos;
			minDif = 250;
			
			clearTimeout(shortDelay);
			shortDelay = setTimeout(function(){
				minDif = 10;
			}, 200);
			clearTimeout(longDelay);
			longDelay = setTimeout(function(){
				minDif = 3;
			}, 1500);
			e = $.extend({}, e, {type: 'mwheelIntent'});
            return $.event.handle.apply(this, arguments);
		}
    }
};
$.fn.extend({
	mwheelIntent: function(fn) {
		return fn ? this.bind("mwheelIntent", fn) : this.trigger("mwheelIntent");
	},
	
	unmwheelIntent: function(fn) {
		return this.unbind("mwheelIntent", fn);
	}
});

$(function(){
	body = doc.body;
	//assume that document is always scrollable, doesn't hurt if not
	$(doc).bind('mwheelIntent.mwheelIntentDefault', $.noop);
});
})(jQuery);



//jScrollPane
/*
 * jScrollPane - v2.0.0beta11 - 2011-07-04
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b,a,c){b.fn.jScrollPane=function(e){function d(D,O){var az,Q=this,Y,ak,v,am,T,Z,y,q,aA,aF,av,i,I,h,j,aa,U,aq,X,t,A,ar,af,an,G,l,au,ay,x,aw,aI,f,L,aj=true,P=true,aH=false,k=false,ap=D.clone(false,false).empty(),ac=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";aI=D.css("paddingTop")+" "+D.css("paddingRight")+" "+D.css("paddingBottom")+" "+D.css("paddingLeft");f=(parseInt(D.css("paddingLeft"),10)||0)+(parseInt(D.css("paddingRight"),10)||0);function at(aR){var aM,aO,aN,aK,aJ,aQ,aP=false,aL=false;az=aR;if(Y===c){aJ=D.scrollTop();aQ=D.scrollLeft();D.css({overflow:"hidden",padding:0});ak=D.innerWidth()+f;v=D.innerHeight();D.width(ak);Y=b('<div class="jspPane" />').css("padding",aI).append(D.children());am=b('<div class="jspContainer" />').css({width:ak+"px",height:v+"px"}).append(Y).appendTo(D)}else{D.css("width","");aP=az.stickToBottom&&K();aL=az.stickToRight&&B();aK=D.innerWidth()+f!=ak||D.outerHeight()!=v;if(aK){ak=D.innerWidth()+f;v=D.innerHeight();am.css({width:ak+"px",height:v+"px"})}if(!aK&&L==T&&Y.outerHeight()==Z){D.width(ak);return}L=T;Y.css("width","");D.width(ak);am.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}Y.css("overflow","auto");if(aR.contentWidth){T=aR.contentWidth}else{T=Y[0].scrollWidth}Z=Y[0].scrollHeight;Y.css("overflow","");y=T/ak;q=Z/v;aA=q>1;aF=y>1;if(!(aF||aA)){D.removeClass("jspScrollable");Y.css({top:0,width:am.width()-f});n();E();R();w();ai()}else{D.addClass("jspScrollable");aM=az.maintainPosition&&(I||aa);if(aM){aO=aD();aN=aB()}aG();z();F();if(aM){N(aL?(T-ak):aO,false);M(aP?(Z-v):aN,false)}J();ag();ao();if(az.enableKeyboardNavigation){S()}if(az.clickOnTrack){p()}C();if(az.hijackInternalLinks){m()}}if(az.autoReinitialise&&!aw){aw=setInterval(function(){at(az)},az.autoReinitialiseDelay)}else{if(!az.autoReinitialise&&aw){clearInterval(aw)}}aJ&&D.scrollTop(0)&&M(aJ,false);aQ&&D.scrollLeft(0)&&N(aQ,false);D.trigger("jsp-initialised",[aF||aA])}function aG(){if(aA){am.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'),b('<div class="jspDragBottom" />'))),b('<div class="jspCap jspCapBottom" />')));U=am.find(">.jspVerticalBar");aq=U.find(">.jspTrack");av=aq.find(">.jspDrag");if(az.showArrows){ar=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",aE(0,-1)).bind("click.jsp",aC);af=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",aE(0,1)).bind("click.jsp",aC);if(az.arrowScrollOnHover){ar.bind("mouseover.jsp",aE(0,-1,ar));af.bind("mouseover.jsp",aE(0,1,af))}al(aq,az.verticalArrowPositions,ar,af)}t=v;am.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){t-=b(this).outerHeight()});av.hover(function(){av.addClass("jspHover")},function(){av.removeClass("jspHover")}).bind("mousedown.jsp",function(aJ){b("html").bind("dragstart.jsp selectstart.jsp",aC);av.addClass("jspActive");var s=aJ.pageY-av.position().top;b("html").bind("mousemove.jsp",function(aK){V(aK.pageY-s,false)}).bind("mouseup.jsp mouseleave.jsp",ax);return false});o()}}function o(){aq.height(t+"px");I=0;X=az.verticalGutter+aq.outerWidth();Y.width(ak-X-f);try{if(U.position().left===0){Y.css("margin-left",X+"px")}}catch(s){}}function z(){if(aF){am.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'),b('<div class="jspDragRight" />'))),b('<div class="jspCap jspCapRight" />')));an=am.find(">.jspHorizontalBar");G=an.find(">.jspTrack");h=G.find(">.jspDrag");if(az.showArrows){ay=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",aE(-1,0)).bind("click.jsp",aC);x=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",aE(1,0)).bind("click.jsp",aC);
if(az.arrowScrollOnHover){ay.bind("mouseover.jsp",aE(-1,0,ay));x.bind("mouseover.jsp",aE(1,0,x))}al(G,az.horizontalArrowPositions,ay,x)}h.hover(function(){h.addClass("jspHover")},function(){h.removeClass("jspHover")}).bind("mousedown.jsp",function(aJ){b("html").bind("dragstart.jsp selectstart.jsp",aC);h.addClass("jspActive");var s=aJ.pageX-h.position().left;b("html").bind("mousemove.jsp",function(aK){W(aK.pageX-s,false)}).bind("mouseup.jsp mouseleave.jsp",ax);return false});l=am.innerWidth();ah()}}function ah(){am.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){l-=b(this).outerWidth()});G.width(l+"px");aa=0}function F(){if(aF&&aA){var aJ=G.outerHeight(),s=aq.outerWidth();t-=aJ;b(an).find(">.jspCap:visible,>.jspArrow").each(function(){l+=b(this).outerWidth()});l-=s;v-=s;ak-=aJ;G.parent().append(b('<div class="jspCorner" />').css("width",aJ+"px"));o();ah()}if(aF){Y.width((am.outerWidth()-f)+"px")}Z=Y.outerHeight();q=Z/v;if(aF){au=Math.ceil(1/y*l);if(au>az.horizontalDragMaxWidth){au=az.horizontalDragMaxWidth}else{if(au<az.horizontalDragMinWidth){au=az.horizontalDragMinWidth}}h.width(au+"px");j=l-au;ae(aa)}if(aA){A=Math.ceil(1/q*t);if(A>az.verticalDragMaxHeight){A=az.verticalDragMaxHeight}else{if(A<az.verticalDragMinHeight){A=az.verticalDragMinHeight}}av.height(A+"px");i=t-A;ad(I)}}function al(aK,aM,aJ,s){var aO="before",aL="after",aN;if(aM=="os"){aM=/Mac/.test(navigator.platform)?"after":"split"}if(aM==aO){aL=aM}else{if(aM==aL){aO=aM;aN=aJ;aJ=s;s=aN}}aK[aO](aJ)[aL](s)}function aE(aJ,s,aK){return function(){H(aJ,s,this,aK);this.blur();return false}}function H(aM,aL,aP,aO){aP=b(aP).addClass("jspActive");var aN,aK,aJ=true,s=function(){if(aM!==0){Q.scrollByX(aM*az.arrowButtonSpeed)}if(aL!==0){Q.scrollByY(aL*az.arrowButtonSpeed)}aK=setTimeout(s,aJ?az.initialDelay:az.arrowRepeatFreq);aJ=false};s();aN=aO?"mouseout.jsp":"mouseup.jsp";aO=aO||b("html");aO.bind(aN,function(){aP.removeClass("jspActive");aK&&clearTimeout(aK);aK=null;aO.unbind(aN)})}function p(){w();if(aA){aq.bind("mousedown.jsp",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageY-aP.top-I,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageY-aS.top-A/2,aQ=v*az.scrollPagePercent,aR=i*aQ/(Z-v);if(aN<0){if(I-aR>aT){Q.scrollByY(-aQ)}else{V(aT)}}else{if(aN>0){if(I+aR<aT){Q.scrollByY(aQ)}else{V(aT)}}else{aL();return}}aK=setTimeout(s,aJ?az.initialDelay:az.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.jsp",aL)};s();b(document).bind("mouseup.jsp",aL);return false}})}if(aF){G.bind("mousedown.jsp",function(aO){if(aO.originalTarget===c||aO.originalTarget==aO.currentTarget){var aM=b(this),aP=aM.offset(),aN=aO.pageX-aP.left-aa,aK,aJ=true,s=function(){var aS=aM.offset(),aT=aO.pageX-aS.left-au/2,aQ=ak*az.scrollPagePercent,aR=j*aQ/(T-ak);if(aN<0){if(aa-aR>aT){Q.scrollByX(-aQ)}else{W(aT)}}else{if(aN>0){if(aa+aR<aT){Q.scrollByX(aQ)}else{W(aT)}}else{aL();return}}aK=setTimeout(s,aJ?az.initialDelay:az.trackClickRepeatFreq);aJ=false},aL=function(){aK&&clearTimeout(aK);aK=null;b(document).unbind("mouseup.jsp",aL)};s();b(document).bind("mouseup.jsp",aL);return false}})}}function w(){if(G){G.unbind("mousedown.jsp")}if(aq){aq.unbind("mousedown.jsp")}}function ax(){b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");if(av){av.removeClass("jspActive")}if(h){h.removeClass("jspActive")}}function V(s,aJ){if(!aA){return}if(s<0){s=0}else{if(s>i){s=i}}if(aJ===c){aJ=az.animateScroll}if(aJ){Q.animate(av,"top",s,ad)}else{av.css("top",s);ad(s)}}function ad(aJ){if(aJ===c){aJ=av.position().top}am.scrollTop(0);I=aJ;var aM=I===0,aK=I==i,aL=aJ/i,s=-aL*(Z-v);if(aj!=aM||aH!=aK){aj=aM;aH=aK;D.trigger("jsp-arrow-change",[aj,aH,P,k])}u(aM,aK);Y.css("top",s);D.trigger("jsp-scroll-y",[-s,aM,aK]).trigger("scroll")}function W(aJ,s){if(!aF){return}if(aJ<0){aJ=0}else{if(aJ>j){aJ=j}}if(s===c){s=az.animateScroll}if(s){Q.animate(h,"left",aJ,ae)
}else{h.css("left",aJ);ae(aJ)}}function ae(aJ){if(aJ===c){aJ=h.position().left}am.scrollTop(0);aa=aJ;var aM=aa===0,aL=aa==j,aK=aJ/j,s=-aK*(T-ak);if(P!=aM||k!=aL){P=aM;k=aL;D.trigger("jsp-arrow-change",[aj,aH,P,k])}r(aM,aL);Y.css("left",s);D.trigger("jsp-scroll-x",[-s,aM,aL]).trigger("scroll")}function u(aJ,s){if(az.showArrows){ar[aJ?"addClass":"removeClass"]("jspDisabled");af[s?"addClass":"removeClass"]("jspDisabled")}}function r(aJ,s){if(az.showArrows){ay[aJ?"addClass":"removeClass"]("jspDisabled");x[s?"addClass":"removeClass"]("jspDisabled")}}function M(s,aJ){var aK=s/(Z-v);V(aK*i,aJ)}function N(aJ,s){var aK=aJ/(T-ak);W(aK*j,s)}function ab(aW,aR,aK){var aO,aL,aM,s=0,aV=0,aJ,aQ,aP,aT,aS,aU;try{aO=b(aW)}catch(aN){return}aL=aO.outerHeight();aM=aO.outerWidth();am.scrollTop(0);am.scrollLeft(0);while(!aO.is(".jspPane")){s+=aO.position().top;aV+=aO.position().left;aO=aO.offsetParent();if(/^body|html$/i.test(aO[0].nodeName)){return}}aJ=aB();aP=aJ+v;if(s<aJ||aR){aS=s-az.verticalGutter}else{if(s+aL>aP){aS=s-v+aL+az.verticalGutter}}if(aS){M(aS,aK)}aQ=aD();aT=aQ+ak;if(aV<aQ||aR){aU=aV-az.horizontalGutter}else{if(aV+aM>aT){aU=aV-ak+aM+az.horizontalGutter}}if(aU){N(aU,aK)}}function aD(){return -Y.position().left}function aB(){return -Y.position().top}function K(){var s=Z-v;return(s>20)&&(s-aB()<10)}function B(){var s=T-ak;return(s>20)&&(s-aD()<10)}function ag(){am.unbind(ac).bind(ac,function(aM,aN,aL,aJ){var aK=aa,s=I;Q.scrollBy(aL*az.mouseWheelSpeed,-aJ*az.mouseWheelSpeed,false);return aK==aa&&s==I})}function n(){am.unbind(ac)}function aC(){return false}function J(){Y.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(s){ab(s.target,false)})}function E(){Y.find(":input,a").unbind("focus.jsp")}function S(){var s,aJ,aL=[];aF&&aL.push(an[0]);aA&&aL.push(U[0]);Y.focus(function(){D.focus()});D.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(aO){if(aO.target!==this&&!(aL.length&&b(aO.target).closest(aL).length)){return}var aN=aa,aM=I;switch(aO.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:s=aO.keyCode;aK();break;case 35:M(Z-v);s=null;break;case 36:M(0);s=null;break}aJ=aO.keyCode==s&&aN!=aa||aM!=I;return !aJ}).bind("keypress.jsp",function(aM){if(aM.keyCode==s){aK()}return !aJ});if(az.hideFocus){D.css("outline","none");if("hideFocus" in am[0]){D.attr("hideFocus",true)}}else{D.css("outline","");if("hideFocus" in am[0]){D.attr("hideFocus",false)}}function aK(){var aN=aa,aM=I;switch(s){case 40:Q.scrollByY(az.keyboardSpeed,false);break;case 38:Q.scrollByY(-az.keyboardSpeed,false);break;case 34:case 32:Q.scrollByY(v*az.scrollPagePercent,false);break;case 33:Q.scrollByY(-v*az.scrollPagePercent,false);break;case 39:Q.scrollByX(az.keyboardSpeed,false);break;case 37:Q.scrollByX(-az.keyboardSpeed,false);break}aJ=aN!=aa||aM!=I;return aJ}}function R(){D.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function C(){if(location.hash&&location.hash.length>1){var aL,aJ,aK=escape(location.hash);try{aL=b(aK)}catch(s){return}if(aL.length&&Y.find(aK)){if(am.scrollTop()===0){aJ=setInterval(function(){if(am.scrollTop()>0){ab(aK,true);b(document).scrollTop(am.position().top);clearInterval(aJ)}},50)}else{ab(aK,true);b(document).scrollTop(am.position().top)}}}}function ai(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function m(){ai();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),aJ;if(s.length>1){aJ=s[1];if(aJ.length>0&&Y.find("#"+aJ).length>0){ab("#"+aJ,true);return false}}})}function ao(){var aK,aJ,aM,aL,aN,s=false;am.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(aO){var aP=aO.originalEvent.touches[0];aK=aD();aJ=aB();aM=aP.pageX;aL=aP.pageY;aN=false;s=true}).bind("touchmove.jsp",function(aR){if(!s){return}var aQ=aR.originalEvent.touches[0],aP=aa,aO=I;Q.scrollTo(aK+aM-aQ.pageX,aJ+aL-aQ.pageY);aN=aN||Math.abs(aM-aQ.pageX)>5||Math.abs(aL-aQ.pageY)>5;
return aP==aa&&aO==I}).bind("touchend.jsp",function(aO){s=false}).bind("click.jsp-touchclick",function(aO){if(aN){aN=false;return false}})}function g(){var s=aB(),aJ=aD();D.removeClass("jspScrollable").unbind(".jsp");D.replaceWith(ap.append(Y.children()));ap.scrollTop(s);ap.scrollLeft(aJ)}b.extend(Q,{reinitialise:function(aJ){aJ=b.extend({},az,aJ);at(aJ)},scrollToElement:function(aK,aJ,s){ab(aK,aJ,s)},scrollTo:function(aK,s,aJ){N(aK,aJ);M(s,aJ)},scrollToX:function(aJ,s){N(aJ,s)},scrollToY:function(s,aJ){M(s,aJ)},scrollToPercentX:function(aJ,s){N(aJ*(T-ak),s)},scrollToPercentY:function(aJ,s){M(aJ*(Z-v),s)},scrollBy:function(aJ,s,aK){Q.scrollByX(aJ,aK);Q.scrollByY(s,aK)},scrollByX:function(s,aK){var aJ=aD()+Math[s<0?"floor":"ceil"](s),aL=aJ/(T-ak);W(aL*j,aK)},scrollByY:function(s,aK){var aJ=aB()+Math[s<0?"floor":"ceil"](s),aL=aJ/(Z-v);V(aL*i,aK)},positionDragX:function(s,aJ){W(s,aJ)},positionDragY:function(aJ,s){V(aJ,s)},animate:function(aJ,aM,s,aL){var aK={};aK[aM]=s;aJ.animate(aK,{duration:az.animateDuration,easing:az.animateEase,queue:false,step:aL})},getContentPositionX:function(){return aD()},getContentPositionY:function(){return aB()},getContentWidth:function(){return T},getContentHeight:function(){return Z},getPercentScrolledX:function(){return aD()/(T-ak)},getPercentScrolledY:function(){return aB()/(Z-v)},getIsScrollableH:function(){return aF},getIsScrollableV:function(){return aA},getContentPane:function(){return Y},scrollToBottom:function(s){V(i,s)},hijackInternalLinks:function(){m()},destroy:function(){g()}});at(O)}e=b.extend({},b.fn.jScrollPane.defaults,e);b.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){e[this]=e[this]||e.speed});return this.each(function(){var f=b(this),g=f.data("jsp");if(g){g.reinitialise(e)}else{g=new d(f,e);f.data("jsp",g)}})};b.fn.jScrollPane.defaults={showArrows:false,maintainPosition:true,stickToBottom:false,stickToRight:false,clickOnTrack:true,autoReinitialise:false,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,contentWidth:c,animateScroll:false,animateDuration:300,animateEase:"linear",hijackInternalLinks:false,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:false,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:true,hideFocus:false,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:0.8}})(jQuery,this);



//Jquery Cycle
/*
 * jQuery Cycle Plugin (core engine only)
 * Examples and documentation at: http://jquery.malsup.com/cycle/
 * Copyright (c) 2007-2010 M. Alsup
 * Version: 2.99 (12-MAR-2011)
 * Dual licensed under the MIT and GPL licenses.
 * http://jquery.malsup.com/license.html
 * Requires: jQuery v1.3.2 or later
 */
(function($){var ver="2.99";if($.support==undefined){$.support={opacity:!($.browser.msie)};}function debug(s){$.fn.cycle.debug&&log(s);}function log(){window.console&&console.log&&console.log("[cycle] "+Array.prototype.join.call(arguments," "));}$.expr[":"].paused=function(el){return el.cyclePause;};$.fn.cycle=function(options,arg2){var o={s:this.selector,c:this.context};if(this.length===0&&options!="stop"){if(!$.isReady&&o.s){log("DOM not ready, queuing slideshow");$(function(){$(o.s,o.c).cycle(options,arg2);});return this;}log("terminating; zero elements found by selector"+($.isReady?"":" (DOM not ready)"));return this;}return this.each(function(){var opts=handleArguments(this,options,arg2);if(opts===false){return;}opts.updateActivePagerLink=opts.updateActivePagerLink||$.fn.cycle.updateActivePagerLink;if(this.cycleTimeout){clearTimeout(this.cycleTimeout);}this.cycleTimeout=this.cyclePause=0;var $cont=$(this);var $slides=opts.slideExpr?$(opts.slideExpr,this):$cont.children();var els=$slides.get();if(els.length<2){log("terminating; too few slides: "+els.length);return;}var opts2=buildOptions($cont,$slides,els,opts,o);if(opts2===false){return;}var startTime=opts2.continuous?10:getTimeout(els[opts2.currSlide],els[opts2.nextSlide],opts2,!opts2.backwards);if(startTime){startTime+=(opts2.delay||0);if(startTime<10){startTime=10;}debug("first timeout: "+startTime);this.cycleTimeout=setTimeout(function(){go(els,opts2,0,!opts.backwards);},startTime);}});};function handleArguments(cont,options,arg2){if(cont.cycleStop==undefined){cont.cycleStop=0;}if(options===undefined||options===null){options={};}if(options.constructor==String){switch(options){case"destroy":case"stop":var opts=$(cont).data("cycle.opts");if(!opts){return false;}cont.cycleStop++;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);}cont.cycleTimeout=0;$(cont).removeData("cycle.opts");if(options=="destroy"){destroy(opts);}return false;case"toggle":cont.cyclePause=(cont.cyclePause===1)?0:1;checkInstantResume(cont.cyclePause,arg2,cont);return false;case"pause":cont.cyclePause=1;return false;case"resume":cont.cyclePause=0;checkInstantResume(false,arg2,cont);return false;case"prev":case"next":var opts=$(cont).data("cycle.opts");if(!opts){log('options not found, "prev/next" ignored');return false;}$.fn.cycle[options](opts);return false;default:options={fx:options};}return options;}else{if(options.constructor==Number){var num=options;options=$(cont).data("cycle.opts");if(!options){log("options not found, can not advance slide");return false;}if(num<0||num>=options.elements.length){log("invalid slide index: "+num);return false;}options.nextSlide=num;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}if(typeof arg2=="string"){options.oneTimeFx=arg2;}go(options.elements,options,1,num>=options.currSlide);return false;}}return options;function checkInstantResume(isPaused,arg2,cont){if(!isPaused&&arg2===true){var options=$(cont).data("cycle.opts");if(!options){log("options not found, can not resume");return false;}if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}go(options.elements,options,1,!options.backwards);}}}function removeFilter(el,opts){if(!$.support.opacity&&opts.cleartype&&el.style.filter){try{el.style.removeAttribute("filter");}catch(smother){}}}function destroy(opts){if(opts.next){$(opts.next).unbind(opts.prevNextEvent);}if(opts.prev){$(opts.prev).unbind(opts.prevNextEvent);}if(opts.pager||opts.pagerAnchorBuilder){$.each(opts.pagerAnchors||[],function(){this.unbind().remove();});}opts.pagerAnchors=null;if(opts.destroy){opts.destroy(opts);}}function buildOptions($cont,$slides,els,options,o){var opts=$.extend({},$.fn.cycle.defaults,options||{},$.metadata?$cont.metadata():$.meta?$cont.data():{});if(opts.autostop){opts.countdown=opts.autostopCount||els.length;}var cont=$cont[0];$cont.data("cycle.opts",opts);opts.$cont=$cont;opts.stopCount=cont.cycleStop;opts.elements=els;opts.before=opts.before?[opts.before]:[];opts.after=opts.after?[opts.after]:[];if(!$.support.opacity&&opts.cleartype){opts.after.push(function(){removeFilter(this,opts);});}if(opts.continuous){opts.after.push(function(){go(els,opts,0,!opts.backwards);});}saveOriginalOpts(opts);if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($slides);}if($cont.css("position")=="static"){$cont.css("position","relative");}if(opts.width){$cont.width(opts.width);}if(opts.height&&opts.height!="auto"){$cont.height(opts.height);}if(opts.startingSlide){opts.startingSlide=parseInt(opts.startingSlide);}else{if(opts.backwards){opts.startingSlide=els.length-1;}}if(opts.random){opts.randomMap=[];for(var i=0;i<els.length;i++){opts.randomMap.push(i);}opts.randomMap.sort(function(a,b){return Math.random()-0.5;});opts.randomIndex=1;opts.startingSlide=opts.randomMap[1];}else{if(opts.startingSlide>=els.length){opts.startingSlide=0;}}opts.currSlide=opts.startingSlide||0;var first=opts.startingSlide;$slides.css({position:"absolute",top:0,left:0}).hide().each(function(i){var z;if(opts.backwards){z=first?i<=first?els.length+(i-first):first-i:els.length-i;}else{z=first?i>=first?els.length-(i-first):first-i:els.length-i;}$(this).css("z-index",z);});$(els[first]).css("opacity",1).show();removeFilter(els[first],opts);if(opts.fit&&opts.width){$slides.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$slides.height(opts.height);}var reshape=opts.containerResize&&!$cont.innerHeight();if(reshape){var maxw=0,maxh=0;for(var j=0;j<els.length;j++){var $e=$(els[j]),e=$e[0],w=$e.outerWidth(),h=$e.outerHeight();if(!w){w=e.offsetWidth||e.width||$e.attr("width");}if(!h){h=e.offsetHeight||e.height||$e.attr("height");}maxw=w>maxw?w:maxw;maxh=h>maxh?h:maxh;}if(maxw>0&&maxh>0){$cont.css({width:maxw+"px",height:maxh+"px"});}}if(opts.pause){$cont.hover(function(){this.cyclePause++;},function(){this.cyclePause--;});}if(supportMultiTransitions(opts)===false){return false;}var requeue=false;options.requeueAttempts=options.requeueAttempts||0;$slides.each(function(){var $el=$(this);this.cycleH=(opts.fit&&opts.height)?opts.height:($el.height()||this.offsetHeight||this.height||$el.attr("height")||0);this.cycleW=(opts.fit&&opts.width)?opts.width:($el.width()||this.offsetWidth||this.width||$el.attr("width")||0);if($el.is("img")){var loadingIE=($.browser.msie&&this.cycleW==28&&this.cycleH==30&&!this.complete);var loadingFF=($.browser.mozilla&&this.cycleW==34&&this.cycleH==19&&!this.complete);var loadingOp=($.browser.opera&&((this.cycleW==42&&this.cycleH==19)||(this.cycleW==37&&this.cycleH==17))&&!this.complete);var loadingOther=(this.cycleH==0&&this.cycleW==0&&!this.complete);if(loadingIE||loadingFF||loadingOp||loadingOther){if(o.s&&opts.requeueOnImageNotLoaded&&++options.requeueAttempts<100){log(options.requeueAttempts," - img slide not loaded, requeuing slideshow: ",this.src,this.cycleW,this.cycleH);setTimeout(function(){$(o.s,o.c).cycle(options);},opts.requeueTimeout);requeue=true;return false;}else{log("could not determine size of image: "+this.src,this.cycleW,this.cycleH);}}}return true;});if(requeue){return false;}opts.cssBefore=opts.cssBefore||{};opts.cssAfter=opts.cssAfter||{};opts.cssFirst=opts.cssFirst||{};opts.animIn=opts.animIn||{};opts.animOut=opts.animOut||{};$slides.not(":eq("+first+")").css(opts.cssBefore);$($slides[first]).css(opts.cssFirst);if(opts.timeout){opts.timeout=parseInt(opts.timeout);if(opts.speed.constructor==String){opts.speed=$.fx.speeds[opts.speed]||parseInt(opts.speed);}if(!opts.sync){opts.speed=opts.speed/2;}var buffer=opts.fx=="none"?0:opts.fx=="shuffle"?500:250;while((opts.timeout-opts.speed)<buffer){opts.timeout+=opts.speed;}}if(opts.easing){opts.easeIn=opts.easeOut=opts.easing;}if(!opts.speedIn){opts.speedIn=opts.speed;}if(!opts.speedOut){opts.speedOut=opts.speed;}opts.slideCount=els.length;opts.currSlide=opts.lastSlide=first;if(opts.random){if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{if(opts.backwards){opts.nextSlide=opts.startingSlide==0?(els.length-1):opts.startingSlide-1;}else{opts.nextSlide=opts.startingSlide>=(els.length-1)?0:opts.startingSlide+1;}}if(!opts.multiFx){var init=$.fn.cycle.transitions[opts.fx];if($.isFunction(init)){init($cont,$slides,opts);}else{if(opts.fx!="custom"&&!opts.multiFx){log("unknown transition: "+opts.fx,"; slideshow terminating");return false;}}}var e0=$slides[first];if(opts.before.length){opts.before[0].apply(e0,[e0,e0,opts,true]);}if(opts.after.length){opts.after[0].apply(e0,[e0,e0,opts,true]);}if(opts.next){$(opts.next).bind(opts.prevNextEvent,function(){return advance(opts,1);});}if(opts.prev){$(opts.prev).bind(opts.prevNextEvent,function(){return advance(opts,0);});}if(opts.pager||opts.pagerAnchorBuilder){buildPager(els,opts);}exposeAddSlide(opts,els);return opts;}function saveOriginalOpts(opts){opts.original={before:[],after:[]};opts.original.cssBefore=$.extend({},opts.cssBefore);opts.original.cssAfter=$.extend({},opts.cssAfter);opts.original.animIn=$.extend({},opts.animIn);opts.original.animOut=$.extend({},opts.animOut);$.each(opts.before,function(){opts.original.before.push(this);});$.each(opts.after,function(){opts.original.after.push(this);});}function supportMultiTransitions(opts){var i,tx,txs=$.fn.cycle.transitions;if(opts.fx.indexOf(",")>0){opts.multiFx=true;opts.fxs=opts.fx.replace(/\s*/g,"").split(",");for(i=0;i<opts.fxs.length;i++){var fx=opts.fxs[i];tx=txs[fx];if(!tx||!txs.hasOwnProperty(fx)||!$.isFunction(tx)){log("discarding unknown transition: ",fx);opts.fxs.splice(i,1);i--;}}if(!opts.fxs.length){log("No valid transitions named; slideshow terminating.");return false;}}else{if(opts.fx=="all"){opts.multiFx=true;opts.fxs=[];for(p in txs){tx=txs[p];if(txs.hasOwnProperty(p)&&$.isFunction(tx)){opts.fxs.push(p);}}}}if(opts.multiFx&&opts.randomizeEffects){var r1=Math.floor(Math.random()*20)+30;for(i=0;i<r1;i++){var r2=Math.floor(Math.random()*opts.fxs.length);opts.fxs.push(opts.fxs.splice(r2,1)[0]);}debug("randomized fx sequence: ",opts.fxs);}return true;}function exposeAddSlide(opts,els){opts.addSlide=function(newSlide,prepend){var $s=$(newSlide),s=$s[0];if(!opts.autostopCount){opts.countdown++;}els[prepend?"unshift":"push"](s);if(opts.els){opts.els[prepend?"unshift":"push"](s);}opts.slideCount=els.length;$s.css("position","absolute");$s[prepend?"prependTo":"appendTo"](opts.$cont);if(prepend){opts.currSlide++;opts.nextSlide++;}if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($s);}if(opts.fit&&opts.width){$s.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$s.height(opts.height);}s.cycleH=(opts.fit&&opts.height)?opts.height:$s.height();s.cycleW=(opts.fit&&opts.width)?opts.width:$s.width();$s.css(opts.cssBefore);if(opts.pager||opts.pagerAnchorBuilder){$.fn.cycle.createPagerAnchor(els.length-1,s,$(opts.pager),els,opts);}if($.isFunction(opts.onAddSlide)){opts.onAddSlide($s);}else{$s.hide();}};}$.fn.cycle.resetState=function(opts,fx){fx=fx||opts.fx;opts.before=[];opts.after=[];opts.cssBefore=$.extend({},opts.original.cssBefore);opts.cssAfter=$.extend({},opts.original.cssAfter);opts.animIn=$.extend({},opts.original.animIn);opts.animOut=$.extend({},opts.original.animOut);opts.fxFn=null;$.each(opts.original.before,function(){opts.before.push(this);});$.each(opts.original.after,function(){opts.after.push(this);});var init=$.fn.cycle.transitions[fx];if($.isFunction(init)){init(opts.$cont,$(opts.elements),opts);}};function go(els,opts,manual,fwd){if(manual&&opts.busy&&opts.manualTrump){debug("manualTrump in go(), stopping active transition");$(els).stop(true,true);opts.busy=0;}if(opts.busy){debug("transition active, ignoring new tx request");return;}var p=opts.$cont[0],curr=els[opts.currSlide],next=els[opts.nextSlide];if(p.cycleStop!=opts.stopCount||p.cycleTimeout===0&&!manual){return;}if(!manual&&!p.cyclePause&&!opts.bounce&&((opts.autostop&&(--opts.countdown<=0))||(opts.nowrap&&!opts.random&&opts.nextSlide<opts.currSlide))){if(opts.end){opts.end(opts);}return;}var changed=false;if((manual||!p.cyclePause)&&(opts.nextSlide!=opts.currSlide)){changed=true;var fx=opts.fx;curr.cycleH=curr.cycleH||$(curr).height();curr.cycleW=curr.cycleW||$(curr).width();next.cycleH=next.cycleH||$(next).height();next.cycleW=next.cycleW||$(next).width();if(opts.multiFx){if(opts.lastFx==undefined||++opts.lastFx>=opts.fxs.length){opts.lastFx=0;}fx=opts.fxs[opts.lastFx];opts.currFx=fx;}if(opts.oneTimeFx){fx=opts.oneTimeFx;opts.oneTimeFx=null;}$.fn.cycle.resetState(opts,fx);if(opts.before.length){$.each(opts.before,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});}var after=function(){opts.busy=0;$.each(opts.after,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});};debug("tx firing("+fx+"); currSlide: "+opts.currSlide+"; nextSlide: "+opts.nextSlide);opts.busy=1;if(opts.fxFn){opts.fxFn(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}else{if($.isFunction($.fn.cycle[opts.fx])){$.fn.cycle[opts.fx](curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}else{$.fn.cycle.custom(curr,next,opts,after,fwd,manual&&opts.fastOnEvent);}}}if(changed||opts.nextSlide==opts.currSlide){opts.lastSlide=opts.currSlide;if(opts.random){opts.currSlide=opts.nextSlide;if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];if(opts.nextSlide==opts.currSlide){opts.nextSlide=(opts.currSlide==opts.slideCount-1)?0:opts.currSlide+1;}}else{if(opts.backwards){var roll=(opts.nextSlide-1)<0;if(roll&&opts.bounce){opts.backwards=!opts.backwards;opts.nextSlide=1;opts.currSlide=0;}else{opts.nextSlide=roll?(els.length-1):opts.nextSlide-1;opts.currSlide=roll?0:opts.nextSlide+1;}}else{var roll=(opts.nextSlide+1)==els.length;if(roll&&opts.bounce){opts.backwards=!opts.backwards;opts.nextSlide=els.length-2;opts.currSlide=els.length-1;}else{opts.nextSlide=roll?0:opts.nextSlide+1;opts.currSlide=roll?els.length-1:opts.nextSlide-1;}}}}if(changed&&opts.pager){opts.updateActivePagerLink(opts.pager,opts.currSlide,opts.activePagerClass);}var ms=0;if(opts.timeout&&!opts.continuous){ms=getTimeout(els[opts.currSlide],els[opts.nextSlide],opts,fwd);}else{if(opts.continuous&&p.cyclePause){ms=10;}}if(ms>0){p.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.backwards);},ms);}}$.fn.cycle.updateActivePagerLink=function(pager,currSlide,clsName){$(pager).each(function(){$(this).children().removeClass(clsName).eq(currSlide).addClass(clsName);});};function getTimeout(curr,next,opts,fwd){if(opts.timeoutFn){var t=opts.timeoutFn.call(curr,curr,next,opts,fwd);while(opts.fx!="none"&&(t-opts.speed)<250){t+=opts.speed;}debug("calculated timeout: "+t+"; speed: "+opts.speed);if(t!==false){return t;}}return opts.timeout;}$.fn.cycle.next=function(opts){advance(opts,1);};$.fn.cycle.prev=function(opts){advance(opts,0);};function advance(opts,moveForward){var val=moveForward?1:-1;var els=opts.elements;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}if(opts.random&&val<0){opts.randomIndex--;if(--opts.randomIndex==-2){opts.randomIndex=els.length-2;}else{if(opts.randomIndex==-1){opts.randomIndex=els.length-1;}}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{if(opts.random){opts.nextSlide=opts.randomMap[opts.randomIndex];}else{opts.nextSlide=opts.currSlide+val;if(opts.nextSlide<0){if(opts.nowrap){return false;}opts.nextSlide=els.length-1;}else{if(opts.nextSlide>=els.length){if(opts.nowrap){return false;}opts.nextSlide=0;}}}}var cb=opts.onPrevNextEvent||opts.prevNextClick;if($.isFunction(cb)){cb(val>0,opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,moveForward);return false;}function buildPager(els,opts){var $p=$(opts.pager);$.each(els,function(i,o){$.fn.cycle.createPagerAnchor(i,o,$p,els,opts);});opts.updateActivePagerLink(opts.pager,opts.startingSlide,opts.activePagerClass);}$.fn.cycle.createPagerAnchor=function(i,el,$p,els,opts){var a;if($.isFunction(opts.pagerAnchorBuilder)){a=opts.pagerAnchorBuilder(i,el);debug("pagerAnchorBuilder("+i+", el) returned: "+a);}else{a='<a href="#">'+(i+1)+"</a>";}if(!a){return;}var $a=$(a);if($a.parents("body").length===0){var arr=[];if($p.length>1){$p.each(function(){var $clone=$a.clone(true);$(this).append($clone);arr.push($clone[0]);});$a=$(arr);}else{$a.appendTo($p);}}opts.pagerAnchors=opts.pagerAnchors||[];opts.pagerAnchors.push($a);$a.bind(opts.pagerEvent,function(e){e.preventDefault();opts.nextSlide=i;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}var cb=opts.onPagerEvent||opts.pagerClick;if($.isFunction(cb)){cb(opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,opts.currSlide<i);});if(!/^click/.test(opts.pagerEvent)&&!opts.allowPagerClickBubble){$a.bind("click.cycle",function(){return false;});}if(opts.pauseOnPagerHover){$a.hover(function(){opts.$cont[0].cyclePause++;},function(){opts.$cont[0].cyclePause--;});}};$.fn.cycle.hopsFromLast=function(opts,fwd){var hops,l=opts.lastSlide,c=opts.currSlide;if(fwd){hops=c>l?c-l:opts.slideCount-l;}else{hops=c<l?l-c:l+opts.slideCount-c;}return hops;};function clearTypeFix($slides){debug("applying clearType background-color hack");function hex(s){s=parseInt(s).toString(16);return s.length<2?"0"+s:s;}function getBg(e){for(;e&&e.nodeName.toLowerCase()!="html";e=e.parentNode){var v=$.css(e,"background-color");if(v&&v.indexOf("rgb")>=0){var rgb=v.match(/\d+/g);return"#"+hex(rgb[0])+hex(rgb[1])+hex(rgb[2]);}if(v&&v!="transparent"){return v;}}return"#ffffff";}$slides.each(function(){$(this).css("background-color",getBg(this));});}$.fn.cycle.commonReset=function(curr,next,opts,w,h,rev){$(opts.elements).not(curr).hide();if(typeof opts.cssBefore.opacity=="undefined"){opts.cssBefore.opacity=1;}opts.cssBefore.display="block";if(opts.slideResize&&w!==false&&next.cycleW>0){opts.cssBefore.width=next.cycleW;}if(opts.slideResize&&h!==false&&next.cycleH>0){opts.cssBefore.height=next.cycleH;}opts.cssAfter=opts.cssAfter||{};opts.cssAfter.display="none";$(curr).css("zIndex",opts.slideCount+(rev===true?1:0));$(next).css("zIndex",opts.slideCount+(rev===true?0:1));};$.fn.cycle.custom=function(curr,next,opts,cb,fwd,speedOverride){var $l=$(curr),$n=$(next);var speedIn=opts.speedIn,speedOut=opts.speedOut,easeIn=opts.easeIn,easeOut=opts.easeOut;$n.css(opts.cssBefore);if(speedOverride){if(typeof speedOverride=="number"){speedIn=speedOut=speedOverride;}else{speedIn=speedOut=1;}easeIn=easeOut=null;}var fn=function(){$n.animate(opts.animIn,speedIn,easeIn,function(){cb();});};$l.animate(opts.animOut,speedOut,easeOut,function(){$l.css(opts.cssAfter);if(!opts.sync){fn();}});if(opts.sync){fn();}};$.fn.cycle.transitions={fade:function($cont,$slides,opts){$slides.not(":eq("+opts.currSlide+")").css("opacity",0);opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.cssBefore.opacity=0;});opts.animIn={opacity:1};opts.animOut={opacity:0};opts.cssBefore={top:0,left:0};}};$.fn.cycle.ver=function(){return ver;};$.fn.cycle.defaults={activePagerClass:"activeSlide",after:null,allowPagerClickBubble:false,animIn:null,animOut:null,autostop:0,autostopCount:0,backwards:false,before:null,cleartype:!$.support.opacity,cleartypeNoBg:false,containerResize:1,continuous:0,cssAfter:null,cssBefore:null,delay:0,easeIn:null,easeOut:null,easing:null,end:null,fastOnEvent:0,fit:0,fx:"fade",fxFn:null,height:"auto",manualTrump:true,next:null,nowrap:0,onPagerEvent:null,onPrevNextEvent:null,pager:null,pagerAnchorBuilder:null,pagerEvent:"click.cycle",pause:0,pauseOnPagerHover:0,prev:null,prevNextEvent:"click.cycle",random:0,randomizeEffects:1,requeueOnImageNotLoaded:true,requeueTimeout:250,rev:0,shuffle:null,slideExpr:null,slideResize:1,speed:1000,speedIn:null,speedOut:null,startingSlide:0,sync:1,timeout:4000,timeoutFn:null,updateActivePagerLink:null};})(jQuery);

//Google Maps
(function($){  
	$.fn.gmaps = function(options) 
	{  
  
		var  
		  defaults = 
		  {  
			location: 'Guadalajara, Jalisco, Mexico', //Ubicacion por default del mapa
			Icon:     '', //Icono del marcador en el mapa
			zoom:     8, //Nivel de acercamiento del mapa
			MapType:  'ROADMAP', //Tipo de mapa por default(ROADMAP, SATELLITE, HYBRID, TERRAIN)
			latlng:   [0,0], //latitud y longitud por default(none)
			width:    '200px', //ancho del div que contiene el mapa
			height:   '200px', //alto del div que contiene el mapa
			center:   '',//creacion de objeto lat
			mode:     'normal',
			message:  'indefinido'// (normal: latitude,longitud) (geocoder: codificacion greografica)
		  },  
		  settings = $.extend({}, defaults, options);  
		
		 this.each(function() 
		 {
		   var $this = $(this);
		     
		   // Verifica que el elemento sea un div
		   if($this.is('div'))
		   {	
					//Establece el tipo de mapa a mostrar
					var mapTypIdSet = google.maps.MapTypeId.ROADMAP;
					
					switch(settings.MapType.toLowerCase())
					{
						case "roadmap":
							var mapTypIdSet = google.maps.MapTypeId.ROADMAP; 
							break;
						case "satellite":
							var mapTypIdSet = google.maps.MapTypeId.SATELLITE; 
							break;
						case "hybrid":
							var mapTypIdSet = google.maps.MapTypeId.HYBRID; 
							break;
						case "terrain":
							var mapTypIdSet = google.maps.MapTypeId.TERRAIN; 
							break;
						default:
							var mapTypIdSet = google.maps.MapTypeId.ROADMAP; 
							break;
					}
					
					//Si latlng ha sido inicializado establece la ubicacion del mapa
					if(settings.mode.toLowerCase() == 'normal')
					{
						if(settings.latlng[0] != 0 && settings.latlng[1] != 0)
						{
							var latlng = new google.maps.LatLng(settings.latlng[0],settings.latlng[1]);
						
							var myOptions = {
							  zoom: settings.zoom,
							  center: latlng,
							  mapTypeId: mapTypIdSet,
	  						  disableDefaultUI: true

							};
						}
						else
						{
							alert('Debes especificar la latitud y longitud para este modo(normal)');
						}
						
						
						map = new google.maps.Map(document.getElementById($this.attr('id')), myOptions);
						
						var latlng = new google.maps.LatLng(settings.latlng[0],settings.latlng[1]);
						
						var marker = new google.maps.Marker({
							  map: map, 
							  position: latlng,
							  title: 'OC Industrial'
						});
						
						var infoWindow = new google.maps.InfoWindow({
							content : settings.message
					  });
					  
					  infoWindow.open(map,marker);
					  
					  google.maps.event.addListener(marker, 'click', function(){
						infoWindow.open(map,marker);
					  });
						

					}
					else if(settings.mode.toLowerCase() == 'geocoder')
					{
						var geocoder;
						var map;
						geocoder = new google.maps.Geocoder();
						
						//var latlng = new google.maps.LatLng(-34.397, 150.644);
						var myOptions = {
						  zoom: settings.zoom,
						  mapTypeId: mapTypIdSet,
						  disableDefaultUI: true
						}
						map = new google.maps.Map(document.getElementById($this.attr('id')), myOptions);
						
						if (geocoder) 
						{
						  geocoder.geocode( { 'address': settings.location}, function(results, status) {
							if (status == google.maps.GeocoderStatus.OK) {
							  map.setCenter(results[0].geometry.location);
							  
							  var infoWindow = new google.maps.InfoWindow({
									content : settings.message
							  });
							  
							  var marker = new google.maps.Marker({
								  map: map, 
								  position: results[0].geometry.location,//,
								  //icon : 'url',
								  title: 'OC Industrial'
							  });
							  
							  infoWindow.open(map,marker);
							  
							  google.maps.event.addListener(marker, 'click', function(){
								infoWindow.open(map,marker);
							  });
							  
							} else {
							  alert("Geocode was not successful for the following reason: " + status);
							}
						  });
						}
					}
					else
					{
						alert('El parametro mode es invalido');
					}
					
					$this.css({
						width: settings.width,
						height: settings.height
					});
			}
		 });   
		 
		 // returns the jQuery object to allow for chainability.  
		 return this;  
   }  
})(jQuery);

// FUNCIÓN QUE VALIDA UN 'email'
//
// @param  string
// @return boolean
function valid_email(string)
{
    return (/^([a-z0-9\+\-\_]+)(\.[a-z0-9\+\-\_]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i).test(string) ? true : false;
}

// Redimensiona la imagen identificada por su instancia
//
//	@params Object
//	@return void
//
function redimensiona_imagen(obj, container)
{
	//Ancho y alto deseados
	var $this = obj;
	var width = $this.width()+'px',
		height = $this.height()+'px';
	
	//Contenedor a redimensionar
	container.css({
		width: width,
		height: height
	});
	
	$('#slides > img').css({
		width: $(window).width()+'px',
		height :$(window).height()+'px'
	});
	
	if(document.getElementById('image-container'))
	{
		$('#image-container > img').css({
			width: $(window).width()+'px',
			height :$(window).height()+'px'
		});
		
		$('#image-container').css({
			width: $(window).width()+'px',
			height :$(window).height()+'px'
		});
		
		
	}
	
	if(document.getElementById('obras-container'))
	{
		var ancho_total = $('#obras-container').width();
		var ancho_subtotal = ancho_total - 88;
		var ancho_imagenes = $('#obras-container > div > div').width();
		
		//Numero de imagenes mostrandose
		var imagenes_mostrandose = parseInt(ancho_subtotal / 49);
		
		//Tamanho real de las imagenes que se estan mostrando
		var ancho_imagenes_real = imagenes_mostrandose * 49;
		
		
		
		if(ancho_imagenes >= ancho_total)
		{
			$('#obras-container > div > div').width(ancho_imagenes_real + 88);
			
			//Establece el nuevo ancho para el contenedor de las imagenes
			$('#obras-container > div > div').width(ancho_imagenes_real);
			
		}
		else
		{
			$('#obras-container').width(ancho_imagenes_real+88);
			$('#obras-container > div > div').width(ancho_imagenes_real);
		}
		
		var total_imagenes_ancho = ($('#obras-container > div > div > img').length * 49);
		
		//el numero de imagenes multiplicado por 49 es mayor que el ancho del div div se muestran botones
		if(total_imagenes_ancho >= $('#obras-container > div > div').width())
		{
			$('#show-more-photos').show();
			$('#show-less-photos').show();
		}
		else
		{
			$('#show-more-photos').hide();
			$('#show-less-photos').hide();
		}
		
	}
	
	//Redimensiona el div que contiene la informacion
	if(document.getElementById('resize-ajax-container'))
	{
		
		var alto_max			= parseInt(height);
		var alto_max_per		= 100;
		var alto_margen			= parseInt($('#resize-ajax-container').css('margin-top'));
		var alto_margen_per		= parseInt((alto_margen * alto_max_per) / alto_max);
		var alto_estimado_per	= alto_max_per - alto_margen_per - 6;
		
		$('#resize-ajax-container').css('height',alto_estimado_per+'%');
		$('#ml-info-container').height('height','100%');
		
	}
}

// Muestra 'n pixeles' hacia arriba en un div con overflow hidden
//
//	@params Object
//	@return void
//
function show_more_info()
{
	document.getElementById('ml-info-container').scrollTop += 20;
	return false;
}

// Muestra 'n pixeles' hacia abajo en un div con overflow hidden
//
//	@params Object
//	@return void
//
function show_less_info()
{
	document.getElementById('ml-info-container').scrollTop -= 20;
	return false;
}

// Capitaliza la primera letra de una cadena
//
//	@params String
//	@return String
//
function capitaliza(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}

function show_less_photos()
{
	document.getElementById('bla').scrollTop -= 40;
}

function show_more_photos()
{
	document.getElementById('bla').scrollTop += 40;
}

var yaoming = false;

// Carga la seccion indicada por el objeto
//
//	@params Object
//	@return void
//
function carga_seccion($this)
{
	//	1.Verifica si el contenedor ajax ya existe
	//		1.a si ya existe
	//			-desliza el contenedor hacia la izquierda
	//			-remueve el contenedor
	//		1.b Si no existe
	//			-Carga el contenido solicitado
	//			-Crea el nuevo contenedor y crea sus estilos
	//			-desplaza el contenedor hacia la derecha
	
	//Si no esta ninguna seccion en animacion, se carga el contenido
	if( ! $('#ajax_container').is(':animated') || ! $('#obras-container').is(':animated'))
	{
	
	
	//Nombre de la seccion a cargar
	var last_segment	= parseInt($this.attr('href').lastIndexOf('/')+1);
	var seccion			= $this.attr('href').substr(last_segment,parseInt($this.attr('href').length));
	var ajax_container	= 'ajax_container';
	var show = true;
	var exist_ajax_container = (document.getElementById(ajax_container)) ? true : false;
	
	//Verifica si la seccion ya se esta mostrando
	if( exist_ajax_container && $('#'+ajax_container).hasClass(seccion))
	{
		//la seccion no se muestra
		show = false;
	}

    if(seccion != 'clientes')
    {
        $('#customers-logos').fadeOut('normal');
    }
	
	
	//Se carga la nueva seccion a mostrar
	if( show && seccion != 'obras')
	{
		
		//Si la seccion obras se esta visualizando la elimino
		if(document.getElementById('obras-container'))
		{
			var ancho_obras = $('#obras-container').width();
			
			$('#obras-container').animate({
				//width: '-='+ancho_obras,
				left: '-='+(ancho_obras+260),
				opacity: '+=1'
				}, 1200, function(){
					$(this).remove();
			});
		}
		
		if(document.getElementById('image-container'))
		{
			$('#image-container').fadeOut('normal', function(){
				$(this).remove();
			});
		}
		
		//Muestra el cargador
		$('#ajax-loader').remove();
		$('<div id="ajax-loader"></div>').appendTo('body').fadeIn('normal');
		
		//Si existe el contenedor ajax se desplaza a la izquierda
		if( exist_ajax_container)
		{
			if($('#ajax_container').css('left') == '-360px')
			{
				$('#'+ajax_container+' > div').hide();
			}
			else
			{
				$('#'+ajax_container+' > div').hide();
				
				var ancho_seccion	= $('#'+ajax_container).width();
				
				$('#'+ajax_container).animate({
					left: '-=620',
					opacity: '+=1'
					}, 1200, function(){
				});
			}
		}
		
		if( ! exist_ajax_container )
		{
			//Se crea el div de ajax
			var contenedor		= '<div id="'+ajax_container+'"></div>';
			$(contenedor).appendTo('body').hide().css('left','-360px');
		}
		
		//Establece la nueva clase de la seccion al contenedor ajax
		$('#'+ajax_container).attr('class',seccion);
		
		$('#titulo-seccion').hide();
		
		//Realiza la peticion del nuevo contenido
		$.ajax({
			url			: 'site/'+seccion,
			type		: 'post',
			dataType	: 'text',
			success		: function(data)
			{
				//Establece el nuevo titulo de la seccion a mostrar
				$('#titulo-seccion').attr('class','titulo-'+seccion);
				$('#titulo-seccion').fadeIn('slow');
				
				//Establece el nuevo titulo en el navegador
				$('title').text('OC Industrial - '+capitaliza(seccion));
				
				//Carga el nuevo contenido
				$('#'+ajax_container).html(data);
				
				$('#'+ajax_container+' > div').hide();
				
				$('#'+ajax_container).fadeIn('fast');
		
				//Nuevo ancho del contenedor ajax
				var ancho_seccion	= $('#'+ajax_container+'.'+seccion).width();
				
				if(exist_ajax_container)
				{
					if($('#'+ajax_container+'.'+seccion).css('left') == '-360px')
					{
						//no hace nada
					}
					else
					{
						$('#'+ajax_container+'.'+seccion).css('left','-260px');
					}
				}
				
				//Desliza el contenedor principal
				$('#'+ajax_container).animate({
						left: '+=620',
						opacity: '+=1'
					}, 1200, function(){
						$('#'+ajax_container+' > div').show();
						
						if(seccion == 'nosotros' || seccion == 'clientes' || seccion == 'servicios' || seccion == 'contacto')
						{

                            
							//JSCROLLPANE
							var settings = {
							showArrows: true,
								autoReinitialise: true
							};
							var pane = $('.scroll-pane')
							pane.jScrollPane(settings);
							var contentPane = pane.data('jsp').getContentPane();

                            if(seccion == 'clientes')
                            {
                                $('#customers-logos').css('left', 'auto').fadeIn('normal');

                                if(!yaoming)
                                {
                                    initImage($('#cust1'));
                                    initImage($('#cust2'));
                                    initImage($('#cust3'));
                                    initImage($('#cust4'));
                                    initImage($('#cust5'));
                                    initImage($('#cust6'));
                                    initImage($('#cust7'));
                                    initImage($('#cust8'));
                                    initImage($('#cust9'));
                                    initImage($('#cust10'));
                                    yaoming = true;
                                }
                            }
                            
						}
								
						//Si es contacto se carga el mapa de google maps
						if( seccion == 'contacto')
						{
							//Muestra el mapa
							carga_mapa();
						}
						else
						{
							$('#mapa').fadeOut('slow',function(){
								$(this).remove();
							});
						}
                        //Muestra la layenda
                        $('#welcome-container').fadeIn('slow');
						
				});
			},
			error		: function()
			{
			},
			complete	: function()
			{
				$('<a href="#" title="" id="close-section"></a>').appendTo('#'+ajax_container).show();
				
				//Elimina el cargador
				$('#ajax-loader').fadeOut('normal',function(){
					$(this).remove();
				});
				
					redimensiona_imagen($(window),$('#slides'));
			}
		});
		
	}
	else if(seccion == 'obras' && ! document.getElementById('obras-container'))
	{
		//Elimina lo que se esta mostrando
		if( exist_ajax_container)
		{
			$('#'+ajax_container+' > div').hide();
			
			
			
			var ancho_seccion	= $('#'+ajax_container).width();
			
			$('#'+ajax_container).animate({
				left: '-=620',
				opacity: '+=1'
				}, 1200, function(){
					
			});
			
		}
		
		//Elimina el mapa
		$('#mapa').fadeOut('normal',function(){
			$(this).remove();
		});
		
		if( ! document.getElementById('obras-container') )
		{
			//Muestra el cargador
			$('#ajax-loader').remove();
			$('<div id="ajax-loader"></div>').appendTo('body').fadeIn('normal');
			
			//Crea el contenedor de obras 88
			var contenedor_obras		= '<div id="obras-container"></div>';
			
			var ancho_obras = (parseInt($(document).width()) - 260);
			
			$(contenedor_obras).appendTo('body')
				.css({
					width: ancho_obras+'px'
				})
				.hide();
					
					//Carga el contenido
					$.ajax({
						url			: 'site/'+seccion,
						type		: 'post',
						dataType	: 'text',
						success		: function(data)
						{
							if(data != '')
							{
								//Establece el nuevo titulo de la seccion a mostrar
								$('#titulo-seccion').attr('class','titulo-'+seccion);
								$('#titulo-seccion').fadeIn('slow');
								
								//Establece el nuevo titulo en el navegador
								$('title').text('OC Industrial - Obras');
								
								
								
								$('#obras-container').html(data);
								
								$('#obras-container').fadeIn('normal');
								
								var ancho_total = $('#obras-container').width();
								var ancho_subtotal = ancho_total - 88;
								var ancho_imagenes = $('#obras-container > div > div').width();
								
								
								var imagenes_mostrandose = parseInt(ancho_subtotal / 49);
								
								
								//Tamanho real de las imagenes que se estan mostrando
								var ancho_imagenes_real = imagenes_mostrandose * 49;
								
								
								if(ancho_imagenes >= ancho_total)
								{
									$('#obras-container > div > div').width(ancho_imagenes_real + 88);
									
									//Establece el nuevo ancho para el contenedor de las imagenes
									$('#obras-container > div > div').width(ancho_imagenes_real);
									
								}
								else
								{
									$('#obras-container').width(ancho_total);
									$('#obras-container > div > div').width(ancho_imagenes_real);
								}
								
								var total_imagenes_ancho = ($('#obras-container > div > div > img').length * 49);
								
								
								//el numero de imagenes multiplicado por 49 es mayor que el ancho del div div se muestran botones
								if(total_imagenes_ancho >= $('#obras-container > div > div').width())
								{
									$('#show-more-photos').show();
									$('#show-less-photos').show();
								}
								else
								{
									$('#show-more-photos').hide();
									$('#show-less-photos').hide();
								}
								
								$('#obras-container').css('left','-'+( ancho_obras )+'px')
								
								$('#obras-container').animate({
										left: '+='+(260+ancho_obras)
									}, 1200, function(){
                                       //Muestra la layenda
                                         $('#welcome-container').fadeIn('slow');
								});
								
							}
						},
						error		: function()
						{
							alert('Error en el servidor, intenta de nuevo !');
						},
						complete	: function()
						{
							$('#ajax-loader').remove();
							
						}
					});
					
			
		}
		
		
		
	}

	}
}


$(function(){
	
	
	//Llama al slider principal al cargar completamente la pagina
	$(window).load(function(){
		$('#slides').cycle({ 
			fx:    'fade', 
			speed:  7000,
			slideResize: 0
		});
		
	});
	
	//Redimensiona la imagen al cargar la pagina
	$(document).load(function(){
		redimensiona_imagen($(this),$('#slides'));
	});
	
	//Redimensiona la imagen al redimensionar la pagina
	$(window).resize(function(){
		redimensiona_imagen($(window),$('#slides'));
		
		//Si existe la seccion de obras tambien se redimensiona
		if(document.getElementById('obras-container'))
		{
			var ancho_obras = (parseInt($(window).width()) - 260)+'px';
			
			$('#obras-container').css({
				width: ancho_obras
			});
		}
		
	});
	
	
	//Activa el desplazamiento solo una vez
	$('a.animate-container').live('click', function(){
		
		if( ! $('#container').is(':animated') )
		{
			var $this = $(this);
			
			var fue_animado = $('#logo-principal a').attr('rel');
			
			if(fue_animado == 'false')
			{
				//Desliza el contenedor principal
				$('#container').animate({
					left: '-=310'
					}, 1200, function(){
						$('#logo-principal a').attr('rel','true');
				});
						
				//Desliza el logotipo
				$('#logo-principal').animate({
						left: '-=310'
					}, 1200, function(){
					
						$('#logo-principal a').attr('rel','true');
						
                        //Muestra la layenda
                        $('#welcome-container').fadeIn('slow');

						//Carga el nuevo logo
						$('<img id="logo-small" src="images/logo-oc-small.png" alt="" />')
							.appendTo($('#container'))
							.css({
								left: '310px',
								bottom: '0px'
							})
							.hide()
							.fadeIn('normal');
						}
				);
				
				//Desliza los logotipo del cliente
				$('#customers-logos').animate({
						left: '-=310'
					}, 1200
				);
			}
			
			if($this.hasClass('i-m'))
			{
				//Cambia a todas las opciones del menu el angulo de la flecha
				$('img.im-rotate').rotate({ angle: 90 });
				$('img.im-rotate').removeClass('im-active');
				
				//Cambio el angulo de la flecha en el menu
				$this.find('img.im-rotate').addClass('im-active');
				$this.find('img.im-rotate').rotate({ angle: 0 });
						
				//Carga el contenido deseado y lo muestra
				carga_seccion($this);
				
			}
		}
		return false;
	});
	
	//Rota las flechas del menu en 90 grados
	$("img.im-rotate").rotate({ angle:90 });
	
	
	//Mouseover / Mouseout
	$('.i-m').hover(function(){
		$(this).find('img.im-rotate').rotate({ angle:90, animateTo: 0, duration: 400 });
	}, function(){
		if( ! $(this).find('img.im-rotate').hasClass('im-active'))
		{
			$(this).find('img.im-rotate').rotate({ angle:0, animateTo:90, duration: 100 });
		}
	});
	
	//Cierra la seccion que se esta mostrando
	$('#close-section').live('click', function(){
        //Esconde los logos
        $('#customers-logos').fadeOut('normal');

		var ancho_seccion	= $('#ajax_container').width();
		
		$('#ajax_container > div').html('');
		$('#ajax_container').attr('class','');
		
		$('#ajax_container').animate({
			//width: '-='+ancho_seccion,
			left: '-=620',
			opacity: '+=1'
			}, 1200, function(){
				$(this).remove();
				
				//Establece el nuevo titulo en el navegador
				$('title').text('OC Industrial - Inicio');
				
				//Elimina el mapa
				$('#mapa').fadeOut('slow',function(){
						$(this).remove();
				});
		});
		
		return false;
	});
	
	
	$('body').keydown(function(e){
		switch(e.keyCode)
		{
			case 38:
				document.getElementById('ml-info-container').scrollTop -= 20;
				break;
			case 40:
				document.getElementById('ml-info-container').scrollTop += 20;
				break;
		}
	});
	
	//Envia los datos del formulario por correo electronico
	$('#enviar').live('click', function(e)
	{
		var nombre      = $('#nombre').val();
		var email       = $('#email').val();
		var telefono    = $('#telefono').val();
		var comentarios = $('#comentarios').val();
		
		if(!(/^[a-záéíóúñ\s]{3,40}$/i).test(nombre))
		{
			$('#error-msj').html('verifica el nombre proporcionado!');
			return false;
		}
		
		if(!(/^([a-z0-9\+\-\_]+)(\.[a-z0-9\+\-\_]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/i).test(email))
		{
			$('#error-msj').html('verifica el e-mail proporcionado!');
			return false;
		}
		
		if(! (/^([^a-z]+)$/i).test(telefono))
		{
			$('#error-msj').html('verifica el tel\u00e9fono proporcionado!');
			return false;
		}
		
		if(!(/^([a-z0-9áéíóúñÁÉÍÓÚÑ\s\.\-\_\(\)\#\/\,\;\'])+$/i).test(comentarios))
		{
			$('#error-msj').html('verifica los comentarios proporcionados!');
			return false;
		}
		
		//Realiza la peticion del nuevo contenido
		$.ajax({
			url			: 'site/send_mail',
			type		: 'post',
			dataType	: 'text',
			data        : $('form').serialize(),
			success		: function(res)
			{
				if(res.toLowerCase() == 'error')
				{
					$('#error-msj').html('se produjo un error al enviar el mensaje, por favor intenta de nuevo!');
				}
				else
				{
					$('#error-msj').html('tu mensaje se ha enviado con \u00e9xito!');
				}
			}
		});
		
		e.preventDefault();
	});
	
	
	//Cierra las obras
	$('#close-obras').live('click', function(e){
		
		//Si la seccion obras se esta visualizando la elimino
		if(document.getElementById('obras-container'))
		{
			var ancho_obras = $('#obras-container').width();
			
			$('#obras-container').animate({
				left: '-='+(ancho_obras+260),
				opacity: '+=1'
				}, 1200, function(){
					$(this).remove();
			});
		}
		
		if(document.getElementById('image-container'))
		{
			$('#image-container').fadeOut('normal', function(){
				$(this).remove();
			});
		}
		e.preventDefault();
	});
	
	//Carga la imagen de obra
	$('#obras-container > div > div > a > img').live('click', function(e){
		var imagen = $(this).attr('alt');
		
		$('#image-container').remove();
		$('<div id="image-container"><img src="cms/uploads/obras/'+imagen+'" alt="" width="'+$(document).width()+'px" height="'+$(document).height()+'px" /></div>')
			.appendTo('body')
			.hide()
			
		$('#image-container')
			.css({
				width: $(window).width()+'px',
				height: $(window).height()+'px'
			})
			.fadeIn('normal');
		$(window).trigger('resize');
		e.preventDefault();
	});
	
});

var paircount = 0;

function initImage(obj)
{
	obj.onload = null;
	var $newthis = $(obj);
	if ($.browser.msie)
	{
		$newthis = $newthis.desaturateImgFix();
	}
	
	$newthis.addClass("pair_" + ++paircount);
	var $cloned = $newthis.clone().attr('id', '');
	$cloned.get(0).onload = null;
	$cloned.insertAfter($newthis).addClass("color").hide();
	$newthis = $newthis.desaturate();
	$newthis.bind("mouseenter mouseleave", desevent);
	$cloned.bind("mouseenter mouseleave", desevent);
};

function desevent(event) 
{
	var classString = new String($(this).attr('class'));
	var pair = classString.match(/pair_\d+/);
	
	$("."+pair).hide();
	if (event.type == 'mouseenter')
		$("."+pair).filter(".color").show();
	if (event.type == 'mouseleave')
		$("."+pair).filter(":not(.color)").show();
}
