﻿$(document).ready(function () {

    /* SCRIPT PER IL MENU */
    $("#topnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag

    var currentLocation = getLeaf(document.location.href);
    //if (currentLocation == "")
    //    currentLocation = "default.aspx";
    $("#topnav li").each(function () { //For each list item...
        var linkText = $(this).find("a").html(); //Find the text inside of the a tag
        $(this).find("span").show().html(linkText); //Add the text in the span tag
        var pageurl = $(this).find("a").attr("href");
        pageurl = pageurl.substring(pageurl.lastIndexOf("/") + 1);
        if (pageurl.toLowerCase() == currentLocation.toLowerCase())
            $(this).find("span").addClass("activemenuitem");
    });

    $("#topnav li div.subnav a").each(function () { //For each list item...
        var pageurl = $(this).attr("href");
        pageurl = pageurl.substring(pageurl.lastIndexOf("/") + 1);
        if (pageurl.toLowerCase() == currentLocation.toLowerCase()) {
            $(this).addClass("activemenuitem");
            var firstlevelmenu = $(this).parent().parent();
            $(firstlevelmenu).find("span").addClass("activemenuitem");
        }
    });

    $("#topnav li").hover(function () {	//On hover...
        $(this).find("span").stop().animate({
            marginTop: "-40" //Find the span tag and move it up 40 pixels
        }, 250);
        $(this).find("div.subnav").slideDown("fast"); //Show the subnav
    }, function () { //On hover out...
        $(this).find("span").stop().animate({
            marginTop: '0'
        }, 250);
        $(this).find("div.subnav").hide();
    });

    checkBrowser();

});

/* FLIP BANNER NEWS AL VOLO */
//flipFunct = window.setInterval("FlipBanner(true)", 60000);
var flipFunct;

$(window).bind('blur', function () {
    window.clearInterval(flipFunct);
    ResetBanner();
});

$(window).bind('focus', function () {
    flipFunct = window.setInterval("FlipBanner(true)", 60000);
});

function getLeaf(url) {
    return url.substring(url.lastIndexOf("/") + 1);
}

function checkBrowser() {
    // se il browser è MS Internet Explorer e se la versione e <= 8

    if(($.browser.msie) && (!document.documentMode))
        $(".msgbrowser").css("visibility", "visible");

    // verifica se è impostata la modalita compatibilità
}


