var selectedTile="c_box red";
var current_flash;
function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	var theName = navigator.userAgent;
	

	if (theWidth >= 1200)
	{		
		setStylesheet("Layout 1280x1024");
	}
	else if (theWidth < 1200) 
	{
		setStylesheet("Layout 800x600");
	}
	
	return true;
}
function setFlashMovie(lang)
{
	var theWidth = getBrowserWidth();
	var theName = navigator.userAgent;
	

	if (theWidth >= 1200 && current_flash!=2)
	{		
			current_flash=2;
			//setStylesheet("Layout 1280x1024");
			if (document.getElementById("flash")) {
			document.getElementById("flash").innerHTML=AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','900','height','570','src','f/home_1280_' + lang + '.swf','quality','high','wmode', 'transparent','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','f/home_1280_' + lang + '.swf', 'wmode', 'transparent');
			}
	}
	else if (theWidth < 1200 && current_flash!=1) 
	{
		current_flash=1;
		//setStylesheet("Layout 800x600");
		if (document.getElementById("flash")) {
		document.getElementById("flash").innerHTML=AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','735','height','460','src','f/home_' + lang + '.swf','quality','high','wmode', 'transparent','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','f/home_' + lang + '.swf', 'wmode', 'transparent');
		}
	}
	
	return true;
}
function setColumnHeights(auto)
{
	var theFeature2 = document.getElementById("feature2Inner");
	var theFeature3 = document.getElementById("feature3Inner");
	var theFeature4 = document.getElementById("feature4Inner");
	var theHeight = "auto";

	if (!auto)
	{
		theHeight = parseInt(theFeature2.scrollHeight);

		if (theFeature3 && theFeature3.scrollHeight > theHeight)
		{
			theHeight = parseInt(theFeature3.scrollHeight);
		}

		if (theFeature4 && theFeature4.scrollHeight > theHeight)
		{
			theHeight = parseInt(theFeature4.scrollHeight);
		}

		theHeight += "px";
	}

	theFeature2.style.height = theHeight;
	theFeature3.style.height = theHeight;
	theFeature4.style.height = theHeight;
	
	return true;
}
function setStylesheet(styleTitle) {
	var currTags = document.getElementsByTagName("link");
	for (var i=0; i<currTags.length; i++) {
			var currTag = currTags[i];
			if (currTag.getAttribute("rel") && currTag.getAttribute("rel") == "alternate stylesheet") {
				if(currTag.getAttribute("title") != null || currTag.getAttribute("title") != undefined) {
					currTag.disabled = true;
				
					if(currTag.getAttribute("title") == styleTitle) {					
						currTag.disabled = false;
					}
				}
			}
	}
	
	return true;
}

function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
}



function clearInputDefault(text,obj)
 {

	 if (text==obj.value) {
		obj.value="";
		obj.className="";
	 } else {
		 obj.select();
	 }

 }
 function clearInputDefault2(text,obj)
 {
	 if (obj.value=="") {
		 obj.className="noteText";
		 obj.value=text;
	 }

 }

function preloadImg()
 {
	var link_array=document.getElementsByTagName("a");
	var hidden_cunter=0;
	var div_array=new Array;
	for (i=0; i<link_array.length ; i++) {
		if (link_array[i].className == "preload") {
			
			eval ("pp_"+i+"=link_array[i].getElementsByTagName(\"img\")");
			eval ("pp_"+i+"[0].setAttribute(\"id\", \"name"+i+"\")");

			var img_name_over=eval ("pp_"+i+"[0].getAttribute('src').replace(/.jpg/,'_c.jpg')");
			var img_name=eval ("pp_"+i+"[0].getAttribute('src')");
			eval ("img_"+i+"=new Image");
			eval ("img_"+i+"_over=new Image");

			eval ("img_"+i+"_over.src='"+img_name_over+"'");
			eval ("img_"+i+".src='"+img_name+"'");
			div_array[hidden_cunter]=link_array[i].parentNode;
			hidden_cunter++;
			if (link_array[i].parentNode.getElementsByTagName("p").length>0) {
				link_array[i].parentNode.getElementsByTagName("p")[0].style.display="none";
			}
			link_array[i].onmouseover= function () {
				if (this.parentNode.getElementsByTagName("p").length>0) {
					this.parentNode.getElementsByTagName("p")[0].style.display="";
				}
				var img_object=this.getElementsByTagName("img");
				var img_id=img_object[0].getAttribute("id").substring(4);
				eval ("document.getElementById(\"name"+img_id+"\").src=img_"+img_id+"_over.src");


		}
			link_array[i].onmouseout= function() {
				if (this.parentNode.getElementsByTagName("p").length>0) {
					this.parentNode.getElementsByTagName("p")[0].style.display="none";
				}
				var img_object=this.getElementsByTagName("img");
				var img_id=img_object[0].getAttribute("id").substring(4);
				eval ("document.getElementById(\"name"+img_id+"\").src=img_"+img_id+".src");
		}
			

		}
	}
	return div_array;
 }
 
 function writeControls(visible,startImg)
 {
	var dArray= new Array;
	dArray=preloadImg();
	var pageNumber=Math.ceil(dArray.length/visible);
	document.getElementById("p_number").innerHTML="";
	for (p=0; p<pageNumber ; p++) {
		if (startImg/visible==p) {
			document.getElementById("p_number").innerHTML=document.getElementById("p_number").innerHTML+"<p>"+(p+1)+"</p>";
		} else {
			document.getElementById("p_number").innerHTML=document.getElementById("p_number").innerHTML+"<a  href=\"#\" onClick=\"writeControls("+visible+","+(p*visible)+"); return false;\">"+(p+1)+"</a>";
		}
	}

	var endImg=startImg+visible;
	for (r=0; r<dArray.length ; r++) {
	 if (r<=startImg-1 || r >endImg-1) {
		dArray[r].style.display="none";
	 } else {
		 dArray[r].style.display="";
	 }
	} 
 }

//window.resize = checkBrowserWidth;



function preloadColorTileImg(listName,element,imgId,path,cont,roolout,returnFalse)
 {
	var p_array=document.getElementById(listName).getElementsByTagName(element);

	for (i=0; i<p_array.length ; i++) {
		
			p_array[i].setAttribute("id",i);
			eval ("img_"+listName+"_"+i+"=new Image");
			var imgSrc = document.getElementById(imgId).src;
			var imgType = imgSrc.substr(imgSrc.lastIndexOf('.'), imgSrc.length)
			//alert(imgType);
			eval ("img_"+listName+"_"+i+".src='"+path+"_"+(i+1)+imgType+"'");
			p_array[i].onmouseover= function () {
				var over_img=this.getAttribute("id");
				eval ("document.getElementById('"+imgId+"').src=img_"+listName+"_"+over_img+".src");
				if (element=="a") {
					link_array=document.getElementById(listName).parentNode.getElementsByTagName(element)
					for (r=0; r<link_array.length ; r++) {
						//alert (p_array.length);
						link_array[r].style.color="";	
					}
					this.style.color="#C81619";	
			
				}
					if (listName=="tile_color" && this.parentNode.className!="select") {
						//alert (this.className);
							var li_array=document.getElementById(listName).getElementsByTagName("li");
							for (r=1; r<li_array.length ; r++) {
								li_array[r].className="";
							}
							this.parentNode.className="over";
					}
				
		}
		if (roolout) (
			p_array[i].onmouseout= function() {
				var over_img=this.getAttribute("id");
				document.getElementById(imgId).src=document.getElementById(cont).value;	
				if (listName=="tile_color" && this.parentNode.className=="over") {
							var li_array=document.getElementById(listName).getElementsByTagName("p");
							for (r=0; r<li_array.length ; r++) {
								li_array[r].parentNode.className="";
								if (li_array[r].className==selectedTile) {
									li_array[r].parentNode.className="over";
									}
							}
				}
			}
		)
			
			p_array[i].onclick= function() {
				if (listName=="tile_color") {
					var li_array=document.getElementById(listName).getElementsByTagName("li");
					for (r=1; r<li_array.length ; r++) {
						li_array[r].className="";
					}
					this.parentNode.className="select";
					selectedTile=this.className;
				}

								
				
				var over_img=this.getAttribute("id");
				eval ("document.getElementById('"+cont+"').value=img_"+listName+"_"+over_img+".src");
			if (returnFalse) {	
				return false;
			}
				
			}
			

	}
 }
function change_img (img,id) {
	document.getElementById(id).src=img;
}
var lastLocation = null;
function showLocation(id_name, class_name) {
	
	if(lastLocation != null) {
		document.getElementById(lastLocation).style.display = "none";
	}
	
	if(document.getElementById(id_name)) {
		document.getElementById(id_name).style.display = "block";
		lastLocation = id_name;
		var city = document.getElementById('location_dd');
		var theMap = document.getElementById("locationMap");
		var prefix = theMap.src.substring(0, theMap.src.lastIndexOf("/")+1);
		var suffix = theMap.src.substring(theMap.src.lastIndexOf("."), theMap.src.length);
		theMap.src = prefix+city[class_name].className+suffix;
	}
}
window.onload = function () {
	checkBrowserWidth();
	
}
window.onresize = function () {
	//setFlashMovie();
	checkBrowserWidth();
}
