﻿/* Site core script
 * ---------------------------------------------------
 * Container core script to enhance the page 
 */

// On DOM ready
$(document).ready(function () {

    // Activate Cufon
    Cufon.replace('nav,h2,p,address');
    Cufon.replace('a,#divide,h2', { fontFamily: 'GothamBold' });
    Cufon.replace('nav,h2,p,address,li');
    Cufon.replace('a,.divide,h2,h3', { fontFamily: 'GothamBold' });
    Cufon.replace('#news a', { hover: true });
    // After Cufon has finished
    Cufon.CSS.ready(function () {
        // Centre container in the window
        $('#container').centreInWindow();
        // Show
        $('#container').fadeIn(1000);
    });

    // Get external links
    $('a[rel="external-link"]').click(function (event) {
        // Get the URL
        var href = $(this).attr('href');
        // Open a new window
        window.open(href);
        // Cancel default
        event.preventDefault();
    });

    // Initialise links
    initialiseLinks();

    // Load the twitter feed
    /*$("#news").tweet({
        query: "#gp2 from:MyCaterhamGP2",
        join_text: "auto",
        avatar_size: 32,
        count: 5,
        template: '<li><a href="{first_link}" target="_blank">{tweet_time_basic} <span class="divide">//</span> {tweet_text_simple}</a></li>',
        auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "Loading...",
        callback: function () {
            // Replace
            Cufon.replace('#news li');
            // Centre container in the window
            $('#container').centreInWindow();
            // Initialise links
            initialiseLinks();
        }
    });*/
});

// Initialises the links
function initialiseLinks() {
    // Get all links
    $('a').each(function (index, link) {
        // Hover
        $(link).hover(
            function () {
                // Fade out
                $(this).fadeTo(50, 0.6);
            },
            function () {
                // Fade in
                $(this).fadeTo(50, 1);
            }
        );
    });
}
