// fadeToggle plugin

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


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

// Contact Info zoomer
$(document).ready(function() {
	$('#zoomer2').fancyZoom({scaleImg: false, closeOnClick: false});
	

	//loadImageLink("#head610 div", 32, "1f53a5", "capitalise","", "hum");
	//loadImageLink(".lbTitle", 22, "1f53a5","", "hum" );
	//loadImageHeader("#searchResults .h2Lite", 22, "1f53a5","", "mplusthin")
});



// 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, fontF){		
	items = $(cssClass);
	
	items.each(function(){
		txtString = $(this).html();
		if (caps == "capitalise") {
			caps2 = "true";
		}
		else {
			caps2 = "false";
		}
		if (fontF.length) {
			fontAdd = "&font="+fontF;
		}
		else {
			fontAdd = "";
		}
		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 + fontAdd + "'>");	
		}	
	});
	
}


function flashMsg(typeOf) {		
	
	var toShow;
	var newClass;
	
	var okMsg = "Your booking request is being submitted.";
	var warningMsg = "<div>Thank you for filling out all fields.</div> <div>Holiday 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 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 reactivate an account.";
	
	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 = "Your requests have been succesfully completed.";
	
	var clientSuccess = "Client details updated";
	var clientDeleted = "Client deleted";
	
	var updateSuccess = "Updated succesfully";
	
	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 = updateSuccess;
			newClass = "successFlash";
			
		case "9":
			toShow = newUserAdvice;
			newClass = "warningFlash";
			break;
		case "10":
			toShow = newUserSubmit;
			newClass = "successFlash";
			break;
		case "11":
			toShow = genericSuccess;
			newClass = "successFlash";
			break;
		case "clientsuccess":
			toShow = clientSuccess;
			newClass = "successFlash";
			break;
		case "clientdeleted":
			toShow = clientDeleted;
			newClass = "warningFlash";
			break;
	}
	
	
	$("#msgBox").fadeOut(function(){
		$(this).removeClass().addClass(newClass).html(toShow);
	});
	
	$("#msgBox").fadeIn();
	
	
}
var state;
state = "search";


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

	

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;
		
		
		
	}
});
}





