$(function () {
    var baseURL = "";
    var currentURL = window.location;

    $(".service a, .items .news a, .story .link a, .member .link a").each(function () {
        var dashReplace = $(this).attr("href");
        dashReplace = dashReplace.substr(7).replace("//", "/");
        dashReplace = dashReplace.replace("//", "/");
        $(this).attr("href", "http://" + dashReplace)
    });

    $(".content_left .Phuse_SiteMap_UL .Phuse_SiteMap_LI a").each(function () {
        if ($(this).attr("href") == currentURL) {
            $(this).parent().addClass("open_ul");
            $(".open_ul .Phuse_SiteMap_UL:first").show();
            $(".open_li").attr("style", "height: auto;");
            $(this).attr("style", "background: url(http://staging.ph-creative.com/sites/laurencelee/res/builtin/sub_nav_active.gif) repeat-y top right;");
        }
    });

    $(".content_left .Phuse_SiteMap_UL .Phuse_SiteMap_LI .Phuse_SiteMap_UL .Phuse_SiteMap_LI a").each(function () {
        if ($(this).attr("href") == currentURL) {
            $(this).parent().parent().parent().addClass("open_ul");
            $(this).parent().addClass("open_ul");
            $(".open_ul").parent().show();
        }
    });

    $(".service, .blog_post").fullLink();
    $(".as_seen_on:last").hide();

    $(".news_feed .items, .news_feed .more_news, .rss").hide();
    $(".news_feed h3").after("<p>Coming Soon!</p>");

    //Body Load


    $("#breadcrumb").each(function () {
        var charReplace = $(this).html();
        charReplace = charReplace.replace("&gt;", "&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;", "&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;", "&nbsp;/&nbsp;");
        charReplace = charReplace.replace("&gt;", "&nbsp;/&nbsp;");
        $(this).html(charReplace);
    });

    //User Interaction

    $(".side_nav ul").each(function () {
        $("li:last", this).attr("style", "border: none;");
    });

    $("#home .services .service:last").attr("style", "margin-right: 0px; cursor:pointer;");

    $("#footer .top .footer_mid p:first").attr("style", "margin-right: 26px;");
    $("#footer .top .footer_right p:first").attr("style", "margin-right: 26px;");

    $("blockquote").addClass("quote");
    $(".quote p").before("<div class='open'></div>");
    $(".quote p").after("<div class='closed'></div>");
    $(".quote em").wrap("<span></span>");

    $(".testimonial_success_stories .testimonial_story").hide();
    //$(".testimonial_success_stories .testimonial_story:eq("+Math.floor(Math.random()*$(".success_stories .story").length)+")").show();
    $(".testimonial_success_stories, .more_stories").hide();

    var pagingItems1 = Math.ceil(eval($(".stories .story").length - 5) / 5);
    var countItems = 1;

    while (countItems <= pagingItems1 + 1) {
        $(".paging").append("<span id=\"" + countItems + "\">" + countItems + "</span>");
        countItems++;
    }
    $(".paging span:first").addClass("active");
    $(".paging span").click(function () {
        $(".paging span").removeClass("active");
        $(this).addClass("active");
        var pageNumber = $(this).attr("id") - 1;
        $(".stories .story").animate({ "top": "-" + eval(pageNumber * 675) + "px" });

    });


    $(".mm_form tr, .contact_form tr").each(function () {
        $("td:first", this).addClass("label");
        $("td:last", this).addClass("input");
    });
    $(".mm_form .label, .contact_form .label").wrapInner("<div></div>");
    $(".mm_form tr textarea, .contact_form tr textarea").parent().addClass("textarea");

    $(".mm_form, .contact_form").each(function () {
        $("input:last", this).addClass("SubmitButton");
        $(".label:last", this).hide();
        $("tr:last", this).addClass("SubmitButtonTR");
        $("td:last", this).addClass("SubmitButtonTD");
        $(".SubmitButtonTD", this).removeClass("input");
        $("textarea", this).parent().removeClass("input");
        $("textarea", this).parent().addClass("textarea");
        $("form", this).addClass("form");
        $(".textarea", this).prev().addClass("textarea_label");
        $(".textarea_label", this).removeClass("label");
    });

    $(".contact_form").each(function () {
        $(".label:last", this).show();
    });

    $(".mm_form tr").each(function () {
        var labelText = $(".label", this).text();
        var labelTextArea = $(".textarea_label", this).text();
        $(".input input", this).val(labelText);
        $(".textarea textarea", this).val(labelTextArea);
    });

    $(".input input, .textarea textarea").each(function () {
        var thisObj = $(this);
        var thisVal = thisObj.val();
        thisObj.bind("focus", function () {
            if (thisObj.val() == thisVal) { thisObj.val(""); }
        }).bind("blur", function () {
            if (thisObj.val() == "") { thisObj.val(thisVal); }
        });
    });

    $(".search_results_pane .paging_filter a").each(function () {
        $(this).wrap("<span></span>");
        var getStyle = $(this).attr("style");
        if (getStyle == "font-weight: bold; text-decoration: underline;") {
            $(this).css("text-decoration", "none").css("font-weight", "normal").parent().addClass("active");
        }
    });

});
