var cDate = new Date();
var hrs = cDate.getHours();
var theme = getTheme(hrs);

var browser = navigator;
var browserName = browser.appName;
var browserVersion = browser.userAgent;
var stringToCheck = browserVersion;
var IE6 = IE("MSIE 6.0");
var IE7 = IE("MSIE 7.0");
var version = String;

var basicCloudWidth;
var cloudWidth = basicCloudWidth = 110;
var posX = -(cloudWidth);

var width = getWidth();
var scrollWidth = width + cloudWidth;
var page;

var id = String;;
var tagName = String;;
var i = 0;

var cloudMoving = false;

//_____________________________ Asset functions ________________________________________________________//

// *** getElementById
function getID(id)
{
	return document.getElementById(id);
}

// *** getElementByTagName
function getTN(tagName) 
{
	return document.getElementsByTagName(tagName)[0];
}

// *** check browser if Microsoft Internet Explorer 6.0 
function IE(version)
{
	if (browserName == "Microsoft Internet Explorer" && stringToCheck.indexOf(version) > -1) 
	{
		return true;
	}
	else
	{
		return false;
	}
}

// *** check browser if Opera
function opera(browserName)
{
	if (browserName == "Opera")
	{
//		alert("Opera");
		return true;
	}
}
//opera(browserName);
// *** This is because IE7 does not repaint total area of screen when stylesheet is switched
// *** This is used only with Microsoft Internet Explorer 7.0

function pageRepaint()
{
	page = getTN("body");
	page.style.display = "none";
	page.style.display = "block";
//	alert("repainting");
}

// *** Used for passing time to setTheme() function for setting appropriate theme
function getTheme(hrs)
{
	if (hrs >= 8 && hrs <= 16)
		{
			return "day";
		}
	if (hrs >= 17 && hrs <= 19)
		{
			return "dusk";
		}
	if (hrs >= 20 && hrs <= 23 || hrs >= 0 && hrs <= 4 )
		{
			return "night";
		}
	if (hrs >= 5 && hrs <= 7)
		{
			return "dawn";
		}
}

// *** Used for passing width for scrolling to moveScroller () function
function getWidth()
{
	var w = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
	}
	return w;
}

//_____________________________ Working functions ________________________________________________________//

function moveCloud()
{
	var cloud = getID("scroll");
	
	if (i < scrollWidth)
	{
		i ++;

		if (posX >= width - cloudWidth)
		{
			cloudWidth --;
			posX ++;
			cloud.style.width = (cloudWidth + "px");
			cloud.style.left = (posX + "px");
		}
		else
		{
			cloudWidth = basicCloudWidth;
			posX ++;
			cloud.style.width = (cloudWidth + "px");
			cloud.style.left = (posX + "px");
		}
	
		setTimeout('moveCloud()',20);
	}
	else
	{
		i = 0;
		posX = -basicCloudWidth;
		setTimeout('moveCloud()',20);
	}
	
	return cloudMoving = true;
}

/*
function stopCloud()
{
	clearTimeout(moveCloud());	
}
*/

// seting contents of bookmark links in opera
var topPos;
var contentHeight = 300;

function setContents(linkNo)
{
	//alert(linkNo);
	if (opera(browserName))
	{
		var contentsWrapper = document.getElementById('contents-wrapper');
		contentsWrapper.style.position = "relative";
	
		topPos = linkNo * contentHeight;
		//alert("in if");		
		contentsWrapper.style.position = "relative";
		contentsWrapper.style.top = -(topPos) + "px";
		//alert("here");
	}
}

function getFlashMovieObject(movieName)
{
	  if (window.document[movieName]) 
	  {
			return window.document[movieName];
	  }
	  if (navigator.appName.indexOf("Microsoft Internet")==-1)
	  {
			if (document.embeds && document.embeds[movieName])
				return document.embeds[movieName]; 
	  }
	  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	  {
			return document.getElementById(movieName);
	  }
}

var themeMusic = ["/mp3/day.mp3", "/mp3/dusk.mp3", "/mp3/night.mp3", "/mp3/dawn.mp3"];

function setThemeMusic(theme)
{
	var swfId = getFlashMovieObject("bgSound");
	swfId.setMP3(theme);
//confirm(swfId);
	
/*	switch(theme)
	{
		case "day":		swfId.setMP3(themeMusic[0]);
						break;
		case "night":	swfId.setMP3(themeMusic[1]);
						break;
		case "dusk":	swfId.setMP3(themeMusic[1]);
						break;
		case "dawn":	swfId.setMP3(themeMusic[1]);
						break;						
	}*/
//	alert("here");
}

function setTheme(theme)
{
		switch(theme)
		{
			case "day":	getID("currentCss").href = "/css/day.css";
							/*if (IE7)
							{
								pageRepaint();
							}*/
							if (IE6)
							{
//								getID("wrapper").style.filter = "none";
								getID("scroll").style.background = "none";
								getID("scroll").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/day/cloud.png');";
								//getID("bottom").style.background = "none";
								//getID("bottom").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/day/land_day.png');";
							}
							if (!cloudMoving)
							{
								moveCloud();
								//alert("called");
							}
							//setThemeMusic(themeMusic[0]);
							//** commented on 21-12-2009 setTimeout('setThemeMusic(themeMusic[0])', 3000);
							break;
			case "dusk":	getID("currentCss").href = "/css/dusk.css";
							/*if (IE7)
							{
								pageRepaint();
							}*/
							if (IE6)
							{
//								getID("wrapper").style.filter = "none";								
								getID("scroll").style.filter = "none";
								//getID("bottom").style.background = "none";
								//getID("bottom").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/dusk/land_dusk.png');";								
							}
							//stopCloud();
							//** commented on 21-12-2009 setTimeout('setThemeMusic(themeMusic[1])', 3000);
							break;
			case "night":	getID("currentCss").href = "/css/night.css";
							/*if (IE7)
							{
								pageRepaint();
							}*/
							if (IE6)
							{
								getID("scroll").style.filter = "none";
								//getID("bottom").style.background = "none";
								//getID("bottom").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/night/land_night.png');";
//								getID("wrapper").style.background = "none";
//								//getID("wrapper").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/night/moon_stars.png',sizingMethod='crop');";
							}
							//stopCloud();
							//setThemeMusic(themeMusic[1]);
							//** commented on 21-12-2009 setTimeout('setThemeMusic(themeMusic[2])', 3000);
							break;
			case "dawn":	getID("currentCss").href = "/css/dawn.css";
							/*if (IE7)
							{
								pageRepaint();
							}*/
							if (IE6)
							{
//								getID("wrapper").style.filter = "none";								
								getID("scroll").style.filter = "none";
								//getID("bottom").style.background = "none";
								//getID("bottom").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/dawn/land_dawn.png');";								
							}
							//stopCloud();
							//** commented on 21-12-2009 setTimeout('setThemeMusic(themeMusic[3])', 3000);							
							break;
		}
		//setTimeout('setThemeMusic(theme)', 3000);
		//setThemeMusic(theme);
}
