var timer = undefined;

function scroll(dir){
	obj = document.getElementById('newsUvod');

	if(dir == 0){
		obj.scrollTop = obj.scrollTop + 1;
	}else{
		obj.scrollTop = obj.scrollTop - 1;
	}

}
function showObj(id){

	if(document.getElementById(id)){
		document.getElementById(id).style.display = 'block';
		if(document.getElementById(id).className == 'allover'){
			fit(id);
		}
	}

}
function hideObj(id){

	if(document.getElementById(id)){
		document.getElementById(id).style.display = 'none';
	}

}

function switchObj(id){

	if(document.getElementById(id)){
		if(document.getElementById(id).style.display == 'block'){
			hideObj(id);
		}else{
			showObj(id);
		}
	}

}

function fit(id){

	obj = document.getElementById(id);
	obj.style.height = (document.getElementsByTagName("body")[0].offsetHeight) + "px";

}

function playMov(id){

	switchObj('playmov');
	ajax("/iax/mov_fetch/" + id + "/", "playmov");

}
function unload(id){

	obj = document.getElementById(id);
	obj.innerHTML = '<div class="loading"></div>';
	hideObj(id);

}
function ajax(url, loc, classname, anch){

	var oldclass;

     if (url != 0){
        if (window.ActiveXObject){
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else{
          httpRequest = new XMLHttpRequest();
        }

		if(document.getElementById('photo_ajax')){
			document.getElementById('photo_ajax').className = document.getElementById('photo_ajax').className + ' loading';
		}
		if(loc == "IMs"){
			document.getElementById(loc).innerHTML = "";
			oldclass = document.getElementById(loc).className;
			document.getElementById(loc).className = oldclass + " loading";
		}
		if(loc == "botgal"){
			document.getElementById(loc).innerHTML = "";
			oldclass = document.getElementById(loc).className;
			document.getElementById(loc).className = oldclass + " loading_trans";
		}

		httpRequest.open("GET", url, true);
		httpRequest.onreadystatechange= function (){
			processRequest(loc, anch, oldclass);
		};

		httpRequest.send(null);

      }else{

        document.getElementById(loc).innerHTML = "";

      }

}

function processRequest(loc, anch, oldclass){
	if(httpRequest.readyState == 4){
		if(httpRequest.status == 200){

			var mistoZobrazeni = document.getElementById(loc);
			mistoZobrazeni.innerHTML = httpRequest.responseText;
			if(loc == 'IMs'){
				mistoZobrazeni.className = oldclass;
			}
			if(loc == 'botgal'){
				mistoZobrazeni.className = oldclass;
			}

			if(anch){
				//document.location = "#anch";
				document.location = "#"+anch;
			}else{
				//document.location = "#anch";
			}

		}else{
			alert("Chyba pri nacitani stanky" + httpRequest.status + ":" + httpRequest.statusText);
			return false;
		}
	}
}

function slideshow(object, t){
	if(timer || t == 'off'){
		document.getElementById('bottomNavSlideShowImage').src = '/share/pixmaps/lb_slideshowlabel.gif';
		clearInterval(window.timer);
		window.timer = undefined;
	}else{
		document.getElementById('bottomNavSlideShowImage').src = '/share/pixmaps/lb_slideshowlabel_off.gif';
		window.timer = window.setInterval(function(t){return next(object,(object.activeImage + 1),t);}, 8500);
	}
}
function next(object, image){
	if (object.activeImage < (object.imageArray.length-1)){
		object.changeImage(image);
	}else{
		slideshow('', 'off');
	}

}
