$(document).ready(function() {
	/* rotate images in page */
	var rotateCount = 0;
	var len = ($('#banner img').length) - 1;
	var delay = 5000;
	var num = 0;
	
	function rotateBanner(hack, num, stopPlaying) {
		var curr = $('#banner img:eq('+rotateCount+')');
		
		$(curr).fadeOut('slow',function() {
			$(this).fadeOut('slow');
			if ((rotateCount+1) > len) {
				rotateCount = 0;
			}else{
				rotateCount++;
			}			
			if (!num) {
				$('#banner img:eq('+rotateCount+')').fadeIn('slow');
			}else{
				$('#banner img:eq('+num+')').fadeIn('slow');
			}
			if (!stopPlaying) {
				timer = setTimeout(rotateBanner, delay);
			}
		});		
	}
	
	function rewindBanner(hack, num) {
		var curr = $('#banner img:eq('+rotateCount+')');
		
		$(curr).fadeOut('slow',function() {
			$(this).fadeOut('slow');
			$('#banner img:eq('+num+')').fadeIn('slow');
			
			if ((rotateCount-1) < 0) {
				rotateCount = len;
			}else{
				rotateCount--;
			}
		});
	}
	
	if (len > 1) {
		timer = setTimeout(rotateBanner, delay);
	}
	
	/* nav rollovers */
	$('#nav li ul').hover( 
		function () { 
			/* on hover stop the images rotating so they don't interfere with the menu drop down */
			clearTimeout(timer);
    	},  
    	function () { 
			/* on rollout start rotating again */
      		timer = setTimeout(rotateBanner, delay);
    	}
	);
	
	/* menus expander */
	$('.btn').toggle(function() {
		$(this).parent().next().show('fast');
		$(this).find('a').text('- hide menu');
		return false;
	}, function() {
		$(this).parent().next().hide('fast');
		$(this).find('a').text('+ show menu');
	})
	
	
	/* slideshow controls */
	$('#pause').click(function() {
		clearTimeout(timer);
		return false;
	});
	$('#play').click(function() {
		rotateBanner();
		return false;
	});
	$('#rewind').click(function() {
		clearTimeout(timer);
		if ((rotateCount - 1) < 0) {
			num = len;
		}else{
			num = rotateCount - 1;
		}
		rewindBanner(0,num);
		return false;
	});
	$('#forward').click(function() {
		clearTimeout(timer);
		if ((rotateCount + 1) > len) {
			num = 0;
			rotateBanner(0,num,true);
		}else{
			rotateBanner();
		}		
		
		return false;
	});
	
	/* venues table zebra striping */
	$('#tbl_venues tr:even td').css('background','#333333');
	
	
});


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
