// JavaScript Document

$(function() {
		
		//fixes hover issue in cart.
		$(".cart-menu a").attr("style", "color:#bda41a !important;");
		
		$(".footer").each(function () {
            $(".footer").animate({ opacity: 1.0 }, 1000);
        });


        $(".wine-link .wine-nav").css({ opacity: 0 });
        $(".wine-link .wine-nav li").css({ opacity: 0.3 });

        $(".wine-link").each(function () {
            $(this).hover(function () {
                $(this).animate({ height: "240px" }, 0),
                $(".wine-nav").animate({ opacity: 1.0 }, 1000);
            },
           function () {
               $(".wine-nav").animate({ opacity: 0 }, 2000);
               /*EMC $(this).animate({ height:"25px"}, 0); setting the height immediately (0) to 25px also will make it hide */
           });
        });

        $(".wine-link .wine-nav li").each(function () {
            $(this).hover(function () {
                $(this).animate({ opacity: 1.0 }, 300);
            },
           function () {
               $(this).animate({ opacity: 0.3 }, 300);
           });
        });

		//Main navigation (left)
        $(".nav a").hover(function () {
            $(this).stop().animate({ color: "#000000" }, 300);
        },
        function () {
        	$(this).stop().animate({ color: "#999999" }, 300);
       	});
		
		//Sub navigation (top)
        $(".sub-nav a").hover(function () {         
			
			if(!$(this).hasClass("nohover"))
			{
				$(this).stop().animate({ color: "#ffffff" }, 300);
			}
        },
        function () {
        	if(!$(this).hasClass("current"))
				$(this).stop().animate({ color: "#bda41a" }, 300);
       	});
		
		//Footer navigation
        $(".footer a").hover(function () {
           $(this).stop().animate({ color: "#bda41a" }, 300);
        },
        function () {
           $(this).stop().animate({ color: "#51470d" }, 300);
        });
		
		$(".this-year").each(function() {
			
			var d = new Date();
			var thisYear = d.getFullYear();
			$(this).text(thisYear);
									  
		});
		
		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		var isiPod = (navigator.userAgent.match(/iPhone/i));
		
		if(isiPad || isiPod) {
			
			//give time for the carousel code to resolve.
			setTimeout("setPageForAltDevices()", 1000);
			
			$("a").click(function (e) {
								   
				if($(this).attr("href").toLowerCase().indexOf("wines.aspx")	!= -1)
				{
					//replace with switch foreach page type.
					e.preventDefault();
					window.location = "wines-alt.aspx";
				}
			});
		}
		   
		   
});

function DetectIphone()
{
   if (uagent.search(deviceIphone) > -1)
      return true;
   else
      return false;
}

function setPageForAltDevices() {
	
	$(".sub-nav a").unbind().click(function() {
		
		var index = parseInt($(this).attr("href").substring(1, 2));
		
		index = index - 1;
		
		$("#content-panel").children("li").hide();
		$("#content-panel").children("li").eq(index).show();
		
	});
	
}
