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

// 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 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 request a new password.";
	
	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;
			
	}
	
	
	$("#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", 32, "E4B638", "capitalise");
	loadImageHeader("#head610 h2", 32, "E4B638");
	loadImageLink(".lbTitle", 22, "E4B638" );*/
});
	
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;
		}
		
	});
}





