﻿$(function () {
    $(document).ready(function () {

        $("body").linkHandler({
            selector: 'a',
            cssclass: 'external',
            excludeDomain: ['citygross'],
            useContains: true
        });

        // ---------------------------------------- Jquery Add class ---------------------------------------- //
        $("#tabs li:last").addClass("last");
        $("#contactDetails li:odd").addClass("even");
        $("#youtubePlaylist li:odd").addClass("marginRight0px");
        $("#thisWeeksProducts li:last").addClass("last");
        $("#second .allProductsList li:odd a").addClass("marginRight0px");
        $("#homeAndLeisureProductList li:lt(2)").addClass("marginBottom25px");
        $("#openHoursModal tr > td:nth-child(2n)").addClass("textRight paddingLeft20px paddingBottom5px");
        $("#openHoursModal tr > td:nth-child(3n)").addClass("textRight paddingLeft20px paddingBottom5px");
        $("#homeAndLeisureProductList li:even").addClass("even");
        $("#themeList li:odd").addClass("odd");
        $(".foodPickerList li:nth-child(3n)").addClass("third");

        $(".foodPickerList > li > a").mouseenter(function () {
            $(this).next("span").css("visibility", "visible");
        }).mouseleave(function () {
            $(this).next("span").css("visibility", "hidden");
        });

        // ------------------------------------------ Detect width ------------------------------------------ //

        $("#homeAndLeisureProductList li span.center span, #thisWeeksProducts li span.center span").each(function () {
            var width = $(this).width() + 27;
            $(this).parent().attr("style", "width:" + width + "px;");
            $(this).show();
        });

        // ------------------------------------------ Open hours Modal  ------------------------------------- //

        $(".openHoursModalToggle").colorbox({ width: "300", inline: true, href: "#openHoursModal" });

        // ------------------------------------------ Store ad bulletin Modal  ------------------------------ //

        $(".storeAdBulletinModalToggle").colorbox({ width: "348", inline: true, innerWidth: 348, innerHeight: 340, iframe: true, scrolling: false });

        // ------------------------------------------ Tabs  ------------------------------------------------- //
        //When page loads...
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content

        //On Click Event
        $("ul.tabs li").click(function () {

            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).toggle(); //Fade in the active ID content
            return false;
        });

        // ------------------------------------------ FAQ  -------------------------------------------------- //
        $(document).ready(function () {
            $("#faq .faqAnswer").hide();

            // Add the click behavior
            $("#faq .faqQuestion").click(function () {
                $(this).next(".faqAnswer").toggle();
                $(this).toggleClass("selected");
            });
        });

        // ------------------------------------------ Contact forms  ----------------------------------------- //
        $(".jQueryContactForm .jQueryContactFormToggle").click(function () {
            $(this).next(".jQueryContactFormContent").slideToggle();
            $(this).toggleClass("selected");
        });

    });
});

