// 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

//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 expandMenu(listName) {
	var control=document.getElementById(listName);
	var listElements=control.getElementsByTagName("li");
	
	for(var i=0; i<listElements.length; i++) {
		//EXPAND MENU
		listElements[i].onmouseover=function() {
				var uls=this.getElementsByTagName("ul");
				for(var n=0; n<uls.length; n++) {
					if(n==0) {
						uls[n].style.display="block";
					}
					
				}
			}
		//CLOSE MENU	
		listElements[i].onmouseout=function() {
			var uls=this.getElementsByTagName("ul");
				for(var n=0; n<uls.length; n++) {
					if(n==0) {
						uls[n].style.display="none";
					}
					
				}
		}
	}
}


	/*
		loadMap()
		
		This function is run on page load
		Sets up the default viewing window
		- If the use has clicked on a link to view say, Spain, the lat, lng and zoom can all be fed to the page
		
		@return - n/a
		
	*/
	function loadMap(){

		if (GBrowserIsCompatible()) {

			var lat = 53.97945;
			var lon = -1.52096;
			var zoomlevel = 14;
			zoomlevel = Number(zoomlevel);  // zoom level must be numeric, not string.

			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(lat,lon), zoomlevel);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());

			var latlng = new GLatLng(lat, lon);
			var marker = new GMarker(latlng);
			map.addOverlay(marker);


		}

	}



	function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});
	
		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});
	
		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	

/*
	startup
*/
$(document).ready(function(){

	// if field is empty afterward, add text again
	$('#buyonline').change(function()
	{
		window.open($('#buyonline').val(), '_blank');
	});
	
	if($('#map').length > 0 ){loadMap();}
	
	// select on focus
	$('.autoselect').focus(function()
	{
		$(this).select();
	});
	

	// product rotator
	/*
	if($('#mycarousel').length > 0 ){

		$('#mycarousel').jcarousel({
			auto: 6,
			wrap: 'last',
			scroll: 1,
			initCallback: mycarousel_initCallback
		});

	}*/
	
	if($('#slider').length > 0 ){
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			speed: 1000
		});
	}

	// tabs on homepage
	$("#mytabs").tabs({
	 fx: {
		  opacity: 'toggle',
		  duration: 'fast'
		 }
	 });

});


function loadTBpage(pagename, title){
	tb_show(title,pagename+".html?height=400&width=800");
}