// JavaScript Document

$(document).ready(function() { 
	
	//init nyroModal
	$('.nyroModal').nyroModal( {bgColor: '#FBF8E5'} );
	
	//cottage sub menu
	if (showSubNav_cottages == true){
		$("#mainNav").css("height","88px");
		$("#subNav_cottages").show();
	}
	else {
		$("#mainNav_cottages").toggle(
		  function () {
			$("#mainNav").animate( { height:'88px' } );
			$("#subNav_cottages").fadeIn();
		  },
		  function () {
			$("#mainNav").animate( { height:'68px' } );
			$("#subNav_cottages").fadeOut();
		  }
		);
	}
	
	//init slideshow
	$("#slideShowItem").cycle({
		fx:      'fade',
		timeout: 10000,
		prev:    '#prev',
		next:    '#next',
		pager:   '#pageButtons',
		pagerAnchorBuilder: pagerFactory
	});
	
	function pagerFactory(idx, slide) {
		var s = idx > 2 ? ' style="display:none"' : '';
		return '<a href="#">'+(idx+1)+'</a>';
	};
	
	//hover event handling for cottage thumbnails
	$("#subMenu_candlelight").hover(
		function(){$('#CsCandlelight').mouseover();},
		function(){$('#CsCandlelight').mouseout();}
	);
	$("#subMenu_village").hover(
		function(){$('#CsVillage').mouseover();},
		function(){$('#CsVillage').mouseout();}
	);
	$("#subMenu_forest").hover(
		function(){$('#CsForestfooter').mouseover();},
		function(){$('#CsForestfooter').mouseout();}
	);
	$("#subMenu_clare").hover(
		function(){$('#CsClareCottage').mouseover();},
		function(){$('#CsClareCottage').mouseout();}
	);
	
	$('#CsCandlelight').append('<span class="hover candlelight">Candlelight Cottage</span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(400, 1);
	  }, function () {
	    $span.stop().fadeTo(800, 0);
	  });
	});
	
	$('#CsVillage').append('<span class="hover village">Cottage in the Village</span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(400, 1);
	  }, function () {
	    $span.stop().fadeTo(800, 0);
	  });
	});
	
	$('#CsForestfooter').append('<span class="hover forest">Cottage in the Forest</span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(400, 1);
	  }, function () {
	    $span.stop().fadeTo(800, 0);
	  });
	});
	
	$('#CsClareCottage').append('<span class="hover clare">Clare Cottage</span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(400, 1);
	  }, function () {
	    $span.stop().fadeTo(800, 0);
	  });
	});
	
	// jQuery tabs for packages page 
	//When page loads...
	$(".package-item").hide(); //Hide all content
	$("ul#menu li:first").addClass("active").show(); //Activate first tab
	$(".package-item:first").show(); //Show first tab content

	//On Click Event
	$("ul#menu li").click(function() {

		$("ul#menu li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".package-item").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show(); //Show in the active ID content
		return false;
	});



});
