var name = ".mail.sidebar";  
var menuYloc = null; 

$(document).ready(function(){
	swfobject.embedSWF("assets/flash/main-umhlanga.swf", "flash-main-umhlanga", "620", "290", "6.0.0","","",{wmode:"opaque"});
	swfobject.embedSWF("assets/flash/gallery.swf", "flash-gallery", "260", "200", "6.0.0","","",{wmode:"opaque"});
	swfobject.embedSWF("assets/flash/main.swf", "flash-main", "620", "290", "6.0.0","","",{wmode:"opaque"});
	$(".gallery a").fancybox();
	$("a.image").fancybox();
	$(".general-gallery a").fancybox();

	$(".landing_listing ul a").fancybox();	
	
	$("#holiday-calendar").fancybox({
		'width'				: 820,
		'height'			: 620,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});	

	// remember to set last index key 0
	var path = location.pathname.substring(1).split("/")[0];
	if (path)
		$('.nav a[href="' + path + '"]').attr('class', 'selected');
	if (path == "")
		$('.nav a[href="index.php"]').attr('class', 'selected');
	
	// Places the H1 one tag in a hidden form field called "refer"
	$(".refer").val($("h1").text());
	if($("h1").text() == "Fifa World Cup 2010"){
			$("input#arrival").val("11/06/2010");
			$("input#departure").val("11/07/2010");	
	}
	
	
	$("#requests").val($(".embed").text());
	
	if($("h1").text() == "Fifa World Cup 2010" || $("h1").text() == "Contact Us"){
			$("li.similar").remove();
	}
	if($("h1").text() == "Get Listed"){
			$("li.similar").remove();
			$("li.arrival").remove();
			$("li.departure").remove();
			$("li.adults").remove();
			$("li.children").remove();
			$("li.ages").remove();
	}	
	
	$('.date-pick').datePicker();
	
	$(".gsc-search-button").attr('value', 'GO');
	
	// Contact Form
	$(".enquiry input.button").click(
		function() {
			if (
				$(".enquiry input#name").val().length && 			
				$(".enquiry input#email").val().length
			){
				$(".enquiry").submit();		
			}
			else {
				alert('Please enter your name and email address.');
				return false;
			}
		}
	);
		// Aweber Contact Form
	$(".aweber input.button").click(
		function() {
			if ($("#optin").is(':checked')) {
				$("form.aweber").attr('action', 'http://www.aweber.com/scripts/addlead.pl');
			} else {
				$("form.aweber").attr('action', 'enquiry-process.php');
			}			
			if ($(".aweber input#email").val().length && $(".contact textarea#comments").val().length) {
				$(".aweber").submit();		
			}
			else {
				return false;
			}
		}
	);
	// External Links
	$('[rel="external"]').click(function(){
			window.open(this.href);
			return false;
		});
		
	$('.large-fade').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '220px' }); 		
	
	$(name).animate({top:$('.sidebar').height()+62},{duration:500,queue:false});
	$(window).scroll(function () {
		if ($(document).scrollTop() > $('.sidebar').height()){
			var offset = $(document).scrollTop()+"px";  
			$(name).animate({top:offset},{duration:500,queue:false}); 
		}
		else {
			$(name).animate({top:$('.sidebar').height()+32},{duration:500,queue:false});
		}		
	});
	
	
	// Competition Form
	$(".competition input.button").click(
		function() {
			if ($(".competition input#email").val().length && $(".competition input#name").val().length && $(".competition input#email1").val().length && $(".competition input#name1").val().length) {
				if ($("#the_terms").is(':checked')) {
					$(".competition").submit();	
				} else {
					alert("You have to accept the terms and conditions to enter");
					return false;
				}	
			} else {
				alert("Please enter your name and email address, and at least one friends details.");
				return false;
			}
		}
	);
	
	function getUrlVars()
	{
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
	param = getUrlVars();
	
	
	$('#arrival').val(param['arrival']);
	$('#departure').val(param['departure']);
	$('form #name').val(param['name']);
	$('form #email').val(param['email']);	
	
	if(param['code']==1){$('#requests').val('Please quote me on the self-catering special at Lemonwood Close. Subject to availability.');}

	
});



