function tourPopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=450,left = 312,top = -16');");
}

$(document).ready(function(){


	
	var loc = window.location.toString().split("/")
	loc = loc[loc.length - 1]
	$('a[href="'+loc+'"]').addClass('active'); 
	
	if(loc == ''){
		$('a[href="index.php"]').addClass('active');
		
	}
	
	$("a").live("click", function(event){
    var href = $(this).attr("href");
	//alert(href);
    if(href[0] == "/"){
        //event.preventDefault();
        //window.location.hash = "#!" + href;
    }
	});
	
	/*
	.default(function(){
    $.get(window.location.hash.replace("#!", ""), function(data){
        $("#container").html(data);
    });
	});
	*/
	 
	//Path.listen();
		
	extLinks();
	
	 if($('#gallery-home').length > 0 /*Bleedn' IE6!*/){
		slideShow();
	 }
	 
	 initproptabs();
	 //paginate();
	 
	 
	 
	
});


function paginate(){
	var start = 0;
    var nb = 9;
    var end = start + nb;
    var length = $('.thumbs li').length;
    var list = $('.thumbs li');
    
	if(nb>=length){
		$('.nav-controls').hide();
	}
	
	
    list.hide().filter(':lt('+(end)+')').show();

    $('.prev-pic, .next-pic').click(function(e){
       e.preventDefault();webegg.co.uk/nfl
	   
       console.log(start);
       if( $(this).hasClass('prev-pic') ){
           start -= nb;
       } else {
           start += nb;
       }
        
       if( start < 0 || start >= length ) start = 0;
       end = start + nb;        
       console.log(start);
       console.log(end);
       
       if( start == 0 ) list.hide().filter(':lt('+(end)+')').show();
       else list.hide().filter(':lt('+(end)+'):gt('+(start-1)+')').show();
    });
}




function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open('/'+URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=450,left = 312,top = -16');");
}


function initproptabs() {
	if($('#propinfotabs').length) {
		$('#propinfotab2').css('display', 'none');
		$('#propinfotab3').css('display', 'none');
		$('#proptablinks li a:eq(0)').attr('class', 'active');		
		$('#proptablinks li a:eq(1)').attr('class', '');		
		$('#proptablinks li a:eq(2)').attr('class', '');		
	}
}

function showproptab(theTabNo) {
	if($('#propinfotab1').css('display')=='block') {
		$('#propinfotab1').fadeOut('slow', function () {
			$('#propinfotab' + theTabNo).fadeIn('slow');
		});
	} else if($('#propinfotab2').css('display')=='block') {
		$('#propinfotab2').fadeOut('slow', function () {
			$('#propinfotab' + theTabNo).fadeIn('slow');
		});
	} else if($('#propinfotab3').css('display')=='block') {
		$('#propinfotab3').fadeOut('slow', function () {
			$('#propinfotab' + theTabNo).fadeIn('slow');
		});
	}
	$('#proptablinks li a:eq(0)').attr('class', '');
	$('#proptablinks li a:eq(1)').attr('class', '');
	$('#proptablinks li a:eq(2)').attr('class', '');
	$('#proptablinks li a:eq(' + ((parseInt(theTabNo) - 1)).toString() + ')').attr('class', 'active');
}


ddaccordion.init({
	headerclass: "silverheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "slow", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

function extLinks(){
	$('a[rel*="external"]').click(function(){
		window.open(this.href);
		return false;
	});
}

function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery-home a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery-home a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery-home .caption').css({opacity: 1});

	//Resize the width of the caption according to the image width
	$('#gallery-home .caption').css({width: $('#gallery-home a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery-home .content').html($('#gallery-home a:first').find('img').attr('alt'))
	.animate({opacity: 1}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery-home a.show')?  $('#gallery-home a.show') : $('#gallery-home a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery-home a:first') :current.next()) : $('#gallery-home a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('alt');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery-home .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery-home .caption').animate({opacity: 1},1 ).animate({height: '50px'},500 );
	
	//Display the content
	$('#gallery-home .content').html(caption);
	
	
}

if($('#yourbooking').length) {
	var pagescrolled = false;
	$(window).scroll(function () { pagescrolled = true; });
}

function doSetBooking(property, wc, start, start2, type, price, nights, url) {
	//var theurl = url + "?wc=" + wc + "&start=" + start + "&type=" + type.toString();

	$.ajax({
	  type: "GET",
	  url: "/_ajax/booking.php",
	  data: "property="+property+"&wc="+wc+"&start="+start+"&start2="+start2+"&type="+type+"&price="+price+"&nights="+nights+"&url="+url,
	  success: function(thereturn){
		if($('#yourbooking').css('display')=="block") {
			$('#bookingoptions').fadeOut('slow', function() { $('#bookingoptions').html(thereturn); $('#bookingoptions').fadeIn('slow'); } );
		}
		else {
			$('#bookingoptions').html(thereturn);
			$('#yourbooking').slideDown('slow');
		}
		pagescrolled = false;
	  	
	  }
	});  		
}

function setBooking(property, wc, start, start2, type, price, nights, url) {
	if($('#yourbooking').css('display')=="none") {
		$.scrollTo('#theavailability', 800);
		var t=setTimeout("doSetBooking("+property+", '"+wc+"', '"+start+"', '"+start2+"', "+type+", '"+price+"', "+nights+", '"+url+"')", 800);
	}
	else if(pagescrolled==true) {
		$.scrollTo('#theavailability', 800);
		var t=setTimeout("doSetBooking("+property+", '"+wc+"', '"+start+"', '"+start2+"', "+type+", '"+price+"', "+nights+", '"+url+"')", 800);
	}
	else {
		doSetBooking(property, wc, start, start2, type, price, nights, url);
	}
}



function cancelBooking() {
	if($('#yourbooking').css('display')=="block") { 
		$.scrollTo('#container', 600);
		$('#yourbooking').slideUp('slow');
	}
}



function externalLinks()
{
	if (!document.getElementsByTagName)
		return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}


