// JAVASCRIPT FILE FOR INDEX.PHP
//*******************************

// A J A X   F U N C T I O N S
var timer;
var willDo = 0;
var photoDesc = "";
var photoLink = "";
//var mhttp;


function getRO()
{
	try
	{
		ro = new XMLHttpRequest();
	}
	catch(e1)
	{
		try
		{
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e2)
		{
			try
			{
				ro = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e3){}
		}
	}
	return(ro);
}

function requestXML()
{
	willDo = 0;
	if(timer)
		clearTimeout(timer);

	var mhttp = getRO();
	if(mhttp)
	{
		//alert(1);
		document.getElementById("picDesc").innerHTML = "Loading . .<blink> .</blink>";
		nocachevar = parseInt(Math.random()*9999999999);
		var url = "photos/infoxml.php?nocachevar="+nocachevar;
		mhttp.open("GET", url, true);
		mhttp.onreadystatechange = function(){updateHTML(mhttp);};
		mhttp.send(null);
	}
	else
		location.href="http://igor.tolkov.com";
}


function updateHTML(mhttp)
{
	if(mhttp.readyState==4 && mhttp.status==200)
	{
		willDo = 1;
		var reqData = mhttp.responseXML;

		var data = reqData.getElementsByTagName("data")[0];

		var photo = data.getElementsByTagName("image")[0];

		if(photo.getElementsByTagName("description")[0].firstChild && photo.getElementsByTagName("region")[0].firstChild && photo.getElementsByTagName("region")[0].firstChild.data!="none" && photo.getElementsByTagName("region")[0].firstChild.data!="hidden")
			photoDesc = photo.getElementsByTagName("description")[0].firstChild.data + " <small>("+photo.getElementsByTagName("region")[0].firstChild.data+")</small>";
		else if(photo.getElementsByTagName("description")[0].firstChild)
			photoDesc = photo.getElementsByTagName("description")[0].firstChild.data;
		else if(photo.getElementsByTagName("region")[0].firstChild && photo.getElementsByTagName("region")[0].firstChild.data!="none" && photo.getElementsByTagName("region")[0].firstChild.data!="hidden")
			photoDesc = photo.getElementsByTagName("region")[0].firstChild.data;
		else if(photo.getElementsByTagName("theme")[0].firstChild)
			photoDesc = photo.getElementsByTagName("theme")[0].firstChild.data;
		else if(photo.getElementsByTagName("park")[0].firstChild)
			photoDesc = photo.getElementsByTagName("park")[0].firstChild.data;
		else if(photo.getElementsByTagName("timeLbl")[0].firstChild)
			photoDesc = photo.getElementsByTagName("timeLbl")[0].firstChild.data;

		var photoName = ((photo.getElementsByTagName("name")[0].firstChild)?(photo.getElementsByTagName("name")[0].firstChild.data):"");

		var photoFullUrl = ((photo.getElementsByTagName("url")[0].firstChild && photo.getElementsByTagName("name")[0].firstChild)?(photo.getElementsByTagName("url")[0].firstChild.data + "/" + photo.getElementsByTagName("name")[0].firstChild.data):"");
		document.getElementById("picImage").src=photoFullUrl;

		photoLink = "photos?exit=1&photoId=" + photoName;
	}
}


function setTimer()
{
	if(1)
	{
		var t = window.setTimeout("requestXML()", 5000);
		return(t);
	}
}


function restoreImage()
{
	if(willDo)
	{	document.getElementById("picDesc").innerHTML=photoDesc;
		document.getElementById("picLink").href=photoLink;
	}
	timer = setTimer();
}



// C L O C K   F U N C T I O N S

var days = new Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");


function getDayOfWeek(date)
{
	if(days[date.getDay()] == "Monday")
		return "Sunday";
	else
		return (days[date.getDay()-1]);
}


function printTime()
{
	if(stop)
		document.getElementById("clock").innerHTML = "Clock Stopped by User";
	else
	{
		var date = new Date();
		var clockStr = getDayOfWeek(date) + ", " + (date.getMonth()+1) + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":";
		if(date.getMinutes() < 10)
			clockStr+="0";
		clockStr+=date.getMinutes() + ":";
		if(date.getSeconds() < 10)
			clockStr+="0";
		clockStr+=date.getSeconds();
		document.getElementById("clock").innerHTML = clockStr;
	}
	window.setTimeout("printTime()", 1000);
}



// O T H E R   F U N C T I O N S

function load_images()
{
	var Im1 = new Image();
	var Im2 = new Image();
	var Im3 = new Image();
	var Im4 = new Image();
	Im1.src = "images/homepage/p01.gif";
	Im2.src = "images/homepage/p11.gif";
	Im3.src = "images/homepage/p21.gif";
	Im4.src = "images/homepage/p31.gif";
}


function checkUrl()
{
	if(location.href != "http://igor.tolkov.com/" && location.href != "file:///C:/Documents%20and%20Settings/Igor/Local%20Documents/Web%20page/index.php")
		location.href="http://igor.tolkov.com/";

}


function mouseOn(id)
{
	document.getElementById("p"+id).src="images/homepage/p"+id+"1.gif";
}


function mouseOff(id)
{
	document.getElementById("p"+id).src="images/homepage/p"+id+"0.gif";
}

function click(id)
{
	for(var i=0; i<5; i++)
		document.getElementById("d"+i).style.display = "none";
	document.getElementById("d"+id).style.display = "";
}

function gotoMap(varstr)
{
//	if(window.navigator.appName == "Microsoft Internet Explorer")
//		alert("This feature currently doesn't work in Internet Expolrer");
//	else
		location.href="photos/GMap/GMap3.php?" + varstr;
}

function init()
{
	load_images();
	printTime();

	var i=0;
	while(ancher=document.getElementById("a"+i))
	{
		ancher.href="javascript:void(click("+i+"))";
		i++;
	}
}
