$(document).ready(function(){
	
	//input labels	
	//$(":text").labelify();
	
	$('#credits').bind('mouseover',showCredits);
	$('#credits-info').bind('mouseleave',hideCredits);
	
	function showCredits(e){
log('showCredits');
		var 	o = $(e.target),
			//x = $(window).width() - $('#credits-info').width() -40,
			//y = $(document).height() - $('#credits-info').height() -20;
			x = $('#footer').position().left + 88,
			y = $('#footer').position().top - 20;
		$('#credits-info')
			.css({ top:y,left:x })
			.fadeIn('fast');	
	};
	function hideCredits(e){
		$('#credits-info').fadeOut('fast');	
	};
	
	
	//filtering
	if ($('.wines-grid').length > 0){

		$('.wines-grid').filtering();
	}

	//tooltips
	//$("a[title]").tooltip();
	
	
	/*
	//drop menu
	$('#menu li').hover(
		function () {
			//show its submenu
			$('ul', this).fadeIn('fast');	
		
		},
		function () {
			//hide its submenu
			$('ul', this).fadeOut('fast');       
		}
	);
	
	
	$("#top-link").find('a').click(function(){
	
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
		
	});
	*/
	
	//external links
	$("a").each( function(){
	
		if ($(this).attr("rel") == "_blank"){
			
			$(this).attr("target","_blank");
			$(this).addClass("external");
		}
	});
	
	
	//logging
	function log(s) {
		if (typeof console != "undefined" && typeof console.debug != "undefined") {
			console.log(s);
		} else {
			//alert(s);
		}
	}


	//vertical centering
	$(window).resize(function(){
	
		positionContainer();
	});
	
	positionContainer();
	
	function positionContainer(){
		
		//if mobile, don't position
		if ( $('body').width() < 640 ){
			
			$('#container').css({
				position:'relative',
				top: 0
			});
			return;
		}
		
		
//try{ console.log('positionContainer'); }catch(e){}
	
		//var new_x = ($(window).width() - jQuery('#container').outerWidth())/2;
		var new_y = ($(window).height() - $('#container').outerHeight())/2 - 50;
	
		if (new_y < 0){ new_y = 0 }
		//if (new_x < 25){ new_x = 25 }
		
		//$('#container').css({
			//position:'absolute'//,
			//left: new_x,
			//top: new_y
			//});
		$('#container').stop().animate({top:new_y},500);	
			
			
	}


	//menu animation
	$('#menu ul').lavaLamp({ fx:'linear', speed:700 });


	//
	//if ($.browser.msie && $.browser.version.substr(0,1) < 8) {
		//no ie6/7 support
	//} else {
		
		$("#scrolling-stage").roller({ 		
			button_left_id:'scrolling-button-left',
			button_right_id:'scrolling-button-right',
			scroll_stage_id:'scrolling-area'
		});
	
	//}
	
	
	

});


$(window).load(function() {
	
	

	
	
	/*$("#scrolling-stage").smoothDivScroll({ 
		scrollableArea: "#scrolling-area",
		scrollWrapper: "#scrolling-wrapper",
		scrollingHotSpotLeft:'#scrolling-button-left',
		scrollingHotSpotRight:'#scrolling-button-right',
		//startAtElementId: "startAtMe",
		speedBooster:1000,
		hiddenOnStart: false
		//visibleHotSpots: "always"
	});*/
	
});

jQuery.fn.singleDoubleClick = function(single_click_callback, double_click_callback, timeout) {
  return this.each(function(){
    var clicks = 0, self = this;
    jQuery(this).click(function(event){
      clicks++;
      if (clicks == 1) {
        setTimeout(function(){
          if(clicks == 1) {
            single_click_callback.call(self, event);
          } else {
            double_click_callback.call(self, event);
          }
          clicks = 0;
        }, timeout || 300);
      }
    });
  });
}
