/**
 *	ImageFlow 0.9
 *
 *	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/
 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// imageflow - varijable ///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 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 = 'e-resize';  // 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;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// imageflow - varijable ///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// PHOTOSLICE 1.24 MADE BY SKID ( www.photoslice.net ) ////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// special thanks to quirksmode.com for js inspiration ////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////

PhotoSliceVARS = {
	effects: 1, // [0, 1] turn off/on the visual effects
	typingEffect: 1, // [0, 1] turn off/on the photo caption typing effect
	framesPerSecond: 35, //effects' speed, the bigger the faster

	loadingImagePath: '/dragonfly/loading2.gif', //loading animation path [loading image from www.ajaxload.info]
	backgroundAlpha: 80, // [0 - 100] background transparency

	aboutButton: 0, // [0, 1] turn off/on the "about" button (default off, appreciated on)
	prevButton: 'predhodna', //'prev', //previous button text
	nextButton: 'sljede&#263;a', //'next', //next button text
	closeButton: "zatvori" //'close' //close button text
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// DO NOT EDIT BELOW ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////

Array.prototype.pushValue = function (value) {
	this[this.length] = value;
	return this.length;
}

Array.prototype.popValue = function () {
	var value = this[this.length - 1]
	delete this[this.length - 1];
	this.length--;
	return value;
}

function PSOverlay () { }

PSOverlay.prototype = {
	Launch:function () {
		var bgDiv = document.createElement('div');
		bgDiv.setAttribute('id', 'PSbackground');
		bgDiv.className = 'PhotoSlice';
		bgDiv.style.position = 'absolute';
		bgDiv.style.zIndex = '99';
		bgDiv.style.left = bgDiv.style.top = bgDiv.style.width = bgDiv.style.height = '0px';
		this.divObj = bgDiv;
		
		PhotoSlice.SetAlpha(bgDiv, 10);
		document.body.appendChild(bgDiv);
		
		this.Stretch(1);
		PhotoSlice.GoToAlpha('PSbackground', PhotoSliceVARS.backgroundAlpha, 25, 'PhotoSlice.Setup();');
		
		PhotoSlice.ForbiddenObjects('hidden');
	},
	Stretch:function (first) {
		var sizeArray = PhotoSlice.GetPageSize();
		var scrollArray = PhotoSlice.GetPageScroll();

		this.divObj.style.width = (sizeArray[0] + scrollArray[0])+ 'px';
		if (first) this.divObj.style.height = sizeArray[1] + 'px';
		
		var self = this;
		window.setTimeout(function () { self.Stretch() }, 1000);
	},
	Close:function (last) {
		if (!PhotoSliceVARS.effects || last) {
			var bgDiv = this.divObj;
			document.body.removeChild(bgDiv);
			PhotoSlice.ForbiddenObjects('visible');
		} else {
			PhotoSlice.GoToAlpha('PSbackground', 0, 25, 'PhotoSlice.photoBg.Close(1);');
		}
	}
}

PhotoSlice = {
	version: '1.24',
	
	photoArray: new Array(),
	currentPhoto: -1,
	photoIsLoaded: 0,
	
	textIsTyping: 0,
	textBuffer: '',
	
	setEvents:function () {
      	var images = document.getElementById(conf_images);
		for (var i = 0; i < images.length; i++) {
			if (links[i].rel.substring(0, 10) == 'photoslice') {
				images[i].ondblclick = function () {
					if (!PhotoSlice.aObj) PhotoSlice.Start(this);
					return false;
                                        }
			}
		}
		this.imgPreloader = document.createElement('img');
		this.imgPreloader.setAttribute('src', PhotoSliceVARS.loadingImagePath);
		
		if (document.addEventListener) document.addEventListener("keyup", PhotoSlice.KeyUp, false);
    		else if (document.attachEvent) document.attachEvent("onkeyup", PhotoSlice.KeyUp);
   		else document.onkeyup = PhotoSlice.KeyUp;
	},
	setEvent:function (image) {

				image.onclick = function () {
					if (!PhotoSlice.aObj) PhotoSlice.Start(this);
					return false;
		}
	},
	KeyUp:function (e) {
   		if (!PhotoSlice.photoIsLoaded) return;
   		
   		if (!e) e = event;
   		var keyVal = null;
   		if (e.keyCode) keyVal = e.keyCode;
                else if (e.which) keyVal = e.which;
                else if (e.charCode) keyVal = e.charCode;
                else if (e.keyIdentifier) keyVal = e.keyIdentifier;
                else return;
   		
   		var prevValues = new Array('37', '80');
   		var nextValues = new Array('39', '78', '32');
   		var closeValues = new Array('8', '27', '67');
   		
   		var action = null;
   		for (var i = 0; i < prevValues.length; i++) if (prevValues[i] == keyVal) action = 'prev';
   		for (var i = 0; i < nextValues.length; i++) if (nextValues[i] == keyVal) action = 'next';
   		for (var i = 0; i < closeValues.length; i++) if (closeValues[i] == keyVal) action = 'close';
   		
   		switch (action) {
   			case 'prev': if (PhotoSlice.currentPhoto > 0) PhotoSlice.ChangePhoto(-1); break;
   			case 'next': if (PhotoSlice.currentPhoto < (PhotoSlice.photoArray.length - 1)) PhotoSlice.ChangePhoto(1); break;
   			case 'close': PhotoSlice.Close(); break;
   		}
	},
	Start:function (aObj) {
		this.aObj = aObj;
		this.photoIsLoaded = 0;
		
		bgObj = new PSOverlay();
		this.photoBg = bgObj;
		
		bgObj.Launch();
	},
	Setup:function () {
		while (this.photoArray.length) {
			this.photoArray.popValue();
	 	}
      	        var images = document.getElementById(conf_images);//('img'); //conf_images);
		var x = 0;
		for (var i = 0; i < images.childNodes.length; i++) {
			//if (images.item(i).getAttribute('rel') == this.aObj.rel) {
                             	var image = images.childNodes.item(i);
		if (image.nodeType == 1)
		{
				var tempArray = new Array(image.getAttribute('longdesc'), image.getAttribute('alt'));
				this.photoArray.pushValue(tempArray);
				if (image == this.aObj) this.currentPhoto = x;
				x++;
		        //}
		}
		}
		var stageDiv = document.createElement('div');
		stageDiv.setAttribute('id', 'PSstage');
		stageDiv.className = 'PhotoSlice';
		stageDiv.style.position = 'absolute';
		stageDiv.style.zIndex = '100';
		stageDiv.style.left = '0px';
		stageDiv.style.top = '0px';
		document.body.appendChild(stageDiv);
		this.stageDivObj = stageDiv;
		
		var stageDivReplica = document.createElement('div');
		stageDivReplica.setAttribute('id', 'PSstage-replica');
		stageDivReplica.style.position = 'absolute';
		stageDivReplica.style.zIndex = '99';
		stageDivReplica.style.left = '0px';
		stageDivReplica.style.top = '0px';
		document.body.appendChild(stageDivReplica);
		this.stageDivReplicaObj = stageDivReplica;
		
		var captionDiv = document.createElement('div');
		captionDiv.setAttribute('id', 'PScaption');
		captionDiv.className = 'PhotoSlice';
		captionDiv.style.position = 'absolute';
		captionDiv.style.zIndex = '101';
		captionDiv.style.left = '0px';
		captionDiv.style.top = '0px';
		captionDiv.style.width = '100%';
		this.SetAlpha(captionDiv, 0);
		document.body.appendChild(captionDiv);
		this.captionDivObj = captionDiv;
		
		var menuDiv = document.createElement('div');
		menuDiv.setAttribute('id', 'PSmenu');
		menuDiv.className = 'PhotoSlice';
		menuDiv.style.position = 'absolute';
		menuDiv.style.zIndex = '102';
		menuDiv.style.left = '0px';
		menuDiv.style.top = '0px';
		menuDiv.style.width = '100%';
		this.SetAlpha(menuDiv, 0);
		document.body.appendChild(menuDiv);
		this.menuDivObj = menuDiv;
		
		this.LoadPhoto();
	},
	LoadPhoto:function () {	
		var stageDiv = this.stageDivObj;
		stageDiv.innerHTML = '';
		stageDiv.style.left = '0px';
		stageDiv.style.top = this.GetPageScroll()[1] + 'px';
		stageDiv.style.width = this.GetPageSize()[2] + 'px';
		stageDiv.style.height = this.GetPageSize()[3] + 'px';
		stageDiv.style.background = "url('" + PhotoSliceVARS.loadingImagePath + "') no-repeat center center";
		this.SetAlpha(stageDiv, 100);

		stageDiv.onclick = function () {
			PhotoSlice.Close();
		}
		
		stageDiv.innerHTML = '';
		var loadingPhoto = document.createElement('img');
		loadingPhoto.setAttribute('id', 'loadingPhoto');
		loadingPhoto.onload = function () { PhotoSlice.WaitToLoad(this); }
		loadingPhoto.src = this.photoArray[this.currentPhoto][0];
		stageDiv.appendChild(loadingPhoto);
	},
	WaitToLoad:function (obj) {
		if (obj) this.photoObj = obj;
		
		if (this.photoObj.offsetWidth > 0) this.PhotoLoaded();
		else {
			var self = this;
			window.setTimeout(function () { self.WaitToLoad() }, 10);
		}
	},
	PhotoLoaded:function () {
		this.stageDivObj.style.background = 'none';
		
		this.stageDivObj.style.width = this.photoObj.offsetWidth + 'px';
		this.stageDivObj.style.height = this.photoObj.offsetHeight + 'px';
		
		this.ShowPanels();
		this.ArrangeStage(1);
		
		this.stageDivObj.onclick = function () { }
	
		this.photoBg.divObj.onclick = function () {
			PhotoSlice.Close();
		}
	
		if (!PhotoSliceVARS.effects) this.ShowPhoto ();
		else this.ShowPhotoEffect ();
	},
	ShowPhotoEffect:function () {
		var stageDivReplica = this.stageDivReplicaObj;
		
		stageDivReplica.style.left = (this.stageDivObj.offsetLeft - 50) + 'px';
		stageDivReplica.style.top = (this.stageDivObj.offsetTop - 50) + 'px';
		stageDivReplica.style.width = (this.stageDivObj.offsetWidth + 100) + 'px';
		stageDivReplica.style.height = (this.stageDivObj.offsetHeight + 100) + 'px';
		
		this.SetAlpha(this.stageDivObj, 0);
		this.SetAlpha(stageDivReplica, 0);
		
		this.photoObj.style.visibility = 'visible';
		this.GoToSizeAndAlpha('PSstage-replica', this.stageDivObj.offsetLeft, this.stageDivObj.offsetTop, this.stageDivObj.offsetWidth, this.stageDivObj.offsetHeight, 100, 15, 'PhotoSlice.GoToAlpha("PSstage", 100, 20, "PhotoSlice.SetAlpha(PhotoSlice.stageDivReplicaObj, 0); PhotoSlice.ShowPhoto();");');
	},
	ShowPhoto:function () {
		this.photoIsLoaded = 1;
		this.photoObj.style.visibility = 'visible';
		
		this.ArrangeStage();
		this.WriteText('PScomment', this.photoArray[this.currentPhoto][1], 0);
		
		if (this.currentPhoto < (this.photoArray.length - 1)) this.imgPreloader.setAttribute('src', this.photoArray[this.currentPhoto + 1][0]);
	
		if (this.photoArray.length > 1) {
			this.photoObj.onclick = function () {
				PhotoSlice.ChangePhoto(1);
			}
		}
	},
	ChangePhoto:function(dir) {
		if (this.photoIsLoaded) {
			this.photoIsLoaded = 0;
			this.currentPhoto += dir;
		
			if (this.currentPhoto >= this.photoArray.length) this.currentPhoto = 0;
		
			document.getElementById('PScomment').innerHTML = '';
		
			if (!PhotoSliceVARS.effects) this.LoadPhoto();
			else {
				this.SetAlpha(this.stageDivReplicaObj, 100);
				this.GoToAlpha('PSstage', 0, 20, 'PhotoSlice.GoToSizeAndAlpha("PSstage-replica", ' + (this.stageDivObj.offsetLeft + 50) + ', ' + (this.stageDivObj.offsetTop + 50) + ', ' + (this.stageDivObj.offsetWidth - 100) + ', ' + (this.stageDivObj.offsetHeight - 100) + ', 0, 20, "PhotoSlice.LoadPhoto();");');
			}
		}
	},
	ShowPanels:function () {
		var captionDiv = this.captionDivObj;
		captionDiv.innerHTML = '';
		
		var scrollArray = this.GetPageScroll();
		captionDiv.style.left = scrollArray[0] + 'px';
		captionDiv.style.top = scrollArray[1] + 'px';
		
		if (PhotoSliceVARS.aboutButton) {
			var aboutDiv = document.createElement('a');
			aboutDiv.setAttribute('id', 'PSabout');
			aboutDiv.href = '#about';
			aboutDiv.className = 'button';
			aboutDiv.innerHTML = '?';
			captionDiv.appendChild(aboutDiv);
			aboutDiv.onclick = function () { 
				PhotoSlice.WriteText('PScomment', 'PhotoSlice v' + PhotoSlice.version + ' - by skid. FREE to use and download at <a href=\'http://www.photoslice.net\' target=\'_blank\'>www.photoslice.net</a>.', 0);
				return false;
			}
		}
		
		var textDiv = document.createElement('p');
		textDiv.setAttribute('id', 'PScomment');
		captionDiv.appendChild(textDiv);
		
		this.SetAlpha(captionDiv, 95);
		
		var menuDiv = this.menuDivObj;
		menuDiv.innerHTML = '';
		
		var buttonsDiv = document.createElement('div');
		buttonsDiv.setAttribute('id', 'PSbuttons');
		menuDiv.appendChild(buttonsDiv);
		
		var prevDiv = document.createElement('a');
		prevDiv.setAttribute('id', 'PSaPrev');
		prevDiv.href = '#prev';
		prevDiv.className = 'button';
		prevDiv.innerHTML = PhotoSliceVARS.prevButton;
		buttonsDiv.appendChild(prevDiv);
		if (this.currentPhoto > 0) prevDiv.onclick = function () { PhotoSlice.ChangePhoto(-1); return false; }
		else prevDiv.className += ' disabled';
		
		var nextDiv = document.createElement('a');
		nextDiv.setAttribute('id', 'PSaNext');
		nextDiv.href = '#next';
		nextDiv.className = 'button';
		nextDiv.innerHTML = PhotoSliceVARS.nextButton;
		buttonsDiv.appendChild(nextDiv);
		if (this.currentPhoto < (this.photoArray.length - 1)) nextDiv.onclick = function () { PhotoSlice.ChangePhoto(1); return false; }
		else nextDiv.className += ' disabled';
		
		var closeDiv = document.createElement('a');
		closeDiv.setAttribute('id', 'PSaClose');
		closeDiv.href = '#close';
		closeDiv.className = 'button';
		closeDiv.innerHTML = PhotoSliceVARS.closeButton;
		buttonsDiv.appendChild(closeDiv);
		closeDiv.onclick = function () { PhotoSlice.Close(); return false; }
		
		this.SetAlpha(menuDiv, 95);
		
	},
	ArrangeStage:function (first) {
		if (first || this.photoIsLoaded) {
			var sizeArray = this.GetPageSize();
			var scrollArray = this.GetPageScroll();
			
			if (this.captionDivObj) {
				this.captionDivObj.style.left = scrollArray[0] + 'px';
				this.captionDivObj.style.top = scrollArray[1] + 'px';
				
			}
			if (this.menuDivObj) {
				if (this.menuDivObj.innerHTML) {
					this.menuDivObj.style.left = scrollArray[0] + 'px';
					this.menuDivObj.style.top = (sizeArray[3] + scrollArray[1] - this.menuDivObj.offsetHeight) + 'px';
				}
			}
			
			var currLeft = this.stageDivObj.offsetLeft;
			var currTop = this.stageDivObj.offsetTop;
			var nextLeft = (sizeArray[2] / 2 - (this.stageDivObj.offsetWidth / 2) + scrollArray[0]);
			var nextTop = (sizeArray[3] / 2 - (this.stageDivObj.offsetHeight / 2) + scrollArray[1]);
			
			var wDif = sizeArray[2] - ((sizeArray[2] - this.stageDivObj.offsetWidth) / 2);
			var hDif = sizeArray[3] - ((sizeArray[3] - this.stageDivObj.offsetHeight) / 2);
			
			var minTop = 0;
			if (this.captionDivObj) minTop = this.captionDivObj.offsetHeight;
			
			if ((this.stageDivObj.offsetWidth < sizeArray[2]) || (nextLeft - currLeft > wDif) || (currLeft - nextLeft > wDif) || first) {
				if (nextLeft < scrollArray[0]) this.stageDivObj.nextLeft = scrollArray[0];
				else if (nextLeft > (this.photoBg.divObj.offsetWidth - this.stageDivObj.offsetWidth) && this.photoBg.divObj.offsetWidth >= sizeArray[2]) this.stageDivObj.nextLeft = this.photoBg.divObj.offsetWidth - this.stageDivObj.offsetWidth;
				else this.stageDivObj.nextLeft = nextLeft;
			}
			if ((this.stageDivObj.offsetHeight < sizeArray[3]) || (nextTop - currTop > hDif) || (currTop - nextTop > hDif) || first) {
				if (nextTop < (minTop + scrollArray[1]))  this.stageDivObj.nextTop = minTop + scrollArray[1];
				else if (nextTop > (this.photoBg.divObj.offsetHeight - this.stageDivObj.offsetHeight) && this.photoBg.divObj.offsetHeight >= sizeArray[3]) this.stageDivObj.nextTop = this.photoBg.divObj.offsetHeight - this.stageDivObj.offsetHeight;
				else this.stageDivObj.nextTop = nextTop;
			}
			
			this.stageDivObj.style.left = this.stageDivObj.nextLeft + 'px';
			this.stageDivObj.style.top = this.stageDivObj.nextTop + 'px';
			
			if (this.stageDivReplicaObj) {
				this.stageDivReplicaObj.style.left = this.stageDivObj.style.left;
				this.stageDivReplicaObj.style.top = this.stageDivObj.style.top;
			}
			if (!first) {
				var self = this;
				window.setTimeout(function () { self.ArrangeStage() }, 500);
			}
		}
	},
	Close:function (last) {
		if (this.captionDivObj) { document.body.removeChild(this.captionDivObj); this.captionDivObj = null; }
		if (this.menuDivObj) { document.body.removeChild(this.menuDivObj); this.menuDivObj = null; }
		this.aObj = null;
		
		if (!PhotoSliceVARS.effects || last || !this.photoIsLoaded) {
			if (this.stageDivReplicaObj) { document.body.removeChild(this.stageDivReplicaObj); this.stageDivReplicaObj = null; }
			if (this.stageDivObj) { document.body.removeChild(this.stageDivObj); this.stageDivObj = null; }
			this.photoBg.Close();
		} else {
			this.SetAlpha(this.stageDivReplicaObj, 100);
			this.GoToAlpha('PSstage', 0, 20, 'PhotoSlice.GoToSizeAndAlpha("PSstage-replica", ' + (this.stageDivObj.offsetLeft + 50) + ', ' + (this.stageDivObj.offsetTop + 50) + ', ' + (this.stageDivObj.offsetWidth - 100) + ', ' + (this.stageDivObj.offsetHeight - 100) + ', 0, 20, "PhotoSlice.Close(1);");');
		}
		this.photoIsLoaded = 0;
	},
	ForbiddenObjects:function (state) {
		var selects = document.getElementsByTagName('select');
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = state;
		}
		var flashObjects = document.getElementsByTagName('object');
		for (i = 0; i < flashObjects.length; i++) {
			flashObjects[i].style.visibility = state;
		}
		var flashEmbeds = document.getElementsByTagName('embed');
		for (i = 0; i < flashEmbeds.length; i++) {
			flashEmbeds[i].style.visibility = state;
		}
	},
	GetPageScroll:function () {
		var xScroll = 0, yScroll = 0;
    
		if (typeof(window.pageYOffset) == 'number') {
			xScroll = window.pageYOffset;
			yScroll = window.pageXOffset;
		} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			xScroll = document.body.scrollTop;
			yScroll = document.body.scrollLeft;
		} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			xScroll = document.documentElement.scrollTop;
			yScroll = document.documentElement.scrollLeft;
		}

		var returnArray = Array(yScroll, xScroll);
		return returnArray;
	},
	GetPageSize:function () {
	
		var xPage, yPage;
		
		if (window.innerHeight && window.scrollMaxY) {
			xPage = window.innerWidth + window.scrollMaxX;
			yPage = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			xPage = document.body.scrollWidth;
			yPage = document.body.scrollHeight;
		} else { 
			xPage = document.body.offsetWidth;
			yPage = document.body.offsetHeight;
		}
	
		var windowWidth, windowHeight;

		if (self.innerHeight) {
			if (document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
			else windowWidth = window.innerWidth;
			if (document.documentElement.clientHeight == (window.innerHeight - 16)) windowHeight = document.documentElement.clientHeight;
			else windowHeight = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		pageWidth = windowWidth;
	
		if (windowHeight < yPage) pageHeight = yPage;
		else pageHeight = windowHeight;

		var returnArray = Array(pageWidth, pageHeight, windowWidth, windowHeight);
		return returnArray;
	},
	SetAlpha:function (obj, alpha) {  
		obj.style.filter = 'alpha(opacity: ' + alpha + ')';
		obj.style.MozOpacity = alpha / 100;
    		obj.style.KhtmlOpacity = alpha / 100;
		obj.style.opacity = alpha / 100;
	},
	GoToAlpha:function (objName, targetAlpha, speed, nextFunction) {
		if (obj = document.getElementById(objName)) {
			var currAlpha = obj.style.opacity * 100;
			var dir = 1;
			if (targetAlpha < currAlpha) dir = -1;

			currAlpha += speed * dir;
			if (PhotoSliceVARS.effects && ((dir == 1 && currAlpha < targetAlpha) || (dir == -1 && currAlpha > targetAlpha))) {
				this.SetAlpha (obj, Math.round(currAlpha));
				setTimeout("PhotoSlice.GoToAlpha('" + objName + "', " + targetAlpha + ", " + speed + ", '" + nextFunction + "')", 1000 / PhotoSliceVARS.framesPerSecond);
			} else {
				this.SetAlpha (obj, Math.round(targetAlpha));
				if (nextFunction) setTimeout(nextFunction, 0);
			}
		}
	},
	GoToSizeAndAlpha:function (objName, targetX, targetY, targetWidth, targetHeight, targetAlpha, speed, nextFunction) {
		if (obj = document.getElementById(objName)) {
			var currentWidth = obj.offsetWidth;
			var currentHeight = obj.offsetHeight;
			var currentX = obj.style.left.substring(0, obj.style.left.length - 2) * 1;
			var currentY = obj.style.top.substring(0, obj.style.top.length - 2) * 1;
			var currentAlpha = obj.style.opacity * 100;
		
			var widthDif = (targetWidth - currentWidth);
			var heightDif = (targetHeight - currentHeight);
			var xDif = (targetX - currentX);
			var yDif = (targetY - currentY);
			var alphaDif = (targetAlpha - currentAlpha);
		
			var totalDif = 0;
			if (widthDif > 0) totalDif += widthDif;
			else totalDif -= widthDif;
			if (heightDif > 0) totalDif += heightDif;
			else totalDif -= heightDif;
	
			var widthStep = speed * (2 * widthDif / totalDif);
			var heightStep = speed * (2 * heightDif / totalDif);
			var xStep = widthStep * (xDif / widthDif);
			var yStep = heightStep * (yDif / heightDif);
			var alphaStep = widthStep * (alphaDif / widthDif);
		
			var nextWidth = currentWidth + widthStep;
			var nextHeight = currentHeight + heightStep;
			var nextX = currentX + xStep;
			var nextY = currentY + yStep;
			var nextAlpha = currentAlpha + alphaStep;
		
			if (PhotoSliceVARS.effects && (((currentWidth < targetWidth && nextWidth < targetWidth) || (currentWidth > targetWidth && nextWidth > targetWidth)) && ((currentHeight < targetHeight && nextHeight < targetHeight) || (currentHeight > targetHeight && nextHeight > targetHeight)))) {

    				obj.style.width = nextWidth + 'px';
    				obj.style.height = nextHeight + 'px';
    				obj.style.left = nextX + 'px';
    				obj.style.top = nextY + 'px';
    				this.SetAlpha (obj, nextAlpha);

				setTimeout("PhotoSlice.GoToSizeAndAlpha('" + objName + "', " + targetX + ", " + targetY + ", " + targetWidth + ", " + targetHeight + ", " + targetAlpha + ", " + speed + ", '" + nextFunction + "')", 1000 / PhotoSliceVARS.framesPerSecond);
	
			} else {
				obj.style.width = targetWidth + 'px';
    				obj.style.height = targetHeight + 'px';
    				obj.style.left = targetX + 'px';
    				obj.style.top = targetY + 'px';
    				this.SetAlpha (obj, targetAlpha);
    	
    				if (nextFunction) setTimeout(nextFunction, 0);
			}
		}
	},
	WriteText:function (objName, fullString, index) {
		if (!index && this.textIsTyping) return;
		this.textIsTyping = 1;
		if ((obj = document.getElementById(objName)) && PhotoSlice.photoIsLoaded) {
			if (PhotoSliceVARS.typingEffect) {
				if (fullString.substr(index, 1) == '<') {
					index++;
					while (fullString.substr(index, 1) != '>' && index < fullString.length) index++;
				}
				index++;
				obj.innerHTML = this.textBuffer = fullString.substr(0, index);
					
				if (index <= fullString.length) setTimeout('PhotoSlice.WriteText("' + objName + '", "' + fullString + '", ' + index + ')', 1000 / PhotoSliceVARS.framesPerSecond);
			} else obj.innerHTML = this.textBuffer = fullString;
		} else {
			this.textBuffer = fullString = '';
			if (obj) obj.innerHTML = this.textBuffer;
		}
		if (fullString == this.textBuffer) this.textIsTyping = 0;
	}
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// photoslice - gore ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////



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 = img_div.childNodes.item(array_images[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 = img_div.childNodes.item(array_images[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;
			}
			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 + '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;
					//image.onclick = function() { image.ondblclick() };//document.location = this.url; }
                                        
					/* Set onclick event */
					PhotoSlice.setEvent(image);

					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;

	/* Cache EVERYTHING! */
	max = img_div.childNodes.length;
	var i = 0;
	for (var index = 0; index < max; index++)
	{ 
		var image = img_div.childNodes.item(index);
		if (image.nodeType == 1)
		{
			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 */
			/*image.url = image.getAttribute('longdesc');*/
			/*image.ondblclick = function() { document.location = this.url; }*/

			/* Set image cursor type */
			image.style.cursor = conf_images_cursor;

			i++;
		}
	}
///////////////////////////////////////////////////////////////
	/* Set ondblclick event */
        PhotoSlice.setEvents();
///////////////////////////////////////////////////////////////

	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';
}

/* 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();
	}
}

/* Refresh ImageFlow on window resize */
window.onresize = function()
{
	if(document.getElementById(conf_imageflow)) refresh();
}

/* Fixes the back button issue */
window.onunload = function()
{
  //document = null;//kod mene ne‘to neradi????
}


/* 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;
	}
}

