﻿$(document).ready(function () {
    Cufon.replace('h1');

    $('#dnn_dnnSEARCH_txtSearch').val('Search Our Site'); //add the search text to the search input
    $("#dnn_dnnSEARCH_txtSearch").focus(function () { //clear the default text out of the search input

        if ($(this).val() == "Search Our Site") {
            $(this).val('');
        }

    });

    $('.product-table tr').each(function () {
        $('td:first', this).addClass("product-td-first");
        $('td:last', this).addClass("product-td-last");
        $('td:empty', this).prev().css("border", "0");


    });
    $('.product-table').each(function () {

        $('tr', this).after('<tr class="gg"><td colspan="4" class="spacer">&nbsp;</td></tr>');

    });


    if ($(".tab-content h3").length > 0) {
        $(".tab-content").hide();
        $(".module-title").hide();
        var strTabContent = "<div class=\"tabs-content\">\n";
        var strTabUL = "<div class=\"tab-navigation\">\n<ul>\n";
        var intTabCount = 0;
        var strTabTitle;
        $(".tab-content").each(function () {
            strTabTitle = $(".module-title", this).text();
            strTabUL += "<li><a id=\"tabs-nav-" + (intTabCount + 1) + "\" href=\"#tabcontent" + intTabCount + "\"><span>" + strTabTitle + "</span></a></li>\n";
            strTabContent += "<div class=\"tab-details\" id=\"tabcontent" + intTabCount + "\">" + $(this).html() + "</div>\n";
            intTabCount++;
        });

        strTabUL += "</ul></div>";
        strTabContent += "</div>";

        $(".tab-content:first").replaceWith("<div class=\"tabs-holder\">" + strTabUL + strTabContent + "</div>");
        $(".tab-details:first").show();
        $(".tab-navigation").addClass("tab1-active");
        $(".tab-navigation li:first").addClass("active");
        $(".tab-navigation a").click(function () {
            if (!$(this).parent().hasClass("active")) {

                var strContent = $(this).attr("href").split("#")[1];
                $(".tab-navigation li").removeClass("active");
                $(this).parent().addClass("active");

                if (this.id === "tabs-nav-1") {
                    $(".tab-navigation").removeClass("tab2-active").addClass("tab1-active");
                } else {
                    $(".tab-navigation").removeClass("tab1-active").addClass("tab2-active");
                }

                $(".tab-details").hide();
                $("#" + strContent).fadeIn("normal");
            }
            $(this).blur();

            return false;
        });
    }
    if ($(".collapse-wrap").length > 0) {
        $(".collapse-wrap .title").click(function () {
            if ($(this).parent().find(".collapse-content").css("display") != "block") {
                $(this).addClass("collapse-expanded");
                $(this).parent().find(".collapse-content").slideDown("fast");
            } else {
                $(this).removeClass("collapse-expanded");
                $(this).parent().find(".collapse-content").slideUp("fast");
            }
        });
    }
    if ($(".collapse-wrap").length > 1) {
        //$(".collapse-wrap:first").prepend("<p><a href=\"javascript:void(0);\" class=\"collapsible-collapse-all\">Collapse All</a> | <a href=\"javascript:void(0);\" class=\"collapsible-expand-all\">Expand All</a></p>");
        $(".collapsible-collapse-all").click(function () {
            expandAll('collapse');
        });
        $(".collapsible-expand-all").click(function () {
            expandAll('expand');
        });
    }

    return false;
});

// expand/collapse all collapsible content
function expandAll(strMode) {
    if (strMode == "expand") {
        $(".collapse-wrap .title").each(function () {
            $(this).addClass("collapse-expanded");
            $(this).parent().find(".collapse-content").slideDown("fast");
        });
    } else {
        $(".collapse-wrap .title").each(function () {
            $(this).removeClass("collapse-expanded");
            $(this).parent().find(".collapse-content").slideUp("fast");
        });
    }
}

