

jQuery.fn.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}



// fadeToggle plugin

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 

// removes html text element and replaces with an image tag
function loadImageHeader(cssClass, size, color){		
	items = $(cssClass);
	items.each(function(){
		txtString = $(this).html();
		width = $(this).innerWidth();
		txtString = escape(txtString);
		if (txtString.length > 0) {
			$(this).after("<img  class='blocked' src='/image.php?color=" + color +"&text=" + txtString +"&size=" + size +"&width="+width+"'>").remove();	
		}
	});
	
}

// Reads text from inside HTML tag and puts image inside, without removing
function loadImageLink(cssClass, size, color, caps){		
	items = $(cssClass);
	
	items.each(function(){
		txtString = $(this).html();
		if (caps == "capitalise") {
			caps2 = "true";
		}
		else {
			caps2 = "false";
		}
		
		
		width = $(this).innerWidth();
		txtString = escape(txtString);
		if (txtString.length > 0) {
			$(this).html("<img class='blocked' src='/image.php?color=" + color +"&text=" + txtString +"&size=" + size +"&width="+width+"&caps="+caps2+ "'>");	
		}	
	});
	
}

function flashMsg(typeOf) {		
	
	var okMsg = "Your booking request is being submitted.";
	var warningMsg = "<div>Thank you for filling out all fields.</div> <div>Golf Bookings are strictly subject to availability and please do not assume that this booking is confirmed until a Pestana representative has got in touch.</div> <div>Your request will be sent once you press ok, and a copy forwarded to your email.</div><div style=\"background-position: 0pt 0px;\" class=\"smlSelButton\" onclick=\"confirmBooking();\" onmouseover=\"this.style.backgroundPosition='0 -31px'\" onmouseout=\"this.style.backgroundPosition='0 0px'\">Continue Booking </div>";
	var errorMsg = "<div>I'm sorry, I don't understand some of the responses.</div> <div>Please check the highlighted fields and try again. If you have any queries, please contact Pestana Customer Service for assistance.</div>";
	var regSuccess = "Thank you for registering. Look out for some great opportunities in your mailbox!";
	var bookSuccess = "Thank you, your booking request was succesfully submitted, and we will be in touch shortly.";
	var contactSuccess = "Thank you for contacting Pestana. We will be in touch shortly.";

	var loginSuccess = "Thank you for logging in";
	var loginFailure = "Login failed. Please double check your details and try again. Contact Pestana Customer Services if you need to request a new password.";
	
	var newUserAdvice = "Thank you for filling out all fields. Your request will be submitted to Pestana for validation. Click below to continue.<div style=\"background-position: 0pt 0px;\" class=\"smlSelButton\" onclick=\"confirmBooking();\" onmouseover=\"this.style.backgroundPosition='0 -31px'\" onmouseout=\"this.style.backgroundPosition='0 0px'\">Continue Registration </div>";
	var newUserSubmit = "Your request is being submitted";
	
	var genericSuccess = "All your requests have been succesfully completed. Thanks for being part of the Pestana lifestyle.";
	
	switch(typeOf){
		case"1":
			toShow = okMsg;
			newClass = "successFlash";
			break;
			
		case "2":
			toShow = warningMsg;
			newClass = "warningFlash";
			break;
			
		case "3":
			toShow = errorMsg;
			newClass = "errorFlash";
			break;
		case "4":
			toShow = regSuccess;
			newClass = "successFlash";
			break;
			
		case "5":
			toShow = contactSuccess;
			newClass = "successFlash";
			break;
		
		case "6":
			toShow = loginSuccess;
			newClass = "successFlash";
			break;
			
		case "7":
			toShow = loginFailure;
			newClass = "errorFlash";
			break;
		case "8":
			toShow = newUserAdvice;
			newClass = "warningFlash";
			break;
		case "9":
			toShow = newUserSubmit;
			newClass = "successFlash";
			break;
		case "10":
			toShow = genericSuccess;
			newClass = "successFlash";
			break;
		case "11":
			toShow = bookSuccess;
			newClass = "successFlash";
			break;
	}
	
	
	$("#msgBox").fadeOut(function(){
		$(this).removeClass().addClass(newClass).html(toShow);
	});
	
	$("#msgBox").fadeIn();
	
	
}


// Contact Info zoomer
$(document).ready(function() {
	$('#zoomer2').fancyZoom({scaleImg: false, closeOnClick: false});
	
	loadImageLink("#head610 div", 24, "41552b", "capitalise");
	//loadImageLink("h1", 24, "41552b");
	loadImageLink(".lbTitle", 18, "41552b" );
	//loadImageLink(".royalBlue.heavy.title22 a", 18, "41552b" );
	//loadImageLink(".lbTitle2", 16, "41552b" );
	
	
	
	
});
	


// Header Rollovers
// HomeWidget JS	

	
$(document).ready(function() {
if (leftBar == "1"){


if( hwo = document.getElementById('homeWidgetOptions')) {
	
	
	
		
	
		var state = "search";
	
		
		bwt = document.getElementById('bottomWidgetTabs');
		var vo = document.getElementById('videoOption');
		var bo = document.getElementById('brochureOption');
		var lo = document.getElementById('locationOption');
		var go = document.getElementById('galleryOption');

		var HWt = document.getElementById('hwTop');
		var e = document.getElementById('hwTop');
		var HWOm = document.getElementById('HWOmailing');
		var HWOr = document.getElementById('HWOresale');
		
		function locTabOver(){
			bwt.style.backgroundPosition = "0px -104px";
		}
		
		function galTabOver(){
			bwt.style.backgroundPosition = "0px -52px";
		}
		
		function videoOver(){
			hwo.style.backgroundPosition = "0px -104px";
			
		}
		
		function optionReset(){
			hwo.style.backgroundPosition = "0px 0px";
			bwt.style.backgroundPosition = "0px 0px";
		}
		
		function brochureOver(){
			hwo.style.backgroundPosition = "0px -52px";
			
		}
		

		
		
		

		
		
		
		vo.onmouseover = videoOver;
		vo.onmouseout = optionReset;

		bo.onmouseover = brochureOver;
		bo.onmouseout = optionReset;

		lo.onmouseover = locTabOver;
		lo.onmouseout = optionReset;

		go.onmouseover = galTabOver;
		go.onmouseout = optionReset;
		
		
		
	}

}
	gB = document.getElementById('gramachoButton');
	vdpB = document.getElementById('vdpButton');
	sB = document.getElementById('silvesButton');
	aB = document.getElementById('altoButton');
	bB = document.getElementById('belouraButton');
	acB = document.getElementById('acadButton');
	
	
	
	
function buttonOver(){
	
	if (this.className == "headButtons currentButton"){
		return;
	}
	this.style.backgroundPosition = "0px -33px";
	this.style.cursor = "pointer";
}

function buttonOut(){
	if (this.className == "headButtons currentButton"){
		return;
	}
	this.style.backgroundPosition = "0px 0px";
	this.style.cursor = "";
}
	
	gsLink = "/"+lang+"/courses/";
	
	
	gB.onmouseover = buttonOver;
	gB.onmouseout = buttonOut;
	gB.onclick = function(){window.location=gsLink + "gramacho";}
	
	acB.onmouseover = buttonOver;
	acB.onmouseout = buttonOut;
	acB.onclick = function(){window.location=gsLink + "academies";}
	
	
	
	vdpB.onmouseover = buttonOver;
	vdpB.onmouseout = buttonOut;
	vdpB.onclick = function(){window.location=gsLink + "vale-da-pinta";}
	
	sB.onmouseover = buttonOver;
	sB.onmouseout = buttonOut;
	sB.onclick = function(){window.location=gsLink + "silves-golf";}
	
	aB.onmouseover = buttonOver;
	aB.onmouseout = buttonOut;
	aB.onclick = function(){window.location=gsLink + "alto-golf";}
	
	bB.onmouseover = buttonOver;
	bB.onmouseout = buttonOut;
	bB.onclick = function(){window.location=gsLink + "beloura";}
});


