$(document).ready(function () {







    //   Overlay2
    if ($(".overlay2").length) {
        $(".overlay2").css("width", $(document).width() + "px");
        $(".overlay2").css("height", $(document).height() + "px");
        $(".overlay2").click(function () {
            $(this).hide();
            $("#pop-Subscription").removeClass("on");
            $("#pop-Error").removeClass("on");
            $(".pop-data .close").hide();
            $(".pop").fadeOut();


            return false;
        });
    }


    // Subscription Close
    $(".pop-data .close").click(function () {
        $(".overlay2").hide();
        $("#pop-Subscription").removeClass("on");
        $("#pop-Error").removeClass("on");

        $(".pop-data .close").hide();

        $(".pop").fadeOut();


        return false;
    });


    // Tooltip
    if ($(".prod-info").length) {

        $(".prod-info").click(function () {

            $(".overlay").show(0);

            //   SetProductImagePosition();
            var currentTab = $(".tabs a.active");
            var TabNumber = currentTab.attr("id").charAt(3);

            // find current subtab id  (tab1box1)
            var ActiveSubTabId = $(".boxes .active").attr("id");
            var SubProductNo = ActiveSubTabId.charAt(7);
            //      debugger;
            $(".div-prod-info div." + ActiveSubTabId + "inf" + SubProductNo).fadeIn(400);

            return false;
        });
        $(".inf .close").click(function () {
            $(".inf").fadeOut(400);
            $(".overlay").hide(0);

            return false;
        });
    }


    // Footer slider
    if ($(".footer-slider").length) {
        $('.footer-slider').bxSlider({
            mode: 'horizontal', 		//Type of transition between each slide
            auto: false, 				//Make slide transitions occur automatically
            speed: 500, 				//In ms, duration of time slide transitions will occupy
            pause: 4000, 			//In ms, the duration between each slide transition
            pager: false, 			//Display a numeric pager
            controls: false, 		//Display previous and next controls
            displaySlideQty: 5, 		//Number of slides to display at once
            moveSlideQty: 5				//Number of slides to move at once
        });
    }

    // Header slider
    if ($(".home-slider").length) {
        $('.home-slider').bxSlider({
            mode: 'fade', 		//Type of transition between each slide
            auto: true, 			//Make slide transitions occur automatically
            speed: 1000, 		//In ms, duration of time slide transitions will occupy
            pause: 4000, 		//In ms, the duration between each slide transition
            pager: true, 		//Display a numeric pager
            controls: false			//Display previous and next controls
        });
    }

    // Product tabs
    if ($(".prod-slider").length) {
        $('.prod-slider').each(function () {
            $(this).bxSlider({
                mode: 'horizontal', 	//Type of transition between each slide
                auto: false, 		//Make slide transitions occur automatically
                speed: 1000, 		//In ms, duration of time slide transitions will occupy
                pause: 4000, 		//In ms, the duration between each slide transition
                pager: false, 		//Display a numeric pager
                controls: true, //Display previous and next controls
                captions: true,
                startingSlide: 0

            });

        });

    }


    // If URL contains tab number then Activate respective product panel      

    var hash = window.location.hash;
    if (hash.length) {
        //    debugger;
        var tabno = hash.charAt(hash.length - 1);
        ActivateProductPanel("tab" + tabno);
    }


    // Overlay
    if ($(".overlay").length) {
        $(".overlay").css("width", $(document).width() + "px");
        $(".overlay").css("height", $(document).height() + "px");
        $(".overlay").click(function () {

            $(this).hide();

            $(".inf").fadeOut(400);

            return false;
        });
    }


    // Tab boxes
    if ($(".boxes").length) {

        if ($(".tabs a.active").length) {
            $("." + $(".tabs a.active").attr("id") + "box").slideDown(400);

        } else {
            $(".tabs a:eq(0)").trigger("click");
        }
        //   debugger;
        $(".boxes a").click(function () {
            //  debugger;


            if (!$(this).hasClass("active")) {

                $(".boxes a").removeClass("active");
                $(".boxes div").removeClass("currentbox");
                $(".product-pic div").removeClass("active");


                $(this).addClass("active");
                var currentTab = $(".tabs a.active");
                var TabNumber = currentTab.attr("id").charAt(3);

                var subtabid = $(this).attr("id");
                //    debugger;

                $(".product-pic " + ".product" + subtabid).addClass("active");
                $(".boxes a." + subtabid).addClass("active");
                $(".boxes a.active").parent().addClass("currentbox");

            }
            return false
        });


        $(".tabs a").click(function () {

            if (!$(this).hasClass("active")) {
                ActivateProductPanel($(this).attr("id"));
            }

            return false
        });

    }

    // Bind Footer-Column3 with respective Product Tab 
    $('.column3 a').click(function () {

        $(this).addClass("active");
        var pathname = window.location.pathname;

        if (pathname == '/Range/') {

            jQuery("html, body").scrollTop(100);
            $(".column3 a").removeClass("active");
            $(this).addClass("active");
            var CurrentTabId = $(".column3 a.active").attr("class");
            var TabNo = CurrentTabId.charAt(3);
            ActivateProductPanel("tab" + TabNo);

            //   $('#tab' + TabNo).trigger('click');

        }
        else {

            //     debugger;
            var CurrentTabId = $(".column3 a.active").attr("class");
            var TabNo = CurrentTabId.charAt(3);
            window.location.href = "/Range/#tab=" + TabNo;

        }

    });

});


function ActivateProductPanel( Tabid ) {

        var PrevActiveTabId = $(".tabs a.active").attr("id");
        var PrevActiveTabNo = PrevActiveTabId.charAt(3);        
        $(".product-pic div.tab" + PrevActiveTabNo + "product").removeClass("active");       
        
        $(".boxes a").removeClass("active");

        $(".boxes div").removeClass("currentbox");

        $(".tabs a").removeClass("active");

        $("#"+Tabid).addClass("active");

        $(".boxes").slideUp(400);

        $("." + Tabid + "box").slideDown(400);

        var CurrentTabId = $(".tabs a.active").attr("id");

        var CurrentTabNo = CurrentTabId.charAt(3);

        // tab3product.productbox3
        $(".producttab" + CurrentTabNo + "box1").addClass("active");

        $(".boxes #tab" + CurrentTabNo + "box1").parent().addClass("currentbox");

        $(".boxes #tab" + CurrentTabNo + "box1").addClass("active");

}


function SubscriptionPopUp(popType) {

    $(document).ready(function () {

        var v = $("#pop-" + popType).attr("id");

        $(v).addClass("on");
        $(".overlay2").show(0);
        $(".pop").fadeIn("slow");
        $('#' + v).fadeIn("slow");
        $('#' + v).addClass("active");
        $(".pop-data .close").css("display","block");      

    });
}
