$(function() {
	if ($(".homeTemplate").length > 0) {
			$(".homeTemplate .whiteBackground").css({ opacity : ".9" });
	}
	
	bc.buildAjaxOverlays();
});

var bc = {
	buildAjaxOverlays : function() {
		$("body").append("<div id='svlvOverlay'></div>");
		this.buildAjaxOverlay($(".svlvOverlayLink"));
	},
	buildAjaxOverlay : function(nodes) {
		nodes.each(function() {
			$(this).attr("rel", "#svlvOverlay");
		});
		nodes.overlay({
			mask : "#444",
			onBeforeLoad : function() {
				var overlay = $("#svlvOverlay");
				if(overlay.children(".content").length > 0) {
					overlay.children(".content").remove();	
				}
				
				if (this.getTrigger().attr("data-width")) {
					overlay.css("width", this.getTrigger().attr('data-width') + "px");
				} else {
					overlay.css("width", "auto");	
				}
				
				var content = $("<div class='content'></div>");
				content.css("left", -10000);
				content.load(this.getTrigger().attr("href"), function() {
					bc.centerOverlay(overlay);	
				});
				
				overlay.append(content);
			},
			onClose : function() {
				$("#svlvOverlay > .content").remove();
			},
			closeOnClick : false,
			fixed : false
		});
	},
	centerOverlay : function(node) {
		node.css("left", ($(window).width() - node.width()) / 2);
		node.css("top", (($(window).height() - node.height()) / 2) + $(window).scrollTop());
		node.children(".content").css("left", "auto");
	}
}
