/*
	All High Seeds, Ltd.
	DHTML functions library
	(c) 2005 carlos@allhighseeds.com
*/

var ajej = document.all && (navigator.appName.indexOf("Internet Explorer") >= 0) ? 1 : 0;
var necky = navigator.appName.indexOf("Netscape") >= 0 ? 1 : 0;
//ajej = true;

var pixelsleft = 0;

// #############################################################################
function preloadImage(url) {
	 preloadedImage = new Image()
	 preloadedImage.src = url; 
}

function changeElementHTML(divid,code) {
	element = document.getElementById(divid);
	element.innerHTML = code;
}

function changeElementBg(divid,code) {
	element = document.getElementById(divid);
	element.style.background = code;
}

function hideElement(divid) {
	element = document.getElementById(divid);
	element.style.display = 'none';
}

function showElement(divid) {
	element = document.getElementById(divid);
	element.style.display = 'block';
}

function changeImageUrl(imagename,url) {
	document.images[imagename].src = url;
}
// #############################################################################

// scrolling function
var scrolltimer = null;
function verScroll(dir, spd, loop) {
	if (pixelsleft > 0) {
		loop = true;
	} else {
		stopScroll();
	}
	direction = "up";
	//alert('sdf');
	//speed = 10; (nastaveno parametrem)
/*	if (document.layers) {
		var page = eval(document.contentLayer);
	} else {
		if (document.getElementById) {
			var page= eval("document.getElementById('contentLayer').style");
		} else {
			if (document.all) {
				var page = eval(document.all.contentLayer.style);
			}
		}
	}*/
	direction = dir;
	speed = 3;//parseInt(spd);
	var y_pos = parseInt(setScroll(null));
	if (loop == true) {
		if (direction == "dn") {
			
//			if (slideshow && -(83*currentphoto) < y_pos) {/
//			} else
			//if (-(83*(photocount-1)) < y_pos) {
				setScroll(y_pos - (speed));
				pixelsleft = pixelsleft - speed;
			//}
			
		} else {
			if (direction == "up" && y_pos < 0) {
				setScroll(y_pos + (speed));
				pixelsleft = pixelsleft - speed;
			} else {
				if (direction == "top") {
					setScroll(0);
				}
 		  }
		}
		scrolltimer = window.setTimeout("verScroll(direction,speed)", 110);
	}
}

// pokud je pozice null tak vrati aktualni, jinak pozici nastavi
function setScroll(position) {
	if (document.layers) {
		var page = eval(document.contentLayer);
	} else {
		if (document.getElementById) {
			var page= eval("document.getElementById('contentLayer').style");
		} else {
			if (document.all) {
				var page = eval(document.all.contentLayer.style);
			}
		}
	}
	if (position == null) {
		return page.top;
	} else {
		page.top = position+'px';
	}
}

// stop scrolling function
function stopScroll() {
	loop = false;
	clearTimeout(scrolltimer);
}

function oneScroll(dir, spd, loop) {
  pixelsleft = 125;
	verScroll(dir, spd, loop);
}

function testScroll() {
	setScroll(-100);
	alert(parseInt(setScroll(null)));
}
//window.onload=startList;



// #############################################################################
//var contexthelp = document.getElementById('contexthelp');
var term = '';

// funkce na sledovani kurzoru
//var started = true;
if (document.layers)
  document.captureEvents(Event.MOUSEDOWN);
//document.onmousedown = eventmouse;

		 
function showTerm(evt,termin) {

	// lepsi cesta na ukazani na contexthelp
	var cursor = 
	 document.layers ? document.contexthelp :
	 document.all ? document.all.contexthelp :
	 document.getElementById ? document.getElementById('contexthelp') : null;

	if (document.layers)
		cursor.visibility = 'show';
	else 
		cursor.style.visibility = 'visible';
	
	cursor.innerHTML = loading;
	loadData(termin);
	
	if (document.layers) {
		cursor.left = evt.pageX;
		cursor.top = evt.pageY;
		//alert('document.layers X:'+evt.pageX+' Y:'+evt.pageY);
	}
	else if (document.all) {
		cursor.style.pixelLeft = event.x;
		cursor.style.pixelTop = event.y;
		//alert('document.all X:'+event.x+' Y:'+event.y);
	}
	else if (document.getElementById) {
		cursor.style.left = evt.pageX + 'px';
		cursor.style.top = evt.pageY + 'px';
		//alert('document.getElementById X:'+evt.pageX+' Y:'+evt.pageY);
	}
	
	return false;
}  

function hideTerm() {
	document.getElementById('contexthelp').style.visibility = 'hidden';
}

function fillTerm(title,description) {
	var cursor = 
	 document.layers ? document.contexthelp :
	 document.all ? document.all.contexthelp :
	 document.getElementById ? document.getElementById('contexthelp') : null;
	cursor.innerHTML = '<ul><li><a class="closeit">'+description+'</a></li><li><a class="helpme" href="help/'+title+'"><img src="./images/contexthelp.gif" width="9" border="0" height="9" alt="Napověda" /></a></li></ul>';
}

function loadData(title) {

    // odmazeme stary skript, pokud existoval
    var hlavicka = document.getElementsByTagName('head')[0];
    var dataLoader = document.getElementById('scriptLoader');
    if(dataLoader) hlavicka.removeChild(dataLoader);

    // vytvorime novy element script
    script = document.createElement('script');
    script.id = 'scriptLoader';
    script.src = 'quickhelp?term='+title+'&r='+Math.random();

    // POZOR, DULEZITE!! Skript musime vlozit do stranky 
    // pomoci DOM - appendChild()
    // Ihned po vlozeni prohlizec stahne skript a spusti jej
    x = document.getElementsByTagName('head')[0];
    x.appendChild(script);

    return false;
}

function clearData() {
    // v jednoduchem cyklu smazeme vsechny elementy v prvku vystup
    while(contexthelp.hasChildNodes()) contexthelp.removeChild(contexthelp.childNodes[0]);
    return false;
}


// #############################################################################
var visiblesection = 1;

function nextSection() {
	if (visiblesection > 2) {
		// redirect
		window.location = 'projects';
	} else {
		hideSection('project'+visiblesection);
		visiblesection++;
		showSection('project'+visiblesection);
	}
}

function prevSection() {
	if (visiblesection < 2) {
		visiblesection = 2;
	}
	hideSection('project'+visiblesection);
	visiblesection--;
	showSection('project'+visiblesection);
}

function showSection(sectionid) {
   if (ajej)  document.getElementById(sectionid).style.display = "block";
   if (necky) document.getElementById(sectionid).style.setProperty("display", "block", "");
}

function hideSection(sectionid) {
   if(sectionid) {
	   if (ajej)  document.getElementById(sectionid).style.display = "none";
	   if (necky) document.getElementById(sectionid).style.setProperty("display", "none", "");
   }
}

// services
function showService(serviceid) {
	hideSection('service'+visiblesection);
	document.getElementById('menuli'+visiblesection).className = "li";
	visiblesection = serviceid;
	showSection('service'+visiblesection);
	document.getElementById('menuli'+visiblesection).className = "li2";
}

function switchPhoto(canvas) {
	photocounter++;
	if (photocounter <= totalphotos)
		changeElementBg('deco0'+canvas,'url(/images/photos'+photo[photocounter]+') no-repeat');
}

function initializePhoto() {
	switchPhoto(1);
	switchPhoto(2);
	switchPhoto(3);
	//changeElementBg('deco01',"url('/alhig/images/photos" + photo[1] + "') no-repeat;");
}
// projects
function showProject(categoryid,projectid) {
	hideSection('chooser'+categoryid);
	hideSection('nav'+categoryid);
	showSection('project'+projectid);
}

function hideProject(categoryid,projectid) {
	showSection('chooser'+categoryid);
	hideSection('project'+projectid);
}

function switchSection(sectionid) {
	if (document.getElementById(sectionid).style.display == "block") {
		hideSection(sectionid);
	} else {
		hideSection('nav1');
		hideSection('nav2');
		hideSection('nav3');
		showSection(sectionid);
	}
}
