// ToolTip

/*
 * Url preview script 
 * powered by jQuery (http://www.jquery.com)
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.tooltip").hover(function(e){						  
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p class='screenshot'><img src='"+ this.href +"' alt='url preview' width='300' />"+ c +"</p>");								 
		$(".screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;	
		$(".screenshot").remove();
    });	
$("a.tooltip").click(function(){return false;});	

};

	
		
// Start on doc ready

$(document).ready(function(){
	
	$('#testimonal').cycle({
			timeout : 9000,
			delay	: -3000}); // Testimonal slideshow					   
	screenshotPreview(); // tooltip
	$("a.colorbox-image").colorbox({
		'maxWidth' : '800px',
		'maxHeight' : '96%'
	}); // Colorbox popup
				   
// Home Page					   
	$("body#home .carousel-wrapper").jCarouselLite({
		btnNext: ".carousel-wrapper .next a",
		btnPrev: ".carousel-wrapper .prev a",
		easing: "easeinout",
		speed: 500,
		auto: 10000
	});   

// boats-listing
	$("ul.list .photo>a,ul.list .summary>a, .carousel>ul .photo>a,.carousel>ul .summary>a").colorbox({
		inline:true, 
		href:function(){ return $(this).attr('rel');},
		onOpen: function() {
			var img = $(this).attr('name');
			if(img) {
				$(this).parent().parent().find('.additional-info .mainImage img').attr('src', img);
			}
		}
	});
			
// listing details

	$("body#contact ul#sub-menu>li, body#details ul#sub-menu>li").click(function() {
		$("body#contact ul#sub-menu>li, body#details ul#sub-menu>li").removeClass("here");
		$(this).addClass("here");
		
		var activeTab = $(this).find('a').attr("href").slice('1');
		$("#main-content-wrapper>div.span-14").not('#main-content-wrapper>div.' + activeTab + '').hide();
		$('div.' + activeTab + '').show(); //Fade in the active content

		$.cookie('here', $(this).find('a').attr("href").slice('1'));
		return false;
	});
		var state = $.cookie("here");
		
		if(state == "enquiry") {
			$("body#contact #main-content-wrapper>div.enquiry, body#details #main-content-wrapper>div.enquiry").show();
			$("body#contact #main-content-wrapper>div.description, body#details #main-content-wrapper>div.description").hide();
			$("body#contact ul#sub-menu li:first, body#details ul#sub-menu li:first").removeClass("here");
			$("body#contact ul#sub-menu li:last, body#details ul#sub-menu li:last").addClass("here");
		} else {
			//Default Action
			$("body#contact #main-content-wrapper>div.span-14, body#details #main-content-wrapper>div.span-14").not("div.description").hide();
		}

		$("body#contact #main-menu a, body#details #main-menu a").click(function() {
			$.cookie('here', null)		  
		});	
		
		
});
