var intervalID;

window.onscroll = onScroll;
window.onresize = doResize;

function onScroll() {
	
	document.getElementById('i_div').style.top=(document.documentElement.scrollTop >= document.body.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px";
}
function doResize() {
	
	document.getElementById('s_div').style.height=(document.documentElement.scrollHeight >= document.body.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + "px";
	
}

function ChangeHeight (elementId, newHeight) {
	intervalID = setInterval(function () { ChangeHeightRepeat(elementId, newHeight) },500);
}

function ChangeHeightRepeat(elementId, newHeight) {
	var currentHeight = document.getElementById(elementId).clientHeight;
	if (currentHeight < newHeight) {
		var setHeight = currentHeight + 1;
		document.getElementById(elementId).style.height=setHeight;
	}
	if (currentHeight == newHeight) {
		clearInterval(intervalID);
		alert("stop");
	}
}

function ShowImage(img_src) {
					onScroll()
					doResize();
    			document.getElementById('s_div').style.display='inline';
    			document.getElementById('i_div').style.display='inline';
    			document.getElementById('s_img').src=img_src;
			}
function HideImage(img_div) {
				document.getElementById('s_div').style.display='none';
				document.getElementById('i_div').style.display='none';	
			}
	


function timer(time_var, time_target) {
		  time_to_end = document.getElementById(time_var).value;
		  if (time_to_end >= 0) {
				time(time_to_end, time_target);
				time_to_end_new= parseInt(time_to_end) - 1;
			  document.getElementById(time_var).value = time_to_end_new;
			  
			  if (time_to_end_new < 44 && time_to_end_new >= 19) document.getElementById(time_target).className = "timer2";
			  if (time_to_end_new < 19) document.getElementById(time_target).className = "timer3";
			
				if (time_to_end > 0) timerID = setTimeout(function() { timer(time_var, time_target); },1000);
				else document.location.reload(true);
		  }
}

function ClearTimerTimeout() {
	
	if (typeof timerID == "number") clearTimeout(timerID);
	
}

function time(sec,target){
      target=document.getElementById(target);
      minutes=Math.floor((sec%3600)/60);
      seconds=pad((sec%3600)%60);
      target.innerHTML=minutes + ":" + seconds;
}
   
function pad(num){
       num=num+"";
       if(num.length==1){
           num="0" + num;
       }
       return num;   
}