$(document).ready(function(){

// colorbox (for gallery images)
	$("a[rel='colorbox']").colorbox();

// entire block clickable function
	$(".clickable").click(function(){
    	window.location=$(this).find("a").attr("href");return false;
	});
	

// drop down menu

	$("#drop1, #drop2, #drop3, #drop4, #drop5").css("visibility","visible").css("display","none");
		
	// variable for z-index
	var z = 1;

	// menu functions
		
		// show	
		jQuery.fn.open = function () {
			z = z + 1;
			this
				.stop(true, true)
				.slideDown(300)
				.css("z-index", z);
			}
			
		// hide with delay	
		jQuery.fn.close = function () {
			this
				.stop(true, true)
				.delay(200)
				.slideUp(300);
			}
			
	 // show and hide each menu with the above functions
		$("#nav1").mouseover(function(){ $("#drop1").open(); });
		$("#nav1").mouseleave(function(){ $("#drop1").close(); });
		$("#nav2").mouseover(function(){ $("#drop2").open(); });
		$("#nav2").mouseleave(function(){ $("#drop2").close(); });
		$("#nav3").mouseover(function(){ $("#drop3").open(); });
		$("#nav3").mouseleave(function(){ $("#drop3").close(); });
		$("#nav5").mouseover(function(){ $("#drop4").open(); });
		$("#nav5").mouseleave(function(){ $("#drop4").close(); });
		$("#nav7").mouseover(function(){ $("#drop5").open(); });
		$("#nav7").mouseleave(function(){ $("#drop5").close(); });
		
	// hides the menu on clicking a link  
		$('.dropbox li').mouseup(function() {
			$('.dropbox').fadeOut(300);
		});	

	// click effect - moves text down 1px to simulate button press 	
		$('.dropbox li').mousedown(function() {
			$(this).css("padding","9px 10px 6px 10px");
		});
		
		$('.dropbox li').mouseup(function() {
			$(this).css("padding","8px 10px 7px 10px");
		});
		
		$('.dropbox li').mouseleave(function() {
			$(this).css("padding","8px 10px 7px 10px");
		});
		
	//ends

	 // hides the menu on mouseleave    
		$(".dropbox").mouseleave(function(){
			$(this)
				.stop(true, true)
				.delay(200)
				.slideUp(300);
				
		});
		
	 // stops menu hiding when re-entering  
		$(".dropbox").mouseenter(function(){
			$(this)
				.stop(true, true)
				.slideDown(100);			
		});
		
// footer controls 	
	
 		$("#footer").hover(function(){
			$(".arrow-foot")
				.css("background-position","-700px -30px");
		}),(function() {
			$(".arrow-foot")
				.css("background-position","-700px -0px");		
			});	
				
				
				
		$("#footer").click(function(){ 
			$("#footcontent")
				.stop(true, true)
				.slideDown(0); 	
			$(".arrow-foot")
				.css("background-position","-700px -10px");
			window.scrollTo(0, 99999)				
		});
		
		// hides footer on mouseleave
		$("#footer").mouseleave(function(){ 
			$("#footcontent")
				.stop(true, true)			
				.slideUp(400);
			$(".arrow-foot")
				.delay(900)	
				.css("background-position","-700px 0px");
		});
		
// tab controls 	
	
		// show or hide menu on click  			
		$(".tabtop").click(function(){
			if ($(this).hasClass('opened')) {
				$(this).nextAll(".tabcontent")
					.stop(true, true)
					.slideUp(200); 	
				$(".arrow-tab", this)
					.css("background-position","-690px -0px");
				$(this).stop(true, true).removeClass('opened');
			}
			else {
				$(this).nextAll(".tabcontent")
					.stop(true, true)
					.slideDown(400);			
				$(".arrow-tab", this)
					.css("background-position","-690px -10px");			
				$(this).stop(true, true).addClass('opened');
			}
		});
		
		
// wine info panels 	
		$(".tooltip").css("visibility","visible").css("display","none");
		$(".wineinfo").css("visibility","visible").css("display","none");
		$(".wineinfo:first").css("display","block");
		$(".showinfo:first").addClass('opened');
		
		$(".showinfo").mouseenter(function(e) {
			$(this).nextAll(".tooltip", this)
				.stop(true, true)
				.delay(200)
				.fadeIn(300);
			});
			
		$(".showinfo").mouseleave(function() {
			$(this).nextAll(".tooltip", this)
				.stop(true, true)
				.fadeOut(200);
			});
			
		
		// shows info on click  	
		$(".showinfo").click(function(){
			if ($(this).hasClass('opened')) {
				$(this).nextAll(".wineinfo", this)
					.stop(true, true)
					.slideUp(200).hide(function(){
						$(this).hide();
						});
				$(".tooltip", this)
					.stop(true, true)
					.fadeOut(200);
				$(".arrow-shop", this)
					.css("background-position","-700px -10px");
				$(this).removeClass('opened');
			}
			else {
				$(this).nextAll(".wineinfo", this)
					.stop(true, true)
					.slideDown(400).show(function(){
						$(this).show();
						});
				$(".tooltip", this)
					.stop(true, true)
					.delay(300)
					.fadeOut(500);
				$(".arrow-shop", this)
					.css("background-position","-700px 0px");					
				$(this).addClass('opened');
			}
		});
	
});

// Twitter

	getTwitters('tweet', {
		id: 'printhiewines', 
		prefix: '', 
		clearContents: true,
		ignoreReplies: false,
		newwindow: true
	});
	
	getTwitters('tweets', {
		id: 'printhiewines', 
		prefix: '', 
		clearContents: true,
		ignoreReplies: false,
		newwindow: true,
		count: 5
	});

// Clear text fields on get focus
	
	function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}

