$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	var totWidth=0;
	var positions = new Array();

	$('#slides .slide').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		positions[i] = totWidth;
		totWidth += $(this).width() + 8;

		/* The positions array contains each slide's commulutative offset from the left part of the container */

		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});

	/* Change the container div's width to the exact width of all the slides combined */
	$('#slides').width(totWidth);

	$('#menu ul li a').click(function(e, autoClick){
		if(autoClick != true) clearInterval(itvl);
		
		/* On a thumbnail click */
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');

		var pos = $(this).parent().prevAll('.menuItem').length;

		$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},350);
		/* Start the sliding animation */

		e.preventDefault();
		/* Prevent the default action of the link */
	});

	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
	/* Enabling auto-advance. */
	var current=1;
	function autoAdvance(){
		if(current==-1) return false;

	    $('#menu ul li a').eq(current%$('#menu ul li a').length).trigger('click', [true]);   // [true] will be passed as the keepScroll parameter of the click function on line 24
	    current++;
	}

	// The number of seconds that the slider will auto-advance in:
    var changeEvery = 6;
    // do not start automatic sliding for beers pages
    if ( ($(this).context.URL).indexOf("beers.php") < 0 ) {
	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
    }
});

/*function HideRolloverImage() {
   if (document.originalImages != null)
      for(var i=0;i < (document.originalImages.length-1);i+=2)
         document.originalImages[i].src = document.originalImages[i+1];
}

function ShowRolloverImage() {
   var i, j=0;
   var objStrobj;
   var imgList = new Array;
   var oldList = document.originalImages;
   for (i=0; i < (ShowRolloverImage.arguments.length-2); i+=3) {
      objStr = ShowRolloverImage.arguments[i+1];
      if ((objStr.indexOf('document.layers[') == 0 && document.layers == null) || (objStr.indexOf('document.all[') == 0 && document.all == null))
         objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
      obj = eval(objStr);
      if (obj != null) {
         imgList[j++] = obj;
         imgList[j++] = (oldList == null || oldList[j-1] != obj) ? obj.src : oldList[j];
         obj.src = ShowRolloverImage.arguments[i+2];
      }
   }
   document.originalImages = imgList;
   }*/

var menupages = new Array("/menupage1.php", "/menupage2.php", "/menupage3.php", "/menupage4.php", "/menupage5.php");
var currentMenuPage = 0;

function menuNext() {
    currentMenuPage++;
    if (currentMenuPage >= menupages.length)
	currentMenuPage = 0;

    //alert(currentMenuPage);
    document.getElementById('minset').setAttribute('src', menupages[currentMenuPage]);
}

function menuPrev() {
    currentMenuPage--;
    if (currentMenuPage < 0)
	currentMenuPage = menupages.length - 1;

    //alert(currentMenuPage);
    document.getElementById('minset').setAttribute('src', menupages[currentMenuPage]);
}

function toggleNewsletter(){
    $('body').toggleClass('overlaid');
    // IE doesn't seem to use the 'overlaid' class, so we use the display CSS property to get it out of the way
    $('div.overlay').toggle();
//    document.body.className = document.body.className.indexOf('overlaid') != -1 ? '' : 'overlaid';
}

