// Cufon
Cufon.replace("#intro h1, #intro h2", { fontFamily: "MyriadBold" });
Cufon.now();

// Object model
if (!MB) var MB = {};

// vars

// public functions
function XXX() {
    
}

// private functions
MB.Nav = function(selector) {
    var obj = jQuery(selector);
    var item = obj.find(".selected");
    
    item.prev().addClass("beforeSelected");
    item.next().addClass("afterSelected");
}

MB.Banner = function(selector) {
    var obj = jQuery(selector);
    var item = obj.find("p:first-child");

    item.addClass("current");
    item.animate({ "opacity": 0 }, 500, function() {
        item.removeClass("current").remove().appendTo(selector).css("opacity", 1);
    });
}

MB.Styling = function() {
    jQuery(".content h1, .content h2, .content h3").each(function() {
        jQuery(this).prepend("<span/>");
    });
    if (!jQuery(".leftSide > *").length) jQuery(".leftSide").remove();
    if (!jQuery(".rightSide > *").length) jQuery(".rightSide").remove();
    jQuery(".overlay").css("opacity", 0.5);
}

MB.Popup = function() {
    jQuery("a.employeeInfo").click(function(e){
		e.preventDefault();
		var self = this;
		jQuery(".overlay").fadeIn(500, function(){
			jQuery(".popup").html(jQuery(self).parents("p").next(".employee").html());
			jQuery(".popup").fadeIn(500);
		});
    });
    jQuery("body *:not('.popup, .popup *')").click(function(){
		if(jQuery(".popup:visible").length){
			jQuery(".popup").fadeOut(500, function(){
				jQuery(".overlay").fadeOut(500);
			});
		}
    });
}

// DOM ready
jQuery(function() {
    new MB.Nav("#nav");
    setInterval(function() { new MB.Banner("#intro .illustration") }, 5000);    
    new MB.Styling();
    new MB.Popup();
});
