$(document).ready(function () {
//if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
//    $(".promotion").click(function(){
//        //we just need to attach a click event listener to provoke iPhone/iPod/iPad's hover event
//        //strange
//    });
//}	
	
	var $mh = $("#menu-hover"),
        $wh = $("#wine-hover"),
        $tl = $("#toplogo"),
        $w = $("#wine"),
        $or = $("#overlay-r"),
        $m = $("#menu"),
        $ol = $("#overlay-l"),	
        $lsrs = $("#left-show,#right-show"),
        $dds = $("#dishes,#dishes-slide"),
        $wws = $("#wines,#wines-slide");	


		$("#overlay-l,#overlay-r").fadeTo(1, 0.4);
		$w.animate({
			width: '485px'
		},1);
		$("#show-wrap,#content,.nav,#topmenu").center();

		

//tooltip
		$(".ttips li").hover(
			function() { $(this).contents("span.tooltip:last-child").fadeIn().css({ display: "block" }); },
			function() { $(this).contents("span.tooltip:last-child").css({ display: "none" }); }
		);
		


		
//hover slide
	$('#mainmenu #menu-hover, #mainmenu #wine-hover').hoverIntent(openMenu,openNone);
		
		$('#mainmenu').mouseleave(function () { 
				$dds.fadeOut("fast", function () {
					$mh.css({height: "91px", top: "220px"}).stop().animate({
						width: '681px'
					}, { queue: false, duration: 400 });
					$w.animate({
						width: '485px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });	
					$or.animate({
						opacity: 0.4,					  
						height: '230px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });	
				});		
				$wws.fadeOut("fast", function () {
					$wh.css({height: "91px", top: "220px"}).stop().animate({
						width: '681px'
					}, { queue: false, duration: 400 });	
					$m.animate({
						width: '135px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });  
					$ol.animate({
						opacity: 0.4,					  
						height: '230px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });						
				});			});		
		
		$('#show-wrap').mouseleave(function () { 
				$tl.fadeIn(1000);
			});		

		$lsrs.cycle({
			timeout: 8000,
			random: 1,
			speed: 2000,
			fx: 'fade'
		});
		$('#topmenu a').click(function () {
			$(".nav").delay(800).fadeIn(); 
			$lsrs.cycle('pause');	
			return false;
		});
		
		var $c = $("#content"),
			$oa = $("#overlay-all");
		$('#close').click(function () {							   
			$('.nav').fadeOut();						   
			$c.fadeOut(400, function () {
				$('#overlay-all').fadeOut();
			});		   
			$lsrs.cycle('resume');	
			return false;
		});
		function onAfter(curr, next, opts) {
			var index = opts.currSlide;
			$('#prev')[index === 0 ? 'fadeOut' : 'fadeIn']();
			$('#next')[index === opts.slideCount - 1 ? 'fadeOut' : 'fadeIn']();
		}

		$c.cycle({ 
			speed: 700,
			fx:      'fade', 
			sync: 1,
			prev:   '#prev',
			next:   '#next',
			after:   onAfter, 
			timeout: 0, 
			cleartype:     1,
			cleartypeNoBg: true		
		});		
		$('#top0').click(function () {
			$oa.fadeTo(500, 0.94, function () {
				$c.cycle(0).delay(200).fadeIn(800); 
			});
			$("#prev").hide(); 
			return false; 
		});	
	
		$('#top1').click(function () { 
			$oa.fadeTo(500, 0.94, function () {
				$c.cycle(1).delay(200).fadeIn(800); 
			});
			return false; 
		});	
	
		$('#top2').click(function () { 
			$oa.fadeTo(500, 0.94, function () {
				$c.cycle(2).delay(200).fadeIn(800); 
				$("#next").hide(); 
			});
			return false; 
		});

        var $ds = $("#dishes-slide");
		$ds.cycle({ 
			speed: 400,
			fx:      'fade', 
			sync: 1, 
			timeout: 0, 
			cleartype:     1,
			cleartypeNoBg: true		
		});		
		$('#tab1').click(function () { 
			$ds.cycle(0); 
			return false; 
		});
		$('#tab2').click(function () { 
			$ds.cycle(1); 
			return false; 
		});
		$('#tab3').click(function () { 
			$ds.cycle(2); 
			return false; 
		});
		$('#tab4').click(function () { 
			$ds.cycle(3); 
			return false; 
		});						   
		$('#tab5').click(function () { 
			$ds.cycle(4); 
			return false; 
		});


		var IE = /*@cc_on!@*/false;
		if (IE) {
		} else {
			$('#dishes .menu-tab li a,#wines .menu-tab li a').hover(function () {
					$(this)
						.prepend('<p></p>')
						.find('p')
						.fadeIn('fast');
				}, function () {
					$(this)
						.find('p')
						.fadeOut('fast', function () {
							$(this).remove();
						});
				});
		}

	
    $('a.newWin').click(function(){
        window.open(this.href);
        return false;
    });	

//Rez Widget
    $("a#rez").click(function () {
      $("#rez-widget").slideToggle("slow");	
    });
	
    $('a.w_button,.w_all_times a').click(function(){
        window.open(this.href);
        return false;
    });

	
	
});
function openMenu(){
	var $mh = $("#menu-hover"),
        $wh = $("#wine-hover"),
        $dds = $("#dishes,#dishes-slide"),
        $wws = $("#wines,#wines-slide"),
        $tl = $("#toplogo"),
        $w = $("#wine"),
        $or = $("#overlay-r"),
        $m = $("#menu"),
        $ol = $("#overlay-l");

  if ( $(this).is('#menu-hover')) {
				$mh.css({width: "1080px",height:"500px",top:"0"});
				$dds.delay(500).fadeIn('slow');
				$tl.fadeOut(1000);
				$w.animate({width: '135px'}, { queue: false, duration: 700, easing: 'easeInOutExpo' });
				$or.animate({
					opacity: 0.9,					  
					height: '500px'
				}, { queue: false, duration: 700, easing: 'easeInOutExpo' });			
		} else {
				$dds.fadeOut("fast", function () {
					$mh.css({width: "681px",height: "91px", top: "220px"});
					$w.animate({
						width: '485px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });	
					$or.animate({
						opacity: 0.4,					  
						height: '230px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });	
				});					
       }  

  if ( $(this).is('#wine-hover')) {
				$wh.css({width: "1080px",height:"500px",top:"0"});
				$wws.delay(500).fadeIn('slow');
				$tl.fadeOut(1000);
				$m.animate({width: '485px'}, { queue: false, duration: 700, easing: 'easeInOutExpo' });
				$ol.animate({
					opacity: 0.9,					  
					height: '500px'
				}, { queue: false, duration: 700, easing: 'easeInOutExpo' });

		} else {
				$wws.fadeOut("fast", function () {
					$wh.css({width: "681px",height: "91px", top: "220px"});	
					$m.animate({
						width: '135px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });  
					$ol.animate({
						opacity: 0.4,					  
						height: '230px'
					}, { queue: false, duration: 700, easing: 'easeInOutExpo' });						
				});			
       }  
			}
function openNone(){};

jQuery.fn.center=function(b){var a={vertical:false,horizontal:true};op=jQuery.extend(a,b);this.each(function(){var m=jQuery(this);var c=m.width();var n=m.height();var o=parseInt(m.css("padding-top"));var d=parseInt(m.css("padding-bottom"));var e=parseInt(m.css("border-top-width"));var l=parseInt(m.css("border-bottom-width"));var h=(e+l)/2;var j=(o+d)/2;var i=m.parent().css("position");var g=(c/2)*(-1);var k=((n/2)*(-1))-j-h;var f={position:"absolute"};if(op.vertical){f.height=n;f.top="50%";f.marginTop=k}if(op.horizontal){f.width=c;f.left="50%";f.marginLeft=g}if(i=="static"){m.parent().css("position","relative")}m.css(f)})};
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
