COOKIE_NAME = 'komarov';
WINDOWX=400
WINDOWY=57 // default position

COL_pink='255,220,227'
COL_gray='197,193,194'
//COL_gray='100,100,100'
CurrentBG='pink'
SHOW_mode=''
isIE=(navigator.userAgent.indexOf("MSIE")!=-1)
isIE6=(navigator.userAgent.indexOf("MSIE 6")!=-1)
DELAYTIMER_resize=0 // delay for resizing 

// -----------------------------------------------------------------------------------------------------------------------
// START EVERYTHING !
// -----------------------------------------------------------------------------------------------------------------------

$(function() {
	
	flashvideoID = Math.round(Math.random()* new Date().getTime());
	flashProxy2 = new FlashProxy(flashvideoID, "_INCL/JavaScriptFlashGateway.swf");

	checkCookie()
	loadBackground()
});


// -----------------------------------------------------------------------------------------------------------------------
// VIDEO FUNCTIONS 
// -----------------------------------------------------------------------------------------------------------------------

function writeVideo(id) {
	// prepares the HTML for flash video
	
	if (SHOW_mode=='text') {
		return // already clicked in text
	}
	if (id==3) {
		// see you in disneyland 4:3
		var VID_DIM=new Array(404,304+20)
		
	} else {
		// all other movies
		var VID_DIM=new Array(540,304+20)
		
	}
	if (id!=4 && id!=1) {
		var vid = new FlashTag("_INCL/videoplayer.swf?moviename="+movieNAMES[id], VID_DIM[0], VID_DIM[1], "9,0,0,0");
	} else {
		// capital & estate
		var vid = new FlashTag("_INCL/videoplayer_streamer2.swf?m="+movieNAMES[id]+"&d="+IS_ONLINE, VID_DIM[0], VID_DIM[1], "9,0,0,0");
	}
	
	vid.setFlashvars("lcId2=" + flashvideoID);
	setTimeout("startVideo('"+vid+"')", 500)	
}

function startVideo(vid) {
	// writes flash code to video div	
	$('#videoContainer').html(vid)
	SHOW_mode=''
}

function killVideo() {
	// stops the video -> call to flash proxy
	// doesn't work in IE, anyways not necessary it seems
	// flashProxy2.call("killVideo");
	// return false
}

function showMovie(id) {
	
	$('#BGGRAY').css('display', 'block')
	$('#videoContainer').html('')
	
	if (id==3) {
		// see you in disneyland 4:3
		$('#POPUP').css({'display':'block', 'left': (parseInt(WINDOWX)+136)+'px', 'top':WINDOWY+'px', 'width':404+'px'})
		$('#videoContainer').css('width', 404)
		$('#linkContainer').css('width', 404)
	
	} else {
		// all other movies
		$('#POPUP').css({'display':'block', 'left':WINDOWX+'px', 'top':WINDOWY+'px', 'width':540+'px'})
		$('#videoContainer').css('width', 540)
		$('#linkContainer').css('width', 540)
	}
	
	$('#READ_LINK').attr('className', 'mo')
	$('#VIDEO_LINK').attr('className', 'moinv')
	
	if (CurrentBG=='pink') {
		$(document.body).css({'backgroundColor':'rgb('+COL_pink+')'})
		$('#POPUP').css({'backgroundColor':'rgb('+COL_pink+')'})
		$('#POPUP').animate({'backgroundColor':'rgb('+COL_gray+')'},1000)
		$(document.body).animate({'backgroundColor':'rgb('+COL_gray+')'},1000)
	}
	$('#BG').fadeOut(1000, function() { CurrentBG='gray';writeVideo(id) })
	
	
	var temp=''
	if (readtextNAMES[id]!="") {
		
		temp+='<a id="READ_LINK" class="mo" style="margin-right:30px" style="text-decoration:none; color:#0000a4;" onclick="readText('+id+')" href="javascript:void(0)">read text</a>'
		temp+='<a id="VIDEO_LINK"  class="moinv" style="margin-right:30px" style="text-decoration:none; color:#0000a4;" onclick="SHOW_mode=\'\';showMovie('+id+')" href="javascript:void(0)">view video</a>'
	}
	
	temp+='<a class="mo" style="text-decoration:none; color:#0000a4;" onclick="hideMovie()"  href="javascript:void(0)">close</a>'
	
	$('#linkContainer').html(temp)

}

function hideMovie() {
	killVideo()
	SHOW_mode=''
	$('#videoContainer').html('')
	$('#POPUP').css('display', 'none')
	CurrentBG='pink'
	$(document.body).css({'backgroundColor':'rgb('+COL_pink+')'})
	$('#POPUP').css({'backgroundColor':'rgb('+COL_pink+')'})
	$('#BG').fadeIn(1000)
	
}

function fadeAndBack() {
	$('#POPUP').css('display', 'none')
	SHOW_mode=''
	$('#BG').fadeIn(500, function() { self.location.href='index.php' } )
	$(document.body).animate({'backgroundColor':'rgb('+COL_pink+')'},500)
	
}


// -----------------------------------------------------------------------------------------------------------------------
// TEXT FUNCTIONS 
// -----------------------------------------------------------------------------------------------------------------------

function showText(id) {
	
	SHOW_mode='text'
	$('#CONTACT').css('display', 'none')
	$('#POPUP').css({'display':'block', 'left':WINDOWX+'px', 'top':WINDOWY+'px'})
	var temp=''
	temp+='<a class="mo" style="text-decoration:none; color:#0000a4;" onclick="hideMovie()"  href="javascript:void(0)">close</a>'
	$('#linkContainer').html(temp)
	readText(id)
}


function showContact() {
	$('#POPUP').css('display', 'none')
	$('#CONTACT').css({'display':'block', 'left':WINDOWX+'px', 'top':WINDOWY+'px'})
}

function hideContact() {
	SHOW_mode=''
	$('#CONTACT').css('display', 'none')
}

function hideTextAndContact() {
	SHOW_mode=''
	$('#CONTACT').css('display', 'none')
	$('#POPUP').css('display', 'none')
}


function readText(id) {
	
	SHOW_mode='text'
	killVideo()
	$('#videoContainer').html('')
	
	$('#READ_LINK').attr('className', 'moinv')
	$('#VIDEO_LINK').attr('className', 'mo')
	
	var temp=''
	var syid=(id==3) ? "SYID":""
	temp+=	'<div class="TEXTBOX'+syid+' WINB">'
	temp+=	'<div class="holdertextbox'+syid+'">'
	temp+=	'<div id="THE_TEXT" class="scroll-paneA" style="height:auto; width:auto">'
	temp+=	'</div></div></div>'
						
	$('#videoContainer').html(temp)

	$.get('_INCL/'+readtextNAMES[id], function(data) {
		$('#THE_TEXT').html(data)
		$('.holdertextbox'+syid).jScrollPane({scrollbarWidth:9, scrollbarMargin:8})
	});

}


// -----------------------------------------------------------------------------------------------------------------------
// BACKGROUND GENERATION
// -----------------------------------------------------------------------------------------------------------------------


function loadBackground() {
	
	var h=$(window).height()
	var w=$(window).width()

	if (letters.length<1) {
		return
	}
	
	var textsize=60
	var orientation=new Array()
	var angles=new Array()
	var allx=new Array()
	var ally=new Array()
	var yOffsets=new Array()
	var offsetX=new Array()
	var offsetY=new Array()
	
	var y=100+Math.round(Math.random()*(h/(letters.length+2))) 
	var x=0
	var lastx=0
	var lasty=0
	var lastAngle=0
	
	for (var i=0; i<letters.length; i++) {
		
		if (i==0) {
			
			x=Math.round(Math.random()*(w-150))+75 
		
		} else {
			
			for (var cc=0; cc<20; cc++) {
				x=Math.round(Math.random()*(w-150))+75
				if (Math.abs(x-lastx)>60) {
					break
				}
			}
			
			var tempAngle=getAngle(lastx,lasty,x,y)
			var tempAngleDiff=lastAngle-tempAngle
			angles.push(tempAngle)
			
			if ((i==1 && x>lastx) || (i>1 && tempAngleDiff>0)) {
				orientation.push(1)
			} else {
				orientation.push(0)
			}
	
			lastAngle=tempAngle
		
		}
		
		allx.push(x)
		ally.push(y)
		lastx=x
		lasty=y
		yOffsets.push(0)
		y+=Math.round(Math.random()*(h/(letters.length+1)))+50
		y=Math.min(h-100, y)

	}
	
	if (angles[angles.length-1]>90) {
		orientation.push(1)
	} else {
		orientation.push(0)
	}
	
	// check for middle letters if offsets are necessary!
	if (letters.length>2) {
		for (var i=1; i<(letters.length-1); i++) {
			
			var tempAngle1=getAngle(allx[i-1],ally[i-1],allx[i],ally[i])
			var tempAngle2=getAngle(allx[i],ally[i],allx[i+1],ally[i+1])
			var tempDiff=(tempAngle2)-(tempAngle1)
		
			if (Math.abs(tempDiff)<60) {
				
				if ((tempAngle1>tempAngle2 && allx[i]>allx[i+1]) || (tempAngle1<tempAngle2 && allx[i]<allx[i+1])  ) {
					yOffsets[i]=2 // move up
				} else {
					yOffsets[i]=1 // move down
				}
	
			}
		}
	}
	
	// generate offsets
	for (var i=0; i<letters.length; i++) {
		if (yOffsets[i]!=null) {
			
			if (yOffsets[i]==1) {
				// move down
				offsetX.push(10)
				offsetY.push(40) 
				
			} else if (yOffsets[i]==2) {
				// move up
				offsetX.push(5)
				offsetY.push((textsize*-1)+15) 
				
			} else { 
				
				offsetX.push((orientation[i]) ? 40:-5)
				offsetY.push(0)
				
			}
			
		} else {
			
			offsetX.push((orientation[i]) ? 40:-5)
			offsetY.push(0)
		}
		
		// add default offset
		offsetY[offsetY.length-1]+=Math.round(textsize/2)
	}

	// create image map
	var mh='<map id="BGmap" name="BGmap">'
	for (var i=0; i<allx.length; i++) {	
		
		var x1=allx[i]-offsetX[i]-5
		var y1=ally[i]+offsetY[i]-textsize
		var x2=allx[i]-offsetX[i]+35
		var y2=ally[i]+offsetY[i]
		var thelink=(lettersLINKS[i].substr(lettersLINKS[i].length-4)==".php") ? lettersLINKS[i]:"javascript:"+lettersLINKS[i] 
	
		mh+= '<area id="mz'+i+'" shape="rect" coords="'+x1+','+y1+','+x2+','+y2+'" onclick="SHOW_mode=\'\'" href="'+thelink+'">\n'	
	}
	mh+= '</map>'
	$('#MAP_c').html(mh)
	
	// create mouseovers
	for (var i=0; i<allx.length; i++) {	
		
		var x1=allx[i]-offsetX[i]
		var y1=ally[i]+offsetY[i]-textsize
		var ttposX=(x1>(w/2)) ?  x1-232:x1+20
		var ttposY=y1-5-82
		var bgimg=(x1>(w/2)) ? "l":"r"
		var imgTM=(lettersIMGTYPE[i]==0) ? 20:27
		var imgLM=(x1>(w/2)) ?  20:20+13
		
		var temp=	''
		temp+=		'<div id="tt'+i+'" style="position:absolute; z-index:1000; display:none; top:'+ttposY+'px; left:'+ttposX+'px; width:232px; height:82px; background-image:url(_GFX/bubble'+bgimg+'.png)" >'
	
		temp+=		'<img src="_GFX/'+lettersIMG[i]+'" style="margin-top:'+imgTM+'px; margin-left:'+imgLM+'px" />'
		temp+=		'</div>'
		$("body").append(temp);
	
	}
	
	
	// add hover behaviour
	for (var i=0; i<allx.length; i++) {
	
		$("#mz"+i).hover(function() {
			var id=(this.id).replace("mz","")
			if (isIE6) {
				$('#tt'+id).css('display', 'block');
			} else {
				$('#tt'+id).fadeIn(100);
			}
		},function() {
			var id=(this.id).replace("mz","")
			if (isIE6) {
				$('#tt'+id).css('display', 'none');
			} else {
				$('#tt'+id).fadeOut(100);
			}
		});
	}
	
	// create image
	var r=Math.random()
	var url=''
	url +='w='+w
	url +='&h='+h
	url +='&lx='+(allx.join(','))
	url +='&ly='+(ally.join(','))
	url +='&letters='+(letters.join(','))
	url +='&offsetX='+(offsetX.join(','))
	url +='&offsetY='+(offsetY.join(','))
	url +='&ts='+textsize
	url +='&r='+r
	
	var art_nr=letters.join('')+allx.join('')+ally.join('')
	
	$('#BG').html('<img style="display:none" onload="showBG1()" usemap="#BGmap" id="BGimage" src="_INCL/BG.php/komarov'+art_nr+'.gif?'+url+'&col='+COL_pink+'" />')
	
	if (loadGray) {
		$('#BGGRAY').html('<img style="display:none" onload="showBG2()" onclick="hideMovie(); return false" usemap="#BGmap" id="BGimagegray" src="_INCL/BG.php/komarovgray'+art_nr+'.gif?'+url+'&col='+COL_gray+'" />')
	}	
}

function showBG1() {
	$('#BGimage').css('display','block')
}

function showBG2() {
	$('#BGimagegray').css('display','block')
}


// -----------------------------------------------------------------------------------------------------------------------
// ETC
// -----------------------------------------------------------------------------------------------------------------------

function RESIZE() {
	clearTimeout(DELAYTIMER_resize)
	DELAYTIMER_resize=setTimeout('RESIZE_NOW()',400)			
}


function RESIZE_NOW() {
	// when resizing the window, reposition popup window!
	$.cookie(COOKIE_NAME, null)
	checkCookie()
	self.location.href=self.location.href

}

function checkCookie() {
	// check for position cookie
	
	if ($.cookie(COOKIE_NAME)!=null) {
		
		var pos=$.cookie(COOKIE_NAME).split(',')
		WINDOWX=pos[0]
		WINDOWY=pos[1]
		
	} else {
		var date = new Date();
		date.setTime(date.getTime() + (20 * 60 * 1000)); // 20 minutes till next window position
		setWindowPosition()
		var pos=WINDOWX+','+WINDOWY
		$.cookie(COOKIE_NAME, pos, { expires: date });
	}
}

function setWindowPosition() {
	
	WINDOWX=50+Math.max(0, Math.round(Math.random()*($(window).width()-540-100)))
	WINDOWY=50+Math.max(0, Math.round(Math.random()*($(window).height()-340-100)))
	
}

function getAngle(x1,y1,x2,y2) {
	return Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI
}

function noSpam(who,domain) {
	str = "mailto:" + who + "@" + domain;
	window.location = str;
}




// -----------------------------------------------------------------------------------------------------------------------
// JQUERY PLUGINS
// -----------------------------------------------------------------------------------------------------------------------


/*
 * Cookie plugin
 */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
      
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



/*
 * jQuery Color Animations
 */

(function(jQuery){

	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	function getRGB(color) {
		var result;

		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	var colors = {
		aqua:[0,255,255]
	};
	
})(jQuery);




/* 
	MOUSEWHEEL PLUGIN
 * Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || 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.
 *
 * $LastChangedDate: 2007-12-14 23:57:10 -0600 (Fri, 14 Dec 2007) $
 * $Rev: 4163 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */
(function($){$.event.special.mousewheel={setup:function(){var handler=$.event.special.mousewheel.handler;if($.browser.mozilla)$(this).bind('mousemove.mousewheel',function(event){$.data(this,'mwcursorposdata',{pageX:event.pageX,pageY:event.pageY,clientX:event.clientX,clientY:event.clientY});});if(this.addEventListener)this.addEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=handler;},teardown:function(){var handler=$.event.special.mousewheel.handler;$(this).unbind('mousemove.mousewheel');if(this.removeEventListener)this.removeEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=function(){};$.removeData(this,'mwcursorposdata');},handler:function(event){var args=Array.prototype.slice.call(arguments,1);event=$.event.fix(event||window.event);$.extend(event,$.data(this,'mwcursorposdata')||{});var delta=0,returnValue=true;if(event.wheelDelta)delta=event.wheelDelta/120;if(event.detail)delta=-event.detail/3;if($.browser.opera)delta=-event.wheelDelta;event.data=event.data||{};event.type="mousewheel";args.unshift(delta);args.unshift(event);return $.event.handle.apply(this,args);}};$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel");},unmousewheel:function(fn){return this.unbind("mousewheel",fn);}});})(jQuery);




/* jScrollpane 1.2.3 
http://code.google.com/p/jscrollpane/downloads/list
*/

(function(A){A.jScrollPane={active:[]};A.fn.jScrollPane=function(C){C=A.extend({},A.fn.jScrollPane.defaults,C);var B=function(){return false};return this.each(function(){var O=A(this);O.css("overflow","hidden");var X=this;if(A(this).parent().is(".jScrollPaneContainer")){var Ac=C.maintainPosition?O.position().top:0;var L=A(this).parent();var d=L.innerWidth();var Ad=L.outerHeight();var M=Ad;A(">.jScrollPaneTrack, >.jScrollArrowUp, >.jScrollArrowDown",L).remove();O.css({top:0})}else{var Ac=0;this.originalPadding=O.css("paddingTop")+" "+O.css("paddingRight")+" "+O.css("paddingBottom")+" "+O.css("paddingLeft");this.originalSidePaddingTotal=(parseInt(O.css("paddingLeft"))||0)+(parseInt(O.css("paddingRight"))||0);var d=O.innerWidth();var Ad=O.innerHeight();var M=Ad;O.wrap(A("<div></div>").attr({className:"jScrollPaneContainer"}).css({height:Ad+"px",width:d+"px"}));A(document).bind("emchange",function(Ae,Af,p){O.jScrollPane(C)})}if(C.reinitialiseOnImageLoad){var N=A.data(X,"jScrollPaneImagesToLoad")||A("img",O);var G=[];if(N.length){N.each(function(p,Ae){A(this).bind("load",function(){if(A.inArray(p,G)==-1){G.push(Ae);N=A.grep(N,function(Ag,Af){return Ag!=Ae});A.data(X,"jScrollPaneImagesToLoad",N);C.reinitialiseOnImageLoad=false;O.jScrollPane(C)}}).each(function(Af,Ag){if(this.complete||this.complete===undefined){this.src=this.src}})})}}var o=this.originalSidePaddingTotal;var l={height:"auto",width:d-C.scrollbarWidth-C.scrollbarMargin-o+"px"};if(C.scrollbarOnLeft){l.paddingLeft=C.scrollbarMargin+C.scrollbarWidth+"px"}else{l.paddingRight=C.scrollbarMargin+"px"}O.css(l);var m=O.outerHeight();var i=Ad/m;if(i<0.99){var H=O.parent();H.append(A("<div></div>").attr({className:"jScrollPaneTrack"}).css({width:C.scrollbarWidth+"px"}).append(A("<div></div>").attr({className:"jScrollPaneDrag"}).css({width:C.scrollbarWidth+"px"}).append(A("<div></div>").attr({className:"jScrollPaneDragTop"}).css({width:C.scrollbarWidth+"px"}),A("<div></div>").attr({className:"jScrollPaneDragBottom"}).css({width:C.scrollbarWidth+"px"}))));var z=A(">.jScrollPaneTrack",H);var P=A(">.jScrollPaneTrack .jScrollPaneDrag",H);if(C.showArrows){var g;var Ab;var S;var r;var j=function(){if(r>4||r%4==0){y(u+Ab*b)}r++};var K=function(p){A("html").unbind("mouseup",K);g.removeClass("jScrollActiveArrowButton");clearInterval(S)};var Z=function(){A("html").bind("mouseup",K);g.addClass("jScrollActiveArrowButton");r=0;j();S=setInterval(j,100)};H.append(A("<a></a>").attr({href:"javascript:;",className:"jScrollArrowUp"}).css({width:C.scrollbarWidth+"px"}).html("Scroll up").bind("mousedown",function(){g=A(this);Ab=-1;Z();this.blur();return false}).bind("click",B),A("<a></a>").attr({href:"javascript:;",className:"jScrollArrowDown"}).css({width:C.scrollbarWidth+"px"}).html("Scroll down").bind("mousedown",function(){g=A(this);Ab=1;Z();this.blur();return false}).bind("click",B));var Q=A(">.jScrollArrowUp",H);var J=A(">.jScrollArrowDown",H);if(C.arrowSize){M=Ad-C.arrowSize-C.arrowSize;z.css({height:M+"px",top:C.arrowSize+"px"})}else{var s=Q.height();C.arrowSize=s;M=Ad-s-J.height();z.css({height:M+"px",top:s+"px"})}}var w=A(this).css({position:"absolute",overflow:"visible"});var D;var Y;var b;var u=0;var V=i*Ad/2;var a=function(Ae,Ag){var Af=Ag=="X"?"Left":"Top";return Ae["page"+Ag]||(Ae["client"+Ag]+(document.documentElement["scroll"+Af]||document.body["scroll"+Af]))||0};var f=function(){return false};var v=function(){n();D=P.offset(false);D.top-=u;Y=M-P[0].offsetHeight;b=2*C.wheelSpeed*Y/m};var E=function(p){v();V=a(p,"Y")-u-D.top;A("html").bind("mouseup",T).bind("mousemove",h);if(A.browser.msie){A("html").bind("dragstart",f).bind("selectstart",f)}return false};var T=function(){A("html").unbind("mouseup",T).unbind("mousemove",h);V=i*Ad/2;if(A.browser.msie){A("html").unbind("dragstart",f).unbind("selectstart",f)}};var y=function(Ae){Ae=Ae<0?0:(Ae>Y?Y:Ae);u=Ae;P.css({top:Ae+"px"});var Af=Ae/Y;w.css({top:((Ad-m)*Af)+"px"});O.trigger("scroll");if(C.showArrows){Q[Ae==0?"addClass":"removeClass"]("disabled");J[Ae==Y?"addClass":"removeClass"]("disabled")}};var h=function(p){y(a(p,"Y")-D.top-V)};var q=Math.max(Math.min(i*(Ad-C.arrowSize*2),C.dragMaxHeight),C.dragMinHeight);P.css({height:q+"px"}).bind("mousedown",E);var k;var R;var I;var t=function(){if(R>8||R%4==0){y((u-((u-I)/2)))}R++};var Aa=function(){clearInterval(k);A("html").unbind("mouseup",Aa).unbind("mousemove",e)};var e=function(p){I=a(p,"Y")-D.top-V};var U=function(p){v();e(p);R=0;A("html").bind("mouseup",Aa).bind("mousemove",e);k=setInterval(t,100);t()};z.bind("mousedown",U);H.bind("mousewheel",function(Ae,Ag){v();n();var Af=u;y(u-Ag*b);var p=Af!=u;return !p});var F;var W;function c(){var p=(F-u)/C.animateStep;if(p>1||p<-1){y(u+p)}else{y(F);n()}}var n=function(){if(W){clearInterval(W);delete F}};var x=function(Af,p){if(typeof Af=="string"){$e=A(Af,O);if(!$e.length){return}Af=$e.offset().top-O.offset().top}H.scrollTop(0);n();var Ae=-Af/(Ad-m)*Y;if(p||!C.animateTo){y(Ae)}else{F=Ae;W=setInterval(c,C.animateInterval)}};O[0].scrollTo=x;O[0].scrollBy=function(Ae){var p=-parseInt(w.css("top"))||0;x(p+Ae)};v();x(-Ac,true);A("*",this).bind("focus",function(Ah){var Ag=A(this);var Aj=0;while(Ag[0]!=O[0]){Aj+=Ag.position().top;Ag=Ag.offsetParent()}var p=-parseInt(w.css("top"))||0;var Ai=p+Ad;var Af=Aj>p&&Aj<Ai;if(!Af){var Ae=Aj-C.scrollbarMargin;if(Aj>p){Ae+=A(this).height()+15+C.scrollbarMargin-Ad}x(Ae)}});if(location.hash){x(location.hash)}A(document).bind("click",function(Ae){$target=A(Ae.target);if($target.is("a")){var p=$target.attr("href");if(p.substr(0,1)=="#"){x(p)}}});A.jScrollPane.active.push(O[0])}else{O.css({height:Ad+"px",width:d-this.originalSidePaddingTotal+"px",padding:this.originalPadding});O.parent().unbind("mousewheel")}})};A.fn.jScrollPane.defaults={scrollbarWidth:10,scrollbarMargin:5,wheelSpeed:18,showArrows:false,arrowSize:0,animateTo:false,dragMinHeight:1,dragMaxHeight:99999,animateInterval:100,animateStep:3,maintainPosition:true,scrollbarOnLeft:false,reinitialiseOnImageLoad:false};A(window).bind("unload",function(){var C=A.jScrollPane.active;for(var B=0;B<C.length;B++){C[B].scrollTo=C[B].scrollBy=null}})})(jQuery);


