$(function() {

	/* ===== HOMEPAGE HERO SWITCHER ===== */

	var homeHero = $('#homeheros a');
	if (homeHero[0]) {
		$('#homeheros a:first').addClass('on');
		var getRel = $('#homeheros a.on').attr('rel');
		$('#homehero').css('background',
				'#666 url(' + getRel + ') top center no-repeat');
	}

	/*
	 * ===== HOMEPAGE PROMOS: if exists, for each, append an image using the
	 * anchor's rel for the src =====
	 */

	var homePromo = $('#homepromos a');
	if (homePromo[0]) {
		$(homePromo).each(function() {
			var getSrc = $(this).attr('rel');
			$(this).append('<img src="' + getSrc + '">');
		});
	}

	/* ===== MAIN NAV HOVER AND CLICK EVENTS ===== */

	var oTimer = new Array();
	
    var mainNavEle = $('#nav-main ul#nav-main-parent li');
    $(mainNavEle).mouseover(function(){
		clearTimer();
		$(this).addClass('on');
    });
	
    $(mainNavEle).mouseout(function(){     
		oTimer.push(setTimeout(hideMenu, 200));
    });
	
	function hideMenu(){
		clearTimer();
		$('#nav-main ul li.on').removeClass('on');
	}
    
	function clearTimer(){
		for(i = 0; i < oTimer.length; i++){
			clearTimeout(oTimer.pop());
		}
	}
	
	$('#nav-main ul#nav-main-parent').children("li").mouseover(function(){
		clearTimer();
		$('#nav-main ul li.on').removeClass('on');
		$(this).addClass('on');
    });


	/* ====== APPEND POD RELATED THUMBNAILS ===== */

	$('#pod-thumbs a.thumb, #content div.menu-item').each(function() {
		var getRel = $(this).attr('rel');
		$(this).css('background', 'url(' + getRel + ') top left no-repeat');
	});

	/* ===== REMOVE BORDERS, REMOVE PADDING, ETC... ===== */

	removeBorder('#nav-utility li:last');
	$('#nav-main-parent ul').each(function() {
		$('a:last', this).addClass('noborder');
	});
	$('a[href="#"]').click(function() {
		return false;
	});
	$('a[href="#top"]').click(function() {
		$('html, body').animate({
			scrollTop : 0
		}, 100);
		return false;
	});

});

/* ===== MENU ITEM ===== */

$(document).ready(function() {
	/* Added to fix OGRD-231 [CG 02-03] */
	/*$("#nav-main ul ul li").addClass("menu_middle_border");
	
	$("#nav-main ul ul > :first-child").removeClass("menu_middle_border");
	$("#nav-main ul ul > :last-child").removeClass("menu_middle_border");
	
	$("#nav-main ul ul > :first-child").addClass("menu_left_border");
	$("#nav-main ul ul > :last-child").addClass("menu_right_border");*/
	/* ------ */
	
	$('#nav-main ul ul:has(li)').append('<li class="last_child"><div></div></li>');	
	
	$('#other-menu-nav #sum').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#myMenu').show();
		
		$('#other-menu-nav #item-arrow').css("left", "33px");
	});

	$('#other-menu-nav #nut').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#nutrition-details').show();
		
		$('#other-menu-nav #item-arrow').css("left", "102px");
	});

	function hidePanels() {
		$('#other-menu-nav #sum').removeClass("selected");
		$('#other-menu-nav #nut').removeClass("selected");

		$('#myMenu').hide();
		$('#nutrition-details').hide();
	}	
		
	$(".panel_header").click(function(){
		$(this).children(".arrow").toggleClass("arrow-selected");
	});
});

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

/* ===== SHARED MENU CART ===== Moved to ogMenuItem.ascx */

//$(document).ready(function() {
//	$('#other-menu-nav #bp').click(function() {
//		hidePanels();
//		$(this).toggleClass("selected");
//		$('#beverage').show();
//		$('#beverage .category-items').show();
//		
//		$('#other-menu-nav #item-arrow').css("left", "60px");
//	});

//	$('#other-menu-nav #nt').click(function() {
//		hidePanels();
//		$(this).toggleClass("selected");
//		$('#nutrition-details').show();
//		
//		$('#other-menu-nav #item-arrow').css("left", "172px");
//	});

//	$('#other-menu-nav #sg').click(function() {
//		hidePanels();
//		$(this).addClass("selected");
//		$('.category-items').show();
//		
//		$('#other-menu-nav #item-arrow').css("left", "265px");
//	});

//	function hidePanels() {
//		$('#other-menu-nav #bp').removeClass("selected");
//		$('#other-menu-nav #nt').removeClass("selected");
//		$('#other-menu-nav #sg').removeClass("selected");
//		
//		$('.category-items').hide();
//		$('#nutrition-details').hide();
//		$('#beverage').hide();
//}
//});

/* ===== VIDEO ===== */

$(document).ready(function() {
	$('#other-menu-nav #feat').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#featured_content').show();		
		$('#other-menu-nav #item-arrow').css("left", "25px");
	});
	$('#other-menu-nav #cook').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#cooking_content').show();		
		$('#other-menu-nav #item-arrow').css("left", "98px");
	});
	$('#other-menu-nav #cul').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#culinary_content').show();		
		$('#other-menu-nav #item-arrow').css("left", "204px");
	});
	$('#other-menu-nav #tv').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#tv_content').show();		
		$('#other-menu-nav #item-arrow').css("left", "291px");
	});
	$('#other-menu-nav #oth').click(function() {
		hidePanels();
		$(this).toggleClass("selected");
		$('#other_content').show();		
		$('#other-menu-nav #item-arrow').css("left", "370px");
	});

	function hidePanels() {
		$('#other-menu-nav #feat').removeClass("selected");
		$('#other-menu-nav #cook').removeClass("selected");
		$('#other-menu-nav #cul').removeClass("selected");
		$('#other-menu-nav #tv').removeClass("selected");
		$('#other-menu-nav #oth').removeClass("selected");
		
		$('#featured_content').hide();
		$('#cooking_content').hide();
		$('#culinary_content').hide();
		$('#tv_content').hide();
		$('#other_content').hide();
	}
});

function removeBorder(ref) {
	$(ref).addClass('noborder');
}
/* / */// /////////////////////////////////////////////*/
(function(a) {
	a.fn.number_slideshow = function(p) {
		var p = p || {};
		var n = p && p.slideshow_autoplay ? p.slideshow_autoplay : "enable";
		var o = p && p.slideshow_time_interval ? p.slideshow_time_interval: "5000";
		var q = p && p.slideshow_window_background_color ? p.slideshow_window_background_color: "white";
		var r = p && p.slideshow_window_padding ? p.slideshow_window_padding: "5";
		var s = p && p.slideshow_window_width ? p.slideshow_window_width: "";
		var t = p && p.slideshow_window_height ? p.slideshow_window_height: "";
		var u = p && p.slideshow_border_size ? p.slideshow_border_size : "1";
		var v = p && p.slideshow_border_color ? p.slideshow_border_color: "black";
		var w = p && p.slideshow_show_button ? p.slideshow_show_button: "enable";
		var H = p && p.slideshow_show_title ? p.slideshow_show_title : "enable";
		var x = p && p.slideshow_button_text_color ? p.slideshow_button_text_color: "red";
		var z = p && p.slideshow_button_background_color ? p.slideshow_button_background_color: "black";
		var A = p && p.slideshow_button_current_background_color ? p.slideshow_button_current_background_color: "white";
		var B = p && p.slideshow_button_border_color ? p.slideshow_button_border_color: "blue";
		var C = p && p.slideshow_button_border_size ? p.slideshow_button_border_size: "2";
		var s_l_g = p && p.slideshow_loading_gif ? p.slideshow_loading_gif: "";
		r += "px";
		s += "px";
		t += "px";
		u += "px";
		C += "px";
		var D;
		var E = 0;
		var F = a(this);
		var G = F.find("ul:first").children("li").length;
		if (F.find("ul").length == 0 || F.find("li").length == 0) {
			/*a.append("Require content");*/
			return null
		}
		F.show();
		F.find("ul:first").children("li").children("a").children("img").css(
				"width", s).css("height", t);
		F.find("ul:first").css("background-image", "url(" + s_l_g + ")").css(
				"background-position", "center center");
		s_s_ul(F.find("ul:first"), r, s, t, u, v, q, z, x, s_l_g);
		s_s_n(F.find(".number_slideshow_nav"), x, w, z, A, B, C);
		F.find("ul:first").children("li").hide();
		var img = new Image();
		img.src = F.find("ul:first").children("li").eq(0).children("a")
				.children("img").attr("src");

		img.onload = play;
		if (img.complete) {
			play();
		}
		F.find("ul:first").hover(function() {
			clearTimeout(D);
		}, function() {
			D = setTimeout(play, o);
		});
		F.find(".number_slideshow_nav").children("li").hover(function() {
			stop($(this))
		});
		function play() {
			if (n == "enable") {
				clearTimeout(D);
				F.find("ul:first").children("li").fadeOut();
				F.find("ul:first").children("li").eq(E).fadeIn();
				F.find(".number_slideshow_nav").children("li").removeClass(
						'current').addClass('active');
				F.find(".number_slideshow_nav").children("li").eq(E)
						.removeClass('active').addClass('current');
				E++;
				if (E >= G) {
					E = 0
				}
				D = setTimeout(play, o)
			} else {
				F.find("ul:first").children("li").eq(E).fadeIn();
			}
		}
		function stop(a) {
			clearTimeout(D);
			var b = a.parent().children().index(a);
			if (b != (E - 1)) {
				E = b + 1;
				if (E >= G) {
					E = 0
				}
				F.find("ul:first").children("li").fadeOut();
				F.find("ul:first").children("li").eq(b).fadeIn();
				F.find(".number_slideshow_nav").children("li").removeClass(
						'current').addClass('active');

				F.find(".number_slideshow_nav").children("li").eq(b)
						.removeClass('active').addClass('current');
			}
		}
		function s_s_ul(a, b, c, d, e, f, g, h, i, l_g) {
			a.children("li").css("width", c).css("height", d);
			if (H == 'enable') {
				a.children("li").each(
						function(i) {
							a.children("li").eq(i).append(
									"<p>"
											+ a.children("li").eq(i).children(
													"a").children("img").attr(
													"alt") + "</p>");

						});
			}
			a.children("li").children("p").css("background-color", h).css(
					"color", i).css('width', parseInt(c) - 10);
			b = parseInt(b);
			c = parseInt(c);
			d = parseInt(d);
			e = parseInt(e);
			var h = c + e * 2 + b * 2;
			var i = d + e * 2 + b * 2;
			F.css("width", h);
			F.css("height", i);
			var j = d + "px";
			var k = c + "px";
			var l = "border: " + f + " solid " + " " + e + "px; height:" + j
					+ "; width:" + k + "; padding:" + b
					+ "px; background-color:" + g + "; background-image:url("
					+ l_g + ");";
			a.attr("style", l)
		}
		function s_s_n(b, c, d, e, f, g, h) {
			h = parseInt(h);
			var j = b.children("li");
			var a = j.children("a");
			a.css("color", c);
			var k = "border: " + g + " solid " + " " + h
					+ "px; background-color:" + e + ";";
			j.attr("style", k);
			if (d != "enable") {
				b.hide()
			}
		}
	}
})(jQuery);

/* ===== ZIP CODE ===== */
// Accordion O
function ZipCode() {
	  $('#restaurants_area ul').hide();
	  $('#restaurants_area ul:first').prev().find("span.local_name").addClass("activeZipCode");
	  $('#restaurants_area ul:first').show();
	  $('#restaurants_area li a').click(
	    function() {
	    	
	    	$("span.local_name").removeClass("activeZipCode");
    		$(this).find("span.local_name").addClass("activeZipCode");
	    	
	    	
	      var checkElement = $(this).next();
	      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
	        return false;
	        }
	      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
	    	  
	        $('#restaurants_area ul:visible').slideUp('normal');
	        checkElement.slideDown('normal');
	        return false;
	        }
	      }
	    );
	  }
$(document).ready(function() {ZipCode();});

$(document).ready(function (){
$(".expand").click(function () {
	$(this).next().toggle();
	$(this).parent().toggleClass("mod_management mod_body arrow_brown selected");
    return false;
});
});
$(document).ready(function() {
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);
        document.getElementById("mask").scrollIntoView();

        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        $(id).fadeIn(1000);

        $(".modal_content .find_restaurant .find_form input#txtSearch").focus();
    });

    $('.window .btn_close').click(function(e) {

        e.preventDefault();



        $('#mask').fadeOut(1000);

        $('.window').fadeOut(1000);

    });


});

// Menu JS
function setWidth(sObjId, nWidth){
    $('#' + sObjId).css("width", nWidth); //170
    $('#' + sObjId + " li").css("width", nWidth - 38); //132
    $('#' + sObjId + " li:hover").css("width", nWidth - 34); //136
    $('#' + sObjId + " li.last_child").css("width", nWidth); //170
    $('#' + sObjId + " li.last_child div").css("width", nWidth - 7); //163
    $('#' + sObjId + " li").hover(function(){
        if (!$(this).hasClass("last_child")) {
            $(this).css("width", nWidth - 34); /*136*/
        }
    }, function(){
        if (!$(this).hasClass("last_child")) {
            $(this).css("width", nWidth - 38); /*136*/
        }
    });
}

$(document).ready(function(){
    setWidth("menu-menu", 170);
});


var menuh = {

    fadesettings: {
        overduration: 350,
        outduration: 100
    }, //duration of fade in/ out animation, in milliseconds
    buildmenu: function(menuid, arrowsvar){
        jQuery(document).ready(function($){
            var $mainmenu = $("#" + menuid + ">ul")
            var $headers = $mainmenu.find("ul").parent()
            $headers.each(function(i){
                var $curobj = $(this)
                var $subul = $(this).find('ul:eq(0)')
                this._dimensions = {
                    w: this.offsetWidth,
                    h: this.offsetHeight,
                    subulw: $subul.outerWidth(),
                    subulh: $subul.outerHeight()
                }
                this.istopheader = $curobj.parents("ul").length == 1 ? true : false
                $subul.css({
                    top: this.istopheader ? this._dimensions.h + "px" : 0
                })
                
                $curobj.hover(function(e){
                    var $targetul = $(this).children("ul:eq(0)")
                    this._offsets = {
                        left: $(this).offset().left,
                        top: $(this).offset().top
                    }
                    var menuleft = this.istopheader ? 0 : this._dimensions.w
                    menuleft = (this._offsets.left + menuleft + this._dimensions.subulw > $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
                    $targetul.css({
                        left: menuleft + "px"
                    }).fadeIn(menuh.fadesettings.overduration)
                }, function(e){
                    $(this).children("ul:eq(0)").fadeOut(menuh.fadesettings.outduration)
                }) //fin hover
            }) //fin principal()
            $mainmenu.find("ul").css({
                display: 'none',
                visibility: 'visible'
            })
        }) //fin carga de menu
    }
}
menuh.buildmenu("nav-main")
