$(function () {
    var currentURL = window.location;
    var baseURL = "http://www.thechargepoint.com";
    //Body Load


    var tabOne = $(".proposition:eq(0) .tab").html();
    var tabTwo = $(".proposition:eq(1) .tab").html();
    var tabThree = $(".proposition:eq(2) .tab").html();
    var tabFour = $(".proposition:eq(3) .tab").html();
    $(".small_tabs").html("<ul><li>" + tabOne + "</li><li>" + tabTwo + "</li><li>" + tabThree + "</li><li>" + tabFour + "</li></ul>");
    $(".small_tabs li").fullLink();

    if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version <= "8")) { } else {
        $(".Phuse_PanelContainingDiv td").each(function () { $(this).css("width", $(this).parent().parent().parent().attr("width") + "px"); });
    }
    $(".NavigationMenu td:first").addClass("nav_first");
    $(".NavigationMenu td:last").addClass("nav_last");
    $("#right_col .myForm tr").not("#right_col .myForm tr:last").not("#right_col .myForm tr:eq(5)").each(function () {
        var $this = $(this);
        $("td:first", $this).hide();           
         $("td:last", $this).html("<span class='label'>" + $("td:first", $this).text() + "<span><div class='mm_form'>" + $("td:last", $this).html() + "</div>");
       
    });
    $("#right_col .myForm .mm_form textarea").parent().removeClass("mm_form").addClass("mm_textarea");
    $("#right_col .myForm tr:last td:first").hide();
    $("#right_col .myForm tr:last td:last").addClass("mm_submit").children("input").attr("value", "");
    $("#generic_right .myForm tr").not("#generic_right .myForm tr:last").each(function () {
        var $this = $(this);
        $("td:first", $this).hide();
        $("td:last", $this).html("<span class='label'>" + $("td:first", $this).text() + "<span><div class='mm_form'>" + $("td:last", $this).html() + "</div>");
    });
    $("#generic_right .myForm .mm_form textarea").parent().removeClass("mm_form").addClass("mm_textarea");
    $("#generic_right .myForm tr:last td:first").hide();
    $("#generic_right .myForm tr:last td:last").addClass("mm_submit").children("input").attr("value", "");


    $("#breadcrumb").each(function () {
        var charReplace = $(this).html();
        charReplace = charReplace.replace("&gt;", "|");
        charReplace = charReplace.replace("&gt;", "|");
        charReplace = charReplace.replace("&gt;", "|");
        charReplace = charReplace.replace("&gt;", "|");
        charReplace = charReplace.replace("&gt;", "|");
        $(this).html(charReplace);
    });
    $("a[href='" + currentURL + "']").addClass("active");
    $("#product_tabs #overview").show();
    $(".document_list_item").each(function () {
        var thisItem = $(this);
        var ext = $(".content a", thisItem).attr("href").split(".").pop().toLowerCase();
        var file = baseURL + "/res/builtin/file_" + ext + ".gif";
        $.ajax({
            url: file,
            success: function () {
                $(".image", thisItem).html('<img src="' + file + '" />');
            },
            error: function (xhr, d, e) {
                if (xhr.status == 404) {
                    //do nothing
                }
            }
        });
    });
    $("#blog_feed li:eq(2)").css("background", "none");

    //User Interaction
    $(".product_list,.phuse_feed,.document_list").pagination({ pageText: "Page:" });
    $("#product_options td").live("click", function () {
        var thisTD = $(this);
        $("#product_options td.active,#product_tab .active").removeClass("active");
        thisTD.addClass("active");
        $("#product_tabs .product_tab").hide();
        $("#product_tabs #" + thisTD.attr("rel")).fadeIn();
    });

});
