﻿function InitialiseSwishyTabs(animationRate)
{
    // Swishy Tabs
    if (document.getElementById('interactiveTabs') && $(".swishytabs-controls li").length > 1)
    {
        /*
        # Swishy Tabs
        */
        swishytabsConatiner = $(".swishytabs-container");

        $(".container", swishytabsConatiner).each(
			function()
			{
			    $(this).css("height", $(this)[0].offsetHeight).css("position", "static");
			}
		);

        $(".container", swishytabsConatiner).css("opacity", "0").css("display", "none");
        $($(".swishytabs-controls .selected a").attr("href")).css("opacity", "100").css("display", "block").addClass("current");

        swishytabsConatiner.css("height", swishytabsConatiner[0].offsetHeight);

        $(".swishytabs-controls li").click(
			function()
			{
			    //swishytabsConatiner.children().addClass("offleft")
			    //$(this).removeClass("selected");
			    if ($(":animated").length < 1 && !this.className.match("selected"))
			    {
			        $(".swishytabs-controls li").removeClass("selected");
			        swishytabsNextTab = $($("a", this).attr("href"));
			        swishytabsNextTab.addClass("next");


			        $(".current").animate({ opacity: 0 }, 5 * animationRate, function()
			        {
			            $(this).removeClass("current").css("display", "none");

			            //console.log($(".swishytabs-container .next").css("height"));
			            $(".swishytabs-container").animate({ height: $(".swishytabs-container .next").css("height") }, 4 * animationRate, "swing", function()
			            {
			                $(".swishytabs-container .next").css("display", "block").animate({ opacity: 100 }, 10 * animationRate, function()
			                {
			                    $(this).removeClass("next").addClass("current");
			                    //$(".swishytabs-controls li:contains()")

			                    //Get the javascript that we need to execute upon change of tab
			                    var eventToFire = $("#deliveryType_ChangeEvent").val();
			                    if (eventToFire != undefined)
			                    {
			                        eval(eventToFire);
			                    }
			                });
			            });
			        });
			        $(this).addClass("selected");
			        // if delTabs then update deliverytype hidden field
			        if (document.getElementById('delTabs'))
			        {
			            //Get the id of the hidden field that needs to be updated for these tabs from the deliveryTypeID hidden field
			            var deliveryTypeFieldId = $("#deliveryTypeID").val();
			            if (deliveryTypeFieldId == undefined)
			            {
			                //If it is not provided in the deliveryTypeID hidden field, use the default
			                deliveryTypeFieldId = "deliveryType";
			            }

			            //Update the hidden field with the name of the currently selected tab
			            $("#" + deliveryTypeFieldId).val($(this).text());
			        }
			    }

			    return false;
			}
		);
    }
}
