Cufon.replace('#sidebar h2, .rounded_box h3, #top_feature a,#email_content, #global_eats_sidebar h4, #bookmarks a, #node_content h4, #node_content h5, .rate_this em, .comment_link, #category_description, #recipe_source h4, #sofi_description h4, #groups_header h4, #groups_header p, #group_members h4, #forums_header h4, #forums_header p, #post_count, a.header, #globaleats h4, #public_profile_location h3, #public_profile_origin h3');

Cufon.replace('#fs-menu a', {
    hover: true
});

function height_padding(theObject) {
    var totalHeight = theObject.height();
    totalHeight += parseInt(theObject.css("padding-top"), 10) + parseInt(theObject.css("padding-bottom"), 10); //Total Padding Width
    totalHeight += parseInt(theObject.css("borderTopWidth"), 10) + parseInt(theObject.css("borderBottomWidth"), 10); //Total Border Width
    return totalHeight
}

function open_login_overlay(heading, caption) {
    $(".overlay").hide();
    $("#overlay_login h2").html(heading);
    $("#overlay_login #login_caption").html(caption);
    $("#overlay_login").css("margin-top", -(height_padding($("#overlay_login"))/2) + 'px');
    $("#overlay_login").show();
}

function open_overlay(object) {
    $(".overlay").hide();
    object.show();
}
    
function close_overlay() {
    $(".overlay").hide();
}

function width_padding(theObject) {
    var totalWidth = theObject.width();
    totalWidth += parseInt(theObject.css("padding-left"), 10) + parseInt(theObject.css("padding-right"), 10); //Total Padding Width
    border_left = parseInt(theObject.css("borderLeftWidth"), 10);
    border_right = parseInt(theObject.css("borderRightWidth"), 10);
    if (!border_left) {
        border_left = 0;
    };
    if (!border_right) {
        border_right = 0;
    };
    totalWidth += border_left + border_right; //Total Border Width
    return totalWidth
}

$(document).ready(function() {
	
    $("li.current ul").show();

	$("#fs-menu > li:first-child").addClass("first");

    $("#fs-menu > li").hover(
        function() {
            $("li.current ul").hide();
            $(this).children("ul").show();
        },
        function() {
            $(this).children("ul").hide();
            $("li.current ul").show();
        });

    // Login Box

	 $("body").click(function() {
		  if ($("#login").is(":visible")) {
            $("#login").hide();
            $("#login_square").remove();
            $("#login_link").show();
		  }
	 });

    $("#login_link").click(function(e) {
        e.preventDefault();
        e.stopPropagation();
		  if($(this).attr("rel") == "nologout") {
				window.location = "/accounts/login/";
				return false;
		  }
        $(this).hide();
        $("#login").before('<span id="login_square">Login</span>');
        $("#login").slideDown("fast");
        var window_left = /*1 + */width_padding($("#login")) - width_padding($("#login_square"));
        var window_new_left = "-" + window_left + "px";
        $("#login").css("left", window_new_left);
    });

    $("#login").click(function(e) {
		  e.stopPropagation();
    });

    $("#login_square").live("click", function() {
        $("#login").hide();
        $(this).remove();
        $("#login_link").show();
    });

    $("input.id_username").focus(function() {
        if ($(this).val() == "Username or Email") {
            $(this).val("")
        }
    });

    $(".temp_pwd").focus(function() {
        $(this).hide();
        $(this).siblings(".id_password").show().focus();
    });

    $("#login #next").val(window.location.pathname);

    $(".overlay .close").click(function() {
        close_overlay();
    });

	 $(document).keyup(function(event){
		  if (event.keyCode == 27) {
				close_overlay();
		  }
	 });

    $("body").click(function() {
        $(".overlay").hide();
    });

    $(".overlay").click(function(e) {
        e.stopPropagation();
    });

	$("a[href^='http://']").click(function(e){
		e.preventDefault();
		window.open($(this).attr('href'));
	});

	 // Rounded Corners
	 function roundMod(selectors, box, placement) {
		var style="position:absolute;display:block;width:9px;height:9px;background:url("+_murl+"images/site/";
		if(box == 'modules') style += "module-rounded.gif)";
		else if(box == 'gray') style += "gray-round.gif)";
		str = "";
		if(placement.search(/tl/i)>-1) str+='<div style="'+style+';top:-1px;left:-1px;"></div>';
		if(placement.search(/tr/i)>-1) str+='<div style="'+style+' -9px 0;top:-1px;right:-1px;"></div>';
		if(placement.search(/bl/i)>-1) str+='<div style="'+style+' 0 -9px;bottom:-1px;left:-1px;"></div>';
		if(placement.search(/br/i)>-1) str+='<div style="'+style+' -9px -9px;bottom:-1px;right:-1px;"></div>';
		if(placement == "") str = '<div style="'+style+';top:-1px;left:-1px;"></div><div style="'+style+' -9px 0;top:-1px;right:-1px;"></div><div style="'+style+' 0 -9px;bottom:-1px;left:-1px;"></div><div style="'+style+' -9px -9px;bottom:-1px;right:-1px;"></div>';
		$(selectors).append(str);
	 }

	 roundMod(".rounded_box:not(#footer,#sidebar,#breadcrumbs,#social)", "modules", "");
	 roundMod("#footer,#sidebar,#breadcrumbs,#social", "gray", "");
	 roundMod("#accounts a:not(#login a,#hello_user span a)", "gray", "bl br");
	 roundMod("#login", "gray", "tl");

	 var menu = $('#fs-menu');
	 if($(menu.children()[0]).hasClass('current')) {
		 var current = '-current';
	 } else {
		 var current = '';
		 $("#fs-menu li:first").hover(function(){$("#fs-menu div:first").css("background","url("+_murl+"images/site/menu-left-hover.gif)");},function(){$("#fs-menu div:first").css("background","url("+_murl+"images/site/menu-left"+current+".gif)");});
	 }
	 menu.append('<div style="position:absolute;top:0;left:0;background:url('+_murl+'images/site/menu-left'+current+'.gif);display:block;width:4px;height:32px;"></div><div style="position:absolute;top:0;right:0;background:url('+_murl+'images/site/menu-right.gif);display:block;width:5px;height:32px;"></div>');

});
