$(document).ready(function () {
    //----------------------------
    // DROP DOWN NAVIGATION
    //----------------------------
    $("#main_nav ul li").hover(
		function () {
		    $(this).children('ul').fadeIn(100);
		    $(this).find('a:first').addClass("active");
		},

		function () {
		    $(this).children("ul").fadeOut(50);
		    $(this).find('a:first').removeClass("active");
		}
	);

    $("#main_nav ul li ul li ul").parent()
	                             .find("a:first")
								 .append("<span>&raquo</span>");

    //----------------------------
    // SPONSOR SLIDESHOW
    //----------------------------
    $("#sponsors .slide_item").crossFade({
        output: '.slide_item',
        fadeSpeed: 'fast',
        startTab: 0,
        interval: 5000,
        hoverPause: true
    });

    //----------------------------
    // TWITTER FEED
    //----------------------------
    $(".twitter").getTwitter({
        userName: "usn_uk",
        numTweets: 2,
        loaderText: "Loading latest tweets...",
        slideIn: true,
        showHeading: false,
        headingText: "Latest Tweets",
        showProfileLink: false,
        showTimestamp: true
    });

    //----------------------------
    // PRODUCT INFO TABS
    //----------------------------
    $('.info_tab').hide();
    $('.info_tab:first').show();
    $('#product_tabs a:first').addClass('current');

    $('#product_tabs a').click(function () {
        var target = $(this).attr('href');
        var current = $('#product_tabs ul li a.current').attr('href');

        $('#info_container ' + current).hide();
        $('#info_container ' + target).show();

        $('#product_tabs a').removeClass('current');
        $(this).addClass('current');

        return false;
    });

    //----------------------------
    // MODAL BOXES
    //----------------------------
    $('a.modal').click(function () {
        $('.modal_wrapper').fadeIn('fast');
        return false;
    });

    $('a.close_modal').click(function () {
        $('.modal_wrapper').hide();
        return false;
    });

    //----------------------------
    // GOALS FEATURE
    //----------------------------
    $("a.swap").crossFade({
        output: '.section',
        fadeSpeed: 'fast',
        startTab: 0,
        interval: 5000,
        hoverPause: true
    });

    //----------------------------
    // HEROES ACCORDION
    //----------------------------

    $("h3.usnhero:first").addClass("active");
    $(".hero_list:first").show();

    $("h3.usnhero").click(function () {
        var checkElement = $(this).next();

        if ((checkElement.is("div")) && (checkElement.is(":visible"))) {
            return false;
        }

        if ((checkElement.is("div")) && (!checkElement.is(":visible"))) {
            $(".hero_list:visible").slideUp("normal");
            checkElement.slideDown("normal");

            $("h3.usnhero").removeClass("active");
            $(this).addClass("active");

            return false;
        }
    });

    $('a[rel=external]').attr('target', '_blank');
});

function modalPopupOpen(popupId) {
    $("#" + popupId).show();
}

function modalPopupClose(popupId) {
    $("#" + popupId).hide();
}
