// JavaScript Document
// ==================================== on page load functions
$(function(){
// ==================================== header search buttons		   
$("#icon-search").click(function(){$("#topsearch").fadeIn(function(){$('body').bind('click', function(event) {if ($(event.target).is('.searchtext') ) {}else{$("#topsearch").fadeOut(function(){$('body').unbind('click');});}});});});

// ==================================== nav functions
$("#navwinery a").mouseenter(function(){shownav("winery",1);});
$("#navaccommodation a").mouseenter(function(){shownav("accommodation",1);});
$("#navfood-and-drink a").mouseenter(function(){shownav("food-and-drink",1);});
$("#navnavweddings a").mouseenter(function(){shownav("navweddings",1);});
$("#navwedding a").mouseenter(function(){shownav("wedding",1);});
$("#navonferences a").mouseenter(function(){shownav("onferences",1);});
$("#navabout-us a").mouseenter(function(){shownav("about-us",1);});
$("#navnews a").mouseenter(function(){shownav("news",1);});
$("#navcontact a").mouseenter(function(){shownav("contact",1);});
$(".leftNav a, .rightNav a, .subnav").mouseleave(function(){navInt = setTimeout(hidenav,1500);});
$(".leftNav a, .rightNav a, .subnav").mouseenter(function(){clearInterval(navInt);});
});


// ==================================== functions

// ====== nav / subnav ============================================================
current = "";
currentnav = "";
function shownav(which,hasnav){
$(".leftNav a, .rightNav a").stop(true, true);$(".subnav").stop(true, true);
$(".leftNav div, .rightNav div").removeClass('over-wine over-hotel over-dining over-escape over-events over-media over-about over-contact');
whichsub = "sub"+which;
whichnav = "nav"+which;
if(current==whichsub){}else{$(".subnav").fadeOut(500);}
if(hasnav==1){
$("#"+whichsub).fadeIn(200);
current=whichsub;
}
$("#"+whichnav).addClass('over-'+which);
}
function hidenav(){
$(".leftNav div, .rightNav div").removeClass('over-wine over-hotel over-dining over-escape over-events over-media over-about over-contact');
$(".subnav:visible").fadeOut();
}
// ================================================================================



// ====== image preview ============================================================
/*
 * Image 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.imagePreview = function(){
	/* CONFIG */
		xOffset = 20;
		yOffset = 250;

		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result

	/* END CONFIG */
	$(".preview").hover(function(e){
								  
		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.t +"' /></p>");								 
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#preview").remove();
    });
	$(".preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});


// ====== filed completion ============================================================
$(function(){
$(".restext").focusin(function(){v=$(this).val();t=this.title;if(v==t){$(this).val("");}});
$(".restext").focusout(function(){v=$(this).val();if(v==""){$(this).val(this.title);}});
})

function drawtop(){
	myheight = $(document).height();
	if(myheight>1200){$(".content").append("<img src=\"/themes/asara/images/but-backtotop.gif\" width=\"41\" height=\"41\" class=\"top\" style=\"top:750px;\"/>");}

}

