// SlideShow 0.9.1 , January 2007
// Created by Matija Abram
//

var images, height, width, dots;
var pointSquare = "/Static/images/gui/square.png";

function slideShow() {
	
	defineSlideShowControls();
	if(images){
		if(!height) height = 240;
		if(!width) width = 240;
		allImgSS = images.length;
		nDiv  = new Array();
		
		for(nj = 0; nj < allImgSS; nj++){
			nDiv[nj] = document.createElement('div');			
			nDiv[nj].style.width = width;
			nDiv[nj].style.display = "none";
			nDiv[nj].style.opacity = 0;
			nDiv[nj].style.filter = 'alpha(opacity=0)';
			nDiv[nj].className = 'opaque';
			
			var im = nDiv[nj].appendChild(document.createElement('img'));
				im.setAttribute('src', images[nj]);
				im.setAttribute('height', height);
				im.setAttribute('width', width);
				
			document.getElementById('imageHolder').appendChild(nDiv[nj]);
			
			if(dots){
				makePopupBox(dots[nj], nDiv[nj], nj);
			}
			//loop.end
		}
			
		curImgSS = 0;
		tofIn = nDiv[curImgSS];
		fadeInIntID = setInterval("fadeIn()", 10);
		
	}
	
}
function makePopupBox(imageDots, holderDiv, k) {
	var imageDots, holderDiv;
	for(i = 0; i < imageDots.length; i++) {
		//za IE 6, ker drugače ne deluje "onmouseover"
		var sqa = holderDiv.appendChild(document.createElement('a'));
			sqa.setAttribute('name', 'desc' + i + k);
		//
		var sq = sqa.appendChild(document.createElement('img'));
			sq.setAttribute('src', pointSquare);
			sq.className = 'square';
			sq.style.top = (parseInt(imageDots[i][1]) - 8) + "px";
			sq.style.left = (parseInt(imageDots[i][0]) - 8) + "px";
			
		var descH =  holderDiv.appendChild(document.createElement('div'));
			descH.setAttribute('id', sqa.name);
			descH.className = 'sDesc';
			descH.innerHTML = imageDots[i][2];
			
			if(imageDots[i][0] > 500) {
				descH.style.left = (parseInt(imageDots[i][0]) - 208) + "px";
				descH.style.top = (parseInt(imageDots[i][1]) + 10) + "px";
			}else {
				descH.style.left = (parseInt(imageDots[i][0]) - 8) + "px";
				descH.style.top = (parseInt(imageDots[i][1]) + 10) + "px";
			}
		
			sqa.onmouseover = function () {
				document.getElementById(this.name).style.display = 'block';
			}
			sqa.onmouseout = function () {
				document.getElementById(this.name).style.display = 'none';
			}
		
		
	}
}
function defineSlideShowControls() {
	if(document.getElementsByTagName){
		if(images && (images.length > 1)){
			var links = document.getElementsByTagName('a');
			for(var cn = 0; cn < links.length; cn++){
				if(links[cn].getAttribute('rel') == "next"){
					links[cn].setAttribute('href', 'javascript:next()');
					links[cn].onmouseover = function () {
						this.style.color = "#000000";
						this.style.backgroundImage = "url('/Static/images/gui/go_r.gif')";
					}
					links[cn].onmouseout = function () {
						this.style.color = "#E2017B";
						this.style.backgroundImage = "url('/Static/images/gui/go_r_pink.gif')";
					}
				}
				if(links[cn].getAttribute('rel') == "prev"){
					links[cn].setAttribute('href', 'javascript:prev()');
					links[cn].onmouseover = function () {
						this.style.color = "#000000";
						this.style.backgroundImage = "url('/Static/images/gui/go_l.gif')";
					}
					links[cn].onmouseout = function () {
						this.style.color = "#E2017B";
						this.style.backgroundImage = "url('/Static/images/gui/go_l_pink.gif')";
					}
				}
			}
		} else {
			var links = document.getElementsByTagName('a');
			for(var cn = 0; cn < links.length; cn++){
				if((links[cn].getAttribute('rel') == "next") || (links[cn].getAttribute('rel') == "prev")){
					links[cn].parentNode.style.display = "none";
				}
			}
		}
	}
}
function fadeIn() {
	if(!tofIn.style.opacity) tofIn.style.opacity = '0';
	tofIn.style.display = "block";
	var nvar = (parseFloat(tofIn.style.opacity) + parseFloat(0.2)) * 10;
	var nvar = (Math.round(nvar))/10;
	tofIn.style.opacity = nvar;
	tofIn.style.filter = 'alpha(opacity=' + nvar*100 + ')';

	if(nvar >= 1){
		clearInterval(fadeInIntID);
	}
	
}
function fadeOut() {
	var nvar = (parseFloat(tofIn.style.opacity) - parseFloat(0.2)) * 10;
	var nvar = (Math.round(nvar))/10;
	
	tofIn.style.opacity = nvar;
	tofIn.style.filter = 'alpha(opacity=' + nvar*100 + ')'
	
	if(nvar <= 0){
		clearInterval(fadeInIntID);
		
		if(porn > 0) {
			if(curImgSS == (allImgSS-1)) curImgSS = 0;
			else curImgSS++;
		} else {
			if(curImgSS == 0) curImgSS = (allImgSS-1);
			else curImgSS--;
		}
		tofIn.style.display = "none";
		tofIn = nDiv[curImgSS];
		fadeInIntID = setInterval("fadeIn()", 10);
	}
}
function next() {
	porn = 1;
	fadeInIntID = setInterval("fadeOut()", 10);
}
function prev() {
	porn = -1;
	fadeInIntID = setInterval("fadeOut()", 10);
}
