//$(function(){

var autorotate;

$("<span>|</span>").insertBefore($("#meta ul li a"));

//submit the search field when the enter key has been pressed.
$('#search').keydown(function (event) {
    if (event.keyCode == '13') {
        $(this).parent("form").submit();
    }
});

$("#home-left-column, #home-middle-column, #home-right-column").equalHeight();
$("#content-left-column, #content-middle-column").equalHeight();

var bodyclass = $("body").attr("class");
var selectedclass = "";
switch (bodyclass) {
    case "about":
        selectedclass = "about";
        break;
    case "contact":
        selectedclass = "contact";
        break;
    case "services":
        selectedclass = "services";
        break;
    case "knowledge":
        selectedclass = "knowledge";
        break;
    case "online":
        selectedclass = "online";
        break;
    case "news":
        selectedclass = "news";
        break;
}

if (selectedclass.length > 0)
    $("#primary ul").find("." + selectedclass).addClass("selected");

var background = $(".story:eq(0)").show().data("background");
$("#featured-story").css("background-image", "url(" + background + ")");
$("#story-left li a:eq(0)").addClass("selected");

function showStory(index, fade) {
    $(".story").hide();
    $("#story-left li a").removeClass("selected")
        .eq(index).addClass('selected');
    background = $(".story:eq(" + index + ")").show().data("background");
    $("#featured-story").css("background-image", "url(" + background + ")");
    if (fade) {
        $("#featured-story").hide().fadeIn('slow');
    }
}

$("#story-left a").mouseover(function () {
    clearInterval(autorotate);
    var index = $(this).parent().index();
    showStory(index, false);
}).click(function () { return false; });

if ($('#story-left li').length > 1) {
    autorotate = setInterval(function () {
        var current = $('#story-left li:has(a.selected)').index(),
              next = (current + 1 == $('#story-left li').length) ? 0 : current + 1;

        showStory(next, true);
    }, 15000);
}

$("#breadcrumb li a, .right-links ul:not(.social) a, .middle-container a, .story a").prepend("<span class='separator'>&#187;</span>");


//if the placeholder attribute is not supported in an older browser 
//load a polyfill using yepnope & modernizr to handle
//polyfill: defaultBlur jQuery Plugin
yepnope({
    test: Modernizr.input.placeholder,
		nope: [applicationPath+'js/plugins/jquery.defaultBlur-1.1.min.js'],
    callback: function (url, result, key) {
        if (!result) {
            $("#search").defaultBlur({ defaultText: "Search" });
        }
    }
});

yepnope({
		load: applicationPath+'js/mylibs/menu.js',
    complete: function () {
        $("#primary > ul > li").hover(function () {
            var index = $(this).index() + 1;
            ShowSubMenu(index);
        }, function () {
            HideSubMenu();
        });
    }
});
//});
