jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

if($.cookie("css")) {
  var style = $.cookie("css");
  $('#style').attr('href', 'styles/'+style+'/style.css');
  $('#color').attr('href', 'styles/'+style+'/color.css');
  setTimeout(function() { Cufon.refresh('h1, h2, h3, #menu ul:first>li>a') }, 3000 );
}

$(document).ready(function(){
    
  $('form a.submit').click(function(evt){
    $(this).parents('form').get(0).submit();
    evt.preventDefault();
  });

  Cufon.replace('h1, h2, h3, .d', {
    fontFamily: 'Futura Bk BT',
    hover: 'true'
  });
  
  Cufon.replace('.m', {
    fontFamily: 'Futura Hv BT',
    hover: 'false'
  });

	$("#menu li").hover(function(){
    $(this).addClass("hover");

    $('ul:first',this).each(function() {
      if ( $(this).parents("ul ul").length==0 ) {
        var center = ( $(this).parent('li').width() - $(this).width() ) / 2
        $(this).css({ left: center });
      }

      $(this).css({visibility: 'visible' });
    });
    
	}, function(){
    $(this).removeClass("hover");
    $('ul:first',this).css('visibility', 'hidden');
	});
	
  $('.slider-gallery').customSlider({ width: 136, distance: 4 });


  $("#menu ul li ul li ul").parent("li").addClass("submenu");
  
  $("#menu ul li ul li a").click(function(event){ 
    var style = $(this).attr('href').match(/style(.)/)[1];
    $('#style').attr('href', 'styles/'+style+'/style.css');
    $('#color').attr('href', 'styles/'+style+'/color.css');

    $.cookie("css",style, {expires: 365, path: '/'});

    setTimeout(function() { Cufon.refresh('h1, h2, h3, #menu ul:first>li>a') }, 3000 );
    event.preventDefault();
  });
  
});
