﻿var tempHtml;
var tempStr1;
var tempStr2;
if (section == null)	var section = 0;
if (level1 == null)	var level1 = "";
if (level2 == null)	var level2 = "";
if (level3 == null)	var level3 = "";
if (selectArray == null)	var selectArray = null;
var id1 = null;
var id2 = null;
var id3 = null;

	var InputTipJS = {
                    /**
                    * Register tip for the input field
                    * @param inputField INPUT DOM Object
                    * @param tipText Tip text
                    */
                   registerInput : function(inputField, tipText) {
                       if(inputField != null) {
                           inputField.setAttribute("tip", tipText);
                           inputField.setAttribute("valid", "false");
                           inputField.value = tipText;

                           inputField.onclick = new InputTipJS.clickHandler();
                           inputField.onblur = new InputTipJS.blurHandler();
                           inputField.onchange = new InputTipJS.changeHandler();
                       }
                   },

                   /**
                    * Unregister tip for the input field
                    * @param inputField INPUT DOM Object
                    */
                   unregisterInput : function() {
                       // There's no needs to use that handler
                   },

                   /**
                    * Click inline handler
                    */
                   clickHandler : function() {
                       return function() {
                           var isValid = this.getAttribute("valid");
                           if(isValid == "false") {
                               this.value = "";
                           }
                       };
                   },

                   /**
                    * Blur inline handler
                    */
                   blurHandler : function() {
                       return function() {
                           var isValid = this.getAttribute("valid");
                           if(this.value == "") {
                               isValid = "false";
                               this.setAttribute("valid", "false");
                           }
                           if(isValid == "false") {
                               this.value = this.getAttribute("tip");
                           }
                       }
                   },

                   /**
                    * Change inline handler
                    */
                   changeHandler : function() {
                       return function() {
                           var isValid = this.getAttribute("valid");
                           if(isValid == "false") {
                               this.setAttribute("valid", "true");
                           }
                       }
                   }
                }


getLevel();
genId();


function getLevel() {
	var link = location.href.toString();
	var obj = sectionArray[section];
	
	if (level1 == "") {
		for (var i=0; i<obj.length; i++) {
			if (link.indexOf(("/" + obj[i].id + "/")) > -1) {
				level1 = obj[i].id;
				
				if (level2 == "" && obj[i].subSection) {
					var obj1 = obj[i].subSection;
					
					for (var j=0; j<obj1.length; j++) {
						if (link.indexOf((obj1[j].id)) > -1) {
							level2 = obj1[j].id;
							
							if (level3 == "" && obj1[j].subSection) {
								var obj2 = obj1[j].subSection;
								
								for (var k=0; k<obj2.length; k++) {
									if (link.indexOf((obj2[k].id)) > -1) {
										level3 = obj2[k].id;
										
										break;
									}
								}
							} else {
								break;
							}
						}
					}
				} else {
					break;
				}
			}
		}
	}	
	
//	alert("level2: "+level2);
}


function genId() {	
	var obj = sectionArray[section];
	
	if (level1 != "") {
		for (var i=0; i<obj.length; i++) {
			//alert(obj[i].id + "  " + level1);
			if (obj[i].id == level1) {
				id1 = i;
				
				if (level2 != "") {
					var obj1 = obj[i].subSection;
					for (var j=0; j<obj1.length; j++) {
						//alert(obj[i].id + "  " + level1);
						if (obj1[j].id == level2) {
							id2 = j;
							
							if (level3 != "") {
								var obj2 = obj1[j].subSection;
								for (var k=0; k<obj2.length; k++) {
									//alert(obj[i].id + "  " + level1);
									if (obj2[k].id == level3) {
										id3 = k;
										break;
									}
								}
							} else {
								break;
							}
						}
					}
				} else {
					break;
				}
			}
		}
	}
//window.status = ("id1: "+id1+"   id2: "+id2+"   id3: "+id3);
}


function genTop() {
	var isSect;
	var sect = 0;
	var obj = sectionArray[sect];
	tempHtml = '';
	tempHtml += '<div id="mainNavContiner">';
	tempHtml += '	<div id="mainNav" class="clearfix">';
	
	
	for (var i=0; i<obj.length; i++) {
		if (sect == section && (id1)== i) {
			isSect = 1;
			var navBtn = document.getElementById('nav_'+id1);
			navBtn.src = path + 'images/nav/nav_'+obj[i].id+'_over.gif';
		} else {
			isSect = 0;
		}
		
		if (id1 == "home") {
			isSect = 1;
			tempStr1 = "_over";
		}
			genMenu(i, isSect);
		//alert(id1);
	}
	
	if (id1>0) 
	{
		var sectsub = document.getElementById(id1+'_submenu');
		
		if (!sectsub)	return;
		sectsub.style.visibility = 'visible';
		sectsub.style.top = '0'+'px';
		sectsub.style.zIndex = '0';
	}
}

var menuH = 40;
function genMenu(i, isSect) {
	var sect = 0;
	var obj = sectionArray[sect];
	var total = obj.length;
	
		if (obj[i].subSection) {
			var obj1 = obj[i].subSection;
			
				for (var j=0; j<obj1.length; j++) {
					if (sect == section && (id1)== i && (id2)== j) {
						isSect = 1;
						var subnavBtn = document.getElementById('subnav_'+id1+'_'+id2);
						subnavBtn.src = path + 'images/nav/subnav_'+obj1[j].id+'_over.gif';
					} else {
						isSect = 0;
						tempStr1 = "";
					}
					//alert('subnav_'+id1+id2);
				}
		}
}

function genLink(i) {
	if ((i.indexOf('javascript') > -1) | (i.indexOf('http') > -1) | (i.indexOf('#') > -1)) {
		var link = i;
	} else {
		var link = path + i;
	}
	
	return link;
}

var maskDiv;
var layer;


function navOver(i, over, isSect) {
	var sect = 0;
	var obj = sectionArray[sect];
	var btn = document.getElementById('nav_'+i);
	
	//alert(id1);
	if (i == id1) return;
	
	
	if (document.getElementById(i+'_submenu')) {
		var layer = document.getElementById(i+'_submenu');
		maskDiv = document.getElementById('mask_'+i);
	}
	
	if (over == 1) {
		if (!isSect)	btn.src = path + 'images/nav/nav_'+obj[i].id+'_over.gif';
		
		if (layer)	menuGo(i, 1);
		btn.hit = true;
	} else {
		if (!isSect)	setTimeout(function(){if (!	btn.hit)	btn.src = path + 'images/nav/nav_'+obj[i].id+'.gif'}, 200);
		
		if (layer)	btn.timeOut = setTimeout(function(){if (!	btn.hit)	menuGo(i, 0);}, 200);
		btn.hit = false;
	}
}

var goSpeed = 10;
var speed;
var goStep;
var timeOut;
var objTop;
var tempTop;

var timeOutSpeed = 25;
var z = 1;

function menuGo(i, over)
{
	var btn = document.getElementById('nav_'+i);
	var layer = document.getElementById(i+'_submenu');
	layer.menuMotion = menuMotion;
	
	if (over)
	{
		if (layer)	layer.style.visibility = 'visible';
		layer.tempTop = 0;
		layer.speed = 5;
		layer.style.zIndex = z++;
		layer.menuMotion(layer);
	}
	else
	{
		if (layer.hit | btn.hit)	return;
		layer.tempTop = -menuH;
		layer.speed = 2;
		layer.menuMotion(layer);
	}
}
	
function menuMotion(layer)
{
	if (isIE)
	{
		layer.objTop = Number(layer.style.pixelTop);
	}
	else
	{
		layer.objTop = Number(layer.style.top.substring(0, (layer.style.top.toString().length-2)));
	}
	layer.goStep = (layer.tempTop - layer.objTop)/layer.speed;
	
	if (!(Math.abs(layer.objTop - layer.tempTop) < 1))
	{
		layer.objTop += layer.goStep;
		var timeOut = setTimeout(function(){layer.menuMotion(layer);}, timeOutSpeed);
	}
	else
	{
		layer.objTop = layer.tempTop;
		clearTimeout(timeOut);
	}
	
//	window.status = layer.objTop;
	layer.style.top = layer.objTop + 'px';
}

function genLeft() {
	tempHtml = '';
	tempHtml += '	<div class="leftImgGran"><img src="'+path+'images/left_gran.gif" alt="Gran Casino Theatre, Mallorca" /></div>';
	tempHtml += '			<div class="leftImgBroadway"><img src="'+path+'images/left_broadway.gif" alt="Broadway Come to Mallorca" /></div>';
	tempHtml += '			<div class="leftImgLive"><img src="'+path+'images/left_live.gif" alt="Live on Stage at The Gran Casino Theatre Experience an Unforgettable Mix of Swing Music, World Class Acrobatics and Dancing" /></div>';
	tempHtml += '			<div class="leftImgStarring"><img src="'+path+'images/left_starring.gif" alt="Starring acclaimed vocalist Chris Mann" /></div>';
	tempHtml += '			<div class="leftImgExclusive"><img src="'+path+'images/left_exclusive.gif" alt="Exclusive" /></div>';
	tempHtml += '			<div class="leftImgCirque"><img src="'+path+'images/left_cirque.gif" alt="“It’s Cirqur Meets Sinatra”" /></div>';
	tempHtml += '			<div class="leftImgFrank"><img src="'+path+'images/left_frank.gif" alt="Frank Leavers, Radio Calvia" /></div>';
	document.write(tempHtml);
}

function genFooter() {
	tempHtml = '';
	tempHtml += '	<div id="footerContainer" class="clearfix">';
	tempHtml += '		<div class="footerFlash">';
	
	innerFlash("images/swf/footer.swf", 198, 91, "footer", "");
	
	tempHtml += '		</div>';
	tempHtml += '		<div class="footerRight">';
	tempHtml += '			<div class="footerImg"><img src="'+path+'images/footer_img.gif" alt="Gran Casino Theatre, Sol de Mallorca" /></div>';
	tempHtml += '			<div class="footerBtm">';
	tempHtml += '				<div class="footerContent">';
	tempHtml += '					<div class="footerCredit">Directed by Martyn Smith &bull; Music by Paul McKeown</div>';
	tempHtml += '					<div><a href="'+path+'show/casting.html">Casting</a> | <a href="'+path+'show/others.html">Other Shows</a> | <a href="'+path+'show/sponsorship.html">Sponsorship</a> | <a href="'+path+'show/sitemap.html">Site Map</a> | <a href="'+path+'show/contactus.html">Contact Us</a></div>';
	tempHtml += '				</div>';
	tempHtml += '				<div class="footerSponsor">Presented by</div>';
	tempHtml += '				<div class="footerLogo"><img src="'+path+'images/footer_logo.gif" alt="Globo Balear" /></div>';
	tempHtml += '			</div>';
	tempHtml += '		</div>';
	tempHtml += '	</div>';
	document.write(tempHtml);
}

function genNewsMenu() {
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	//alert("sPage: "+sPage);
	var menu = document.getElementById('menu');
	var option = menu.getElementsByTagName('option');
	for (var i=0; i<option.length; i++)
	{
		option[i].value;
		if (sPage == option[i].value)
		{
			option[i].selected = true;
			//alert(option[i].select);
		}
	}
}


