 /* Copyright (C) 2009 Lorenzo Sfarra (lorenzosfarra@ubuntu.com)
  *
  * Website: http://twilight.netsons.org
  * Blog: http://lorenzosfarra.blogspot.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */

/* The currently selected category */
curCategory = "";
/* The URL realated to the current category */
url = "http://www.ubuntu-it.org/Ottenere_Ubuntu.shtml";
/* category -> url map */
urlsMap = {
  "support": "http://www.ubuntu-it.org/Supporto.shtml",
  "contribuire": "http://www.ubuntu-it.org/contribuire.shtml",
  "newsletter": "http://www.ubuntu-it.org/contenuti/newsletter-italiana-2.shtml",
  "fcm": "http://www.ubuntu-it.org/contenuti/fcm.shtml",
  "media": "http://www.ubuntu-it.org/contenuti/media.shtml",
  "contatti": "http://www.ubuntu-it.org/contatti.shtml"
}
/* Tracking activated items, if the user highlights more than 1 menu item
 * too fast. */
activatedItems = Array();

function changeActiveCategory(liId) {
  /* Change the active category in the banner.

  @param liId the ID of the selected 'li' element
  */
  /* Change 'li' classes for the old selected category and the new one */
  newCategory = liId.substring(2);
  if (curCategory != "") {
    $("#li" + curCategory).removeClass("lihover");
    $("#li" + curCategory).addClass("linormal");
  } else {
    $("#homepagebuttons").fadeOut("fast");
  }
  $("#" + liId).removeClass("linormal");
  $("#" + liId).addClass("lihover");
  /* Change the main image for the new category*/
  $("#bannermainbg").fadeOut("slow", function(data) {
    if (curCategory != "") {
      $("#bannermainbg").removeClass(curCategory + "main");
    }
    /* Update info about the new category */
    curCategory = newCategory;
    url = urlsMap[curCategory];
    $("#bannermainbg").addClass(curCategory + "main");
    /* Workaround for IE6: CSS class doesn't work properly, so we set
     * the background manually. */
    if ($.browser.msie) {
      /* Check that is IE with version < 7 */
      if ($.browser.version < 7.0) {
        path = "url(/uploads/file/banner2009/images/" + curCategory + ".png)";
        $("#bannermainbg").css("background-image", path);
      }
    }
    $("#bannermainbg").fadeIn("slow");
  });

}


$(document).ready(function() {
  /* Change the link href, because the user has JS enabled */
  $("#bannerlinkslist li a").attr("href", "#");
  $("#bannerlinkslist li").hover(function() {
    /* Give info about the current 'li' id to the function */
    activatedItems.push($(this).attr("id"));
    changeActiveCategory($(this).attr("id"));
  },
  function() {
    /* If it's not the currently selected item, 
     * remove the correspective class */
    for (iter = 0; iter < activatedItems.length; iter += 1) { 
      if (activatedItems[iter] != ("li" + curCategory)) {  
        $("#" + activatedItems[iter]).removeClass("lihover");
        $("#" + activatedItems[iter]).addClass("linormal");
        activatedItems.splice(iter);
      }
    }
  });
  /* Manage the onclick event on the main banner content */
  $("#bannermain").click(function() {
    /* Base: we have 2 buttons to "Discover" and "Download",
       so we ignore this event. */
    if (curCategory == "") {
      return;
    } else {
      window.location = url;
    }
  });

  /* Now we set the onclick event for the 2 buttons in the main
   * image */
  $("#discoverit").click(function() {
    window.location = "http://www.ubuntu-it.org/Caratteristiche.shtml";
  });
  $("#downloadit").click(function() {
    window.location = "http://www.ubuntu-it.org/Ottenere_Ubuntu.shtml";
  });
});

//vim: ai ts=2 sw=2 et sts=2
