jQuery.fn.exists = function(){return jQuery(this).length>0;}

var cookieList = function(cookieName) {

var cookie = $.cookie(cookieName);
var items = cookie ? cookie.split(/,/) : new Array();

return {
    "add": function(val) {
        items.push(val);
        $.cookie(cookieName, items.join(','), { path: '/' });
    },
    "clear": function() {
        items = null;
        $.cookie(cookieName, null, { path: '/' });
    },
    "del": function(val) {

        item = $.inArray(val, items);
        items.splice(item, 1);

       $.cookie(cookieName, items.join(','), { path: '/' });
       
    },
    "inarray": function(val) {

        alert($.inArray(val, items));
       
    },
    "items": function() {
        return items;
    }
  }
}

var active_menus = new cookieList("active-sub-menus");
//active_menus.clear();
$(document).ready(function() {
 $(".sub-menu").hide();
 var items = active_menus.items();
 for(var i in items) {
    $("#menu .item").eq(items[i]).next().show();
    $("#menu .item").eq(items[i]).find("span").removeClass("item-arrow-right").addClass("item-arrow-down active")
 }

  $("#menu .item").each(function(i) {

      if ($(this).next().exists()) {
        $(this).click(function() {
          if($(this).find(".active").exists()) {
             active_menus.del(i);
            $(this).find("span").addClass("item-arrow-right").removeClass("item-arrow-down active");
            $(this).next().slideUp();

          } else {
            active_menus.add(i);  
            $(this).find("span").removeClass("item-arrow-right").addClass("item-arrow-down active");
            $(this).next().slideDown();
            
          }
          return false;
        });
      }

  });
  
/* Slider */

  $('#s3slider').s3Slider({
      timeOut: 4000 
   });
  
});
