/* NAVIGATION */

Cufon.replace("#navigation a:first", {
  fontWeight : "normal",
  fontFamily : "GillSans",
  hover : {
    color : "#fff"
  }
});
Cufon.replace("#navigation ul#primary_navigation a span ", {
  fontWeight : "bold",
  fontFamily : "GillSans",
  hover : {
    color : "#7a0b0b"
  }
});
Cufon.replace("#navigation ul#secondary_navigation a", {
  fontWeight : "normal",
  fontFamily : "GillSans",
  hover : {
    color : "#fff"
  }
});

/* CONTENT */

Cufon.replace("#title", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-2px"
});
Cufon.replace("#content h2", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-0.5px"
});
Cufon.replace("#content h3", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-1px"
});
Cufon.replace("#content h4", {
  fontFamily : "GillSans",
  fontWeight : "normal"
});
Cufon.replace("#content blockquote", {
  //fontStyle : "italic"
    fontFamily : "GillSansLight"
});

/* BLOCK */

Cufon.replace(".block h2", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-0.5px"
});
Cufon.replace(".block h3", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-0.5px"
});
Cufon.replace(".block h4", {
  fontFamily : "GillSans",
  fontWeight : "normal"
});

/* PROMO */

Cufon.replace(".promo h2", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-2px"
});

/* SLIDESHOW */

Cufon.replace(".slideshow .pager a", {
  fontFamily : "GillSans",
    fontWeight : "bold"
});
Cufon.replace(".slide h2", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-2px"
});

/* BUTTON */

Cufon.replace("a.button", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-1px"
});

/* NEWS TICKER */

Cufon.replace(".news_ticker h2", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-1px"
});

/* FORM */

Cufon.replace(".form h1", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-2px"
});

Cufon.replace(".form h2", {
  //fontStyle : "italic"
    fontFamily : "GillSansLight"
});

Cufon.replace(".form h3", {
  fontFamily : "GillSans",
  fontWeight : "bold",
  letterSpacing : "-1px"
});

function closePopup() {
    $("iframe").trigger("close");
}

function updatePromo(promo, positions) {
    positions = positions.split(" ");
    positions[0] = positions[0].split(",");
    positions[1] = positions[1].split(",");
    
    promo.find("h2").css({
        "left" : positions[0][0] + "px",
        "top" : positions[0][1] + "px"
    });
    
    promo.find("p").css({
        "left" : positions[1][0] + "px",
        "top" : positions[1][1] + "px"
    });
}

$(document).ready(function() {
     // Handle promo mouse over
    
    $(".promo").each(function(index, promo) {
        promo = $(promo);
        updatePromo(promo, promo.attr("data-mouseout"));
    });
    
    $(".promo").hover(function(e) {
        var promo = $(e.currentTarget);

        if (promo.attr("data-mouseover") != "") {
            updatePromo(promo, promo.attr("data-mouseover"));
            promo.addClass("mouse_over");
        }
        
        Cufon.refresh();
    }, function(e) {
        var promo = $(e.currentTarget);
        
        if (promo.attr("data-mouseover") != "") {
            updatePromo(promo, promo.attr("data-mouseout"));
            promo.removeClass("mouse_over");
        }
        //promo.removeClass(promo.attr("data-mouseover"));
        //promo.addClass(promo.attr("data-mouseout"));
        
        Cufon.refresh();
    });
    
    // Catch form clicks
    
    $("a[href*=FormTemplate.aspx],a[href*=login]").click(function(e) {
        var link = $(e.currentTarget);
        var href = link.attr("href");
        var css = link.attr("class");
        
        if (css == "") {
            css = "popup_small";
        }
        
        var iframe = $("<iframe frameborder='0' class='" + css + "' src='" + href + "'></iframe>");
        
        $("body").append(iframe);
        
        iframe.lightbox_me({
            centered : true,
            destroyOnClose : true
        });
        
        return false;
    });
    
    // Catch Vimeo clicks
    
    $("a[href*='www.vimeo.com']").click(function(e) {
        var link = $(e.currentTarget);
        
        var href = link.attr("href");
        $.url.setUrl(href);
        
        var id = $.url.segment(0);
        var width = $.url.param("width");
        var height = $.url.param("height");
        var popup = $.url.param("popup");
        
        if (popup == null) {
            var iframe = $("<iframe frameborder='0' src='http://player.vimeo.com/video/" + id +"' style='width:" + width + "px;height:" + height + "px;'></iframe>");
            
            $("body").append(iframe);
            
            iframe.lightbox_me({
                centered : true,
                destroyOnClose : true,
                onClose : function() {
                    $(".slideshow .slides").cycle("resume");
                }
            });
        } else {
            window.open("/UI/Static/VimeoPopup.aspx?id=" + id + "&width=" + width + "&height=" + height, "vimeoPopup", "width=" + width + ",height=" + height + ",location=0,status=0,menubar=0,scrollbars=0,toolbar=0");
        }
        
        // Pause slideshow
        
        $(".slideshow .slides").cycle("pause");
        
        return false;
    });
    
    // Catch FLV clicks
    
    $("a[href*='.flv'],a[href*='.mp4']").click(function(e) {
        var href = $(this).attr("href");
        
        $.url.setUrl(href);
        
        var popupHeight = $.url.param("height") != null ? parseInt($.url.param("height")) : 495;
        var popupWidth = $.url.param("width") != null ? parseInt($.url.param("width")) : 880;
        
        var body = $("body");
        body.append("<div id='player' style=\"width: " + popupWidth + "px; height: " + popupHeight + "px;\"></div>");

        var player = $("#player");

        player.flash({
            src : "/UI/Flash/Player.swf",
            width : popupWidth,
            height : popupHeight,
            allowFullScreen : true,
            flashvars : {
                source : $.url.attr("path"),
                onClose : "videoOnClose"
            }
        });

        player.lightbox_me({
            centered : true,
            destroyOnClose : true
        });
        
        return false;
    });
    
    // Catch Facebook clicks
    
    $("a[href*='www.facebook.com']").click(function(e) {
        window.open($(e.currentTarget).attr("href"));
        
        return false;
    });
    
    $("a.close_link").click(function() {
        top.closePopup();
        
        return false;
    });
});
