/*
 * This object will generate 4 quotes and retrieve 1 quote randomley everytime its called
 */
var quoteRandomizer = 
{
	getQuote: function(populate){
		var data = new Array("Superb, Really Useful...", "I love this feature...", "The functionality ... is outstanding", "This is an awesome tool...");
		var randomNumber = Math.floor(Math.random() * 4);
		populate.innerHTML = data[randomNumber];
	},
	getLondonQuote: function(populate){
		var data = new Array("Superb, Really Useful<br/>And Easy To Use", "I love this feature...", "The functionality ... is outstanding", "This is an awesome tool...");
		var randomNumber = Math.floor(Math.random() * 4);
		populate.innerHTML = data[randomNumber];
	}
}
	
var PageCurl = {
	rollDown : function(){
		var movie = document.getElementById('movie');
		//document.getElementById('small').style.top = "-100000px";
		//document.getElementById('large').style.top = "0px";
		document.getElementById('small').style.zIndex = '0'; 
		if(movie != null){
			movie.style.zIndex = '0';
		}
		document.getElementById('large').style.zIndex = '99';
		document.getElementById('large').style.display = 'block';
		
	},
	rollUp : function(){
		var movie = document.getElementById('movie');
		//document.getElementById('large').style.top = "-100000px";
		//document.getElementById('small').style.top = "0px";
		document.getElementById('small').style.zIndex = '99';
		if(movie != null){
			movie.style.zIndex = '99'; 
		}
		document.getElementById('large').style.zIndex = '0';
		document.getElementById('large').style.display = 'none';
	}
}


function rollDown(){
	document.getElementById('small').style.top = "-1000px";
	document.getElementById('large').style.top = "0px";	
}

function rollUp(){
	document.getElementById('large').style.top = "-1000px";
	document.getElementById('small').style.top = "0px";
}

var PositionFlash = {
	windowSize : function(){
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
		}
		return myWidth;
	},
	
	getScrollBarWidth : function() {
		var myWidth = 0;
		
		var inner = document.createElement('p');
		inner.style.width = "100%";
		inner.style.height = "200px";
		
		var outer = document.createElement('div');
		outer.style.position = "absolute";
		outer.style.top = "0px";
		outer.style.left = "0px";
		outer.style.visibility = "hidden";
		outer.style.width = "200px";
		outer.style.height = "150px";
		outer.style.overflow = "hidden";
		outer.appendChild(inner);
		document.body.appendChild(outer);
		
		var w1 = inner.offsetWidth;
		outer.style.overflow = 'scroll';
		var w2 = inner.offsetWidth;
		
		if (w1 == w2){
			if( typeof( outer.innerWidth ) == 'number' ) {
				myWidth = outer.innerWidth;
			} else if(outer.clientWidth) {
				myWidth = outer.clientWidth;
			} else if(window.navigator.appName.indexOf('Opera') > -1){
				myWidth -= 20;	
			}
			w2 = myWidth;
		}
		
		document.body.removeChild (outer);
		
		return (w1 - w2);
	},	
	posSmall : function(flashwidth){
		if(document.all){
			var screenwidth = PositionFlash.windowSize() - flashwidth;
			if(screenwidth <= contentWidth){
				document.getElementById('small').style.display = 'none';
			} else {
				document.getElementById('small').style.display = 'block';
				document.getElementById('small').style.left = (PositionFlash.windowSize() - flashwidth) + "px";
			}
		} else {
			var screenwidth = (PositionFlash.windowSize() - PositionFlash.getScrollBarWidth()) - flashwidth;
			if(screenwidth <= contentWidth){
				document.getElementById('small').style.display = 'none';
			} else {
				document.getElementById('small').style.display = 'block';
				document.getElementById('small').style.left = ((PositionFlash.windowSize() - PositionFlash.getScrollBarWidth()) - flashwidth) + "px";
			}
		}

	},
	posLarge : function(flashwidth){
		if(document.all){
			var screenwidth = PositionFlash.windowSize() - flashwidth;
				document.getElementById('large').style.display = 'block';
				document.getElementById('large').style.left = (PositionFlash.windowSize() - flashwidth) + "px";
		} else {
			var screenwidth = PositionFlash.windowSize() - flashwidth;
				document.getElementById('large').style.display = 'block';
				document.getElementById('large').style.left = ((PositionFlash.windowSize() - PositionFlash.getScrollBarWidth()) - flashwidth) + "px";
		}
	}
}

var SwitchLogin = {
	getHeight : function(height){
		if(height.indexOf('px')){
			return height.substring(0, height.length - 2);
		} else {
			return height;
		}
	},
	animateDropDown : function(login, originalHeight, exclusiveimage){
		if(parseInt(this.getHeight(login.style.height)) < parseInt(originalHeight)){
			setTimeout(
							function(){
								login.style.height = (parseInt(SwitchLogin.getHeight(login.style.height)) + 9) + "px";
								SwitchLogin.animateDropDown(login, originalHeight, exclusiveimage);
							}, 5
					   )
		} else {
			exclusiveimage.src = "/images/exclusive2.png";
		}
	},animateDropUp : function(login, wrapper, topbar, exclusiveimage){
		if(this.getHeight(login.style.height) > 0){
			setTimeout(
							function(){
								login.style.height = (SwitchLogin.getHeight(login.style.height) - 9) + "px";
								SwitchLogin.animateDropUp(login, wrapper, topbar, exclusiveimage);
							}, 5
					   )	
		} else {
			topbar.style.backgroundImage = "url(/images/pagetop.png)";
			wrapper.style.backgroundImage = "url(/images/pagetop.png)";
			exclusiveimage.src = "/images/exclusive.png";
			login.style.display = 'none';
			login.style.height = "54px";
		}
	},
	loginAction : function(login, wrapper, topbar, exclusiveimage){
		if(login.style.display == 'none'){
			topbar.style.backgroundImage = "url(/images/pagetop2.png)";
			wrapper.style.backgroundImage = "url(/images/pagetop2.png)";
			exclusiveimage.src = "/images/exclusive2.png";
			
			var originalHeight = this.getHeight(login.style.height);
			login.style.height = "0px";
			login.style.display = "block";
			this.animateDropDown(login, originalHeight,exclusiveimage);	
		} else {
			this.animateDropUp(login, wrapper, topbar, exclusiveimage);			
		}
	},
	logoutAction : function(){
		var url = "/Objects/SaveVenueMap.php?pageAction=logOut";
		BaseAjaxObject.ajaxinit(url);
	}
}

var RememberMe = {
	setHiddenCheckbox : function(checkboxId,hiddenId) {
		var hidden = document.getElementById(hiddenId);
		var checkbox = document.getElementById(checkboxId);
		if ( checkbox && hidden ) {
			if ( checkbox.checked ) {
				hidden.value = '1';
			} else {
				hidden.value = '';
			}
		}
	}
}

var BaseAjaxObject =
{

	ajaxHandle : null,
	success : false,
	items : null,

	// Ajax Initialiser
	ajaxinit : function( url )
	{
		// Add a random number to avoid pre-caching
		url += (url.indexOf('?') == -1 ? '?' : '&') + "rnd=" + Math.random();

		if ( window.XMLHttpRequest ) {
			BaseAjaxObject.ajaxHandle = new XMLHttpRequest();
		} else if ( window.ActiveXObject ) {
			BaseAjaxObject.ajaxHandle = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			alert("Your browser is not supported");
		}

		if ( BaseAjaxObject.ajaxHandle ) {
			var l = this;
			BaseAjaxObject.ajaxHandle.onreadystatechange = function() {
				l.ajaxReadyStateProcessor.call(l);
			}
			try{
				//searchAjaxIcon(this.fieldInput);
				//alert(url);
				BaseAjaxObject.ajaxHandle.open("GET", url, true);
				BaseAjaxObject.ajaxHandle.send(null);
			} catch (e){
				//alert( "HandleFailure: " +this.ajaxHandle.readyState + "--" + e.message + " -- " + e.lineNumber);
			}
		}
	},

	// Ajax On Ready State Processor
	ajaxReadyStateProcessor : function()
	{
		try
		{
			// alert("HEADERS: " + this.ajaxHandle.getAllResponseHeaders());
			if (BaseAjaxObject.ajaxHandle.readyState == 4 && BaseAjaxObject.ajaxHandle.status == 200)
			{
				try
				{
					if(BaseAjaxObject.ajaxHandle.responseText != ''){
						eval(BaseAjaxObject.ajaxHandle.responseText);
					}

				}
				catch(Exceptisad)
				{
					//alert(Exceptisad.message);
				}
			}
		}
		catch ( exception )
		{
			// alert("READYSTATE: " + this.ajaxHandle.readyState + " - " + exception.message + " -- " + exception.lineNumber);
		}
	}
};