// JavaScript Document

// EDIT THESE VALUES IF REQUIRED
var alertText = 'Are you sure you wish to perform this action' + "\n"; //DEFAULT TEXT DISPLAYED ON CONFIRM BUTTONS/LINKS WHEN NO ALT/TITLE
var newWindowLink = false; //OPEN EXTERNAL LINKS BY DEFAULT IN A NEW WINDOW (TRUE/FALSE)?


var woms = new Array(); //CREATE ARRAY OF FUNCTIONS TO LAUNCH ONLOAD


function datepicker()
{
	if($("#bookingdate").length == 0) return false;
	
	$(function() {
		$("#bookingdate").datepicker({
			showOn: 'button',
			buttonImage: 'images/icon-calendar.png',
			buttonImageOnly: true
		});
	});
}

function fontreplace()
{
	Cufon.replace('h1,h2,h3,.phonenumber');
	Cufon.now(); 
}

function gamezonegallery()
{
	if($("#gamezonegallery").length == 0) return false;

	$("#gamezonegallery li").each(function()
	{
		$(this).click(function()
		{
			var alt = $(this).children().attr('alt');
			var src = $(this).children().attr('src');

			var sourcebits = src.split('/');
			var filename = sourcebits[(sourcebits.length-1)];
			
			var path = 'uploads/images/gamezones/large/' + filename;

			$('#largeimg').attr('alt', alt);
			$('#largeimg').attr('src', path);
			
		});
	});
}

function accordion()
{
	$("#pricingtable .jsnoshow").each(function()
	{
		var id = $(this).attr('id');
		var bits = id.split('_');
		var rowid = bits['1'];
		
		$('#inforow_'+rowid).removeClass("jsnoshow");
		$('#inforow_'+rowid).addClass("noshow");
	});
	
	
	$("#pricingtable tr td .hide-show").each(function()
	{
		$(this).click(function()
		{
			$("#pricingtable .show").each(function()
			{
				var id = $(this).attr('id');
				var bits = id.split('_');
				var rowid = bits['1'];
				
				$('#inforow_'+rowid).removeClass("show");
				$('#inforow_'+rowid).addClass("noshow");
				$('#inforow_'+ rowid).slideUp();
				
				$('#toggle_'+rowid).html('Show Details');
			});
			
			var id = $(this).attr('id');
			var bits = id.split('_');
			var rowid = bits['1'];
			
			$('#inforow_'+rowid).removeClass("noshow");
			$('#inforow_'+rowid).addClass("show");
			$('#inforow_'+ rowid).slideDown();
			
			$('#toggle_'+rowid).html('Details');
			
			return false;
		});
	});
}


function photoscroll(type)
{
	if($("#easyscrollnav").length == 0) return false;

	// id of the container element 
	
	if(type == 'gallery')
	{
		var id = "gamezonegallery";
		var height = 359;
	}
	else
	{
		var id = "thumbImgs";
		var height = 290;
	}

	// movement speed
	var speed = 5;
	
	// desired height of the container element (in pixels)
	
	
	var obj = document.getElementById(id);
	
	obj.up = false;
	obj.down = false;
	obj.fast = false;

	var container = document.createElement("div");
	var parent = obj.parentNode;
	container.id="easyscroll";
	parent.insertBefore(container,obj);
	parent.removeChild(obj);	
	
	container.style.position = "relative";
	container.style.height = height + "px";
	container.style.overflow = "hidden";
	obj.style.position = "absolute";
	obj.style.top = "0";
	obj.style.left = "5";
	container.appendChild(obj);

	document.getElementById('btnUp').onmouseover = function(){
		obj.up = true;
		this.className = "over";
	};
	document.getElementById('btnUp').onmouseout = function(){
		obj.up = false;
		this.className = "";
	};		
	document.getElementById('btnDown').onmouseover = function(){
		obj.down = true;
		this.className = "over";		
	};
	document.getElementById('btnDown').onmouseout = function(){
		obj.down = false;
		this.className = "";
	};		
	document.getElementById('btnUp').onmousedown = document.getElementById('btnDown').onmousedown = function(){
		obj.fast = true;
	};	
	document.getElementById('btnUp').onmouseup = document.getElementById('btnDown').onmouseup = function(){
		obj.fast = false;
	};
	
	this.start = function(){				
		var newTop;
		var objHeight = obj.offsetHeight;
		var top = obj.offsetTop;
		var fast = (obj.fast) ? 2 : 1;
		if(obj.down){		 
			newTop = ((objHeight+top) > height) ? top-(speed*fast) : top;	
			obj.style.top = newTop + "px";
		};	
		if(obj.up){		 
			newTop = (top < 0) ? top+(speed*fast) : top;
			obj.style.top = newTop + "px";
		};
	};	
	obj.interval = setInterval("start()",50);		
		
};


function homepagecats()
{

	if($('#homegalleries').length == 0) return false;
	
	var elementlist = $("#homegalleries").children(); 
		
	elementlist.each(function() 
	{
		$(this).click(function()
		{
			$("#hpImgGallery").html('<img src="images/ajax-loader.gif" alt="Loading" />');
			
			var id = $(this).attr('id');			

			$.post("libs/includes/homepageimg.ajax.php", { 'id': id, 'type':'homepagecategory'},
			function(data){
				 $("#hpImgGallery").html(data);
				 homepagethumbs();
			});

			return false;
		});	
	});

}


function switchimage() 
{  
	
	if( $('#thumbImgs .selected').attr('id') == $('#thumbImgs li').last().attr('id') )
	{
		var id = $('#thumbImgs li').first().attr('id');
	}
	else
	{
		var id = $('#thumbImgs .selected').next().attr('id');
	}
	
	
	$.post("libs/includes/homepageimg.ajax.php", { 'id': id, 'type':'homepageimages'},
	function(data){
		
		$("#thumbImgs .selected").each(function()
		{
			$(this).removeClass("selected");
		});
		
		$("#"+id).addClass("selected");
		
		$("#featureImg").html(data);
	});

	
}

function rotatingimages()
{
	if($("#thumbImgs > li").length > 1)
	{
		window.setInterval('switchimage()', 5000);
	}
}

function homepagethumbs()
{

	if($('#thumbImgs').length == 0) return false;
	
	photoscroll("home");
	
	var elementlist = $("#thumbImgs").children(); 
		
	elementlist.each(function() 
	{
		$(this).click(function()
		{
			
			$("#featureImg").html('<img src="images/ajax-loader.gif" alt="Loading" />');
			var id = $(this).attr('id');			
			
			$.post("libs/includes/homepageimg.ajax.php", { 'id': id, 'type':'homepageimages'},
			function(data){
				
				$("#thumbImgs .selected").each(function()
				{
					$(this).removeClass("selected");
				});
				
				$("#"+id).addClass("selected");
				
				$("#featureImg").html(data);
			});
			return false;
		});	
	});

}

function enlargeimage()
{
	if($('.enlarge').length == 0) return false;
	$('.enlarge').lightBox(); 
}


//ONLOAD MANAGER
function womOn(){
  window.onload = womGo;
}

function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}

function womAdd(func){
  woms[woms.length] = func;
}

function CreateBookmarkLink() {

	title = document.title;
	url = window.location.href;
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");
	} else if(window.external) {
		window.external.AddFavorite( url, title); 
	} else if(window.opera && window.print) {
		return true;
	}
	
}

function objToggle(obj) { 

	var obj = document.getElementById(obj);

	if(obj.style.display == "block") { 
		obj.style.display = "none";
	} else { 
		obj.style.display = "block";
	}

}

function tabs()
{
	if($('#tabs').length == 0) return false;
	$("#tabs").tabs();
}

$(document).ready(
	function ()
	{
		$("#nav").lavaLamp({fx: "backout",speed: 700});
		
		enlargeimage();
	}
);
