$(function(){
    var currentURL = window.location;
	if ((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<="8")) { } else {
		$(".Phuse_PanelContainingDiv td").each(function(){ $(this).css("width",$(this).parent().parent().parent().attr("width")+"px"); });
	}
    /* Body Load */
    $(".MMDataCaptureForm_Table tr").each(function(){
        var label = $(".MMDataCaptureForm_LabelTD",this).text()+"<br/>";
        var input = $(".MMDataCaptureForm_Input",this);
        input.removeAttr("style").before(label).val("").wrap("<div class=\"mm_input\"></div>");
    });
    var pagingItems = Math.ceil(eval($(".news_item").length)/4);
    var countItems = 1;
    $("#news_feed").after("<div class=\"paging\"><strong>Page</strong> </div>");
    while (countItems<=pagingItems) {
        $(".paging").append("<span id=\""+countItems+"\">"+countItems+"</span>");
        countItems++;
    }
    $(".paging span:first").addClass("active");
    $("#left_col .MMDataCaptureForm_Table").wrap("<fieldset id=\"contact_container\"></fieldset>");
    $("fieldset").prepend("<legend>Send&nbsp;Us&nbsp;a&nbsp;Message</legend>");
    $("#blogFeed").html($("#blogItems").html());
    $(".testimonial").hide();
    $(".testimonial:eq("+Math.floor(Math.random()*$(".testimonial").length)+")").show();
    $("a[href$='/services/default.phuse']").removeAttr("href").parent().parent().parent().removeAttr("onclick");
    $("a[href$='/services/']").removeAttr("href");
    
    /* Interaction */
    $("#print").click(function(){ window.print(); });
    $("#stumble").click(function(){ location.href="http://www.stumbleupon.com/submit?url="+currentURL+""; });
    $("#delicious").click(function(){ location.href="http://del.icio.us/post?url="+currentURL+""; });
    $("#facebook").click(function(){ location.href="http://www.facebook.com/sharer.php?u="+currentURL+""; });
    $("#digg").click(function(){ location.href="http://digg.com/submit?url="+currentURL+""; });
    $("#reddit").click(function(){ location.href="http://reddit.com/submit?url="+currentURL+""; });
    $("#netvibes").click(function(){ location.href="http://www.netvibes.com/share?url="+currentURL+""; });
    $(".paging span").click(function(){
        $(".paging span").removeClass("active");
        $(this).addClass("active");
        var pageNumber=$(this).attr("id")-1;
        $(".news_item").animate({"top":"-"+eval(pageNumber*505)+"px"},{duration:1250});
    });
    
    /* IE6 Hacks :( */
    if ((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version=="6")) {
        $("img").each(function(){
            var gifReplace = $(this).attr("src");
            gifReplace = gifReplace.replace("png","gif");
            gifReplace = gifReplace.replace("png","gif");
            $(this).attr("src",gifReplace);
        });
    }
});
