function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}


$(document).ready(function() {

	$('#slideshow').after('<ul id="nav">').cycle({ 
		fx: 'scrollVert',
		timeout: 0, 
		easing: 'easeOutExpo',
		pager:  '#nav', 
		// callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>'; 
		} 
	});
	
	var contentArray = new Array();
	contentArray["home"] = 0;
	contentArray["info"] = 500;
	contentArray["salads"] = 1000;
	contentArray["lunch"] = 1500;
	contentArray["lunch2"] = 2000;
	contentArray["dinner"] = 2500;
	contentArray["dinner2"] = 3000;
	contentArray["sweet"] = 3500; 
	contentArray["sweet2"] = 4000; 
	contentArray["wines"] = 4500; 
	contentArray["beverages"] = 5000;
	contentArray["specials"] = 5500;
	contentArray["seasonal"] = 6000;
	contentArray["hours"] = 6500;
	contentArray["gallery"] =7000;
	contentArray["contact"] = 7500;
	
	// Cleanup if sent noJS link e.g. '/#salad'
	if (window.location.hash.indexOf('/') == '-1') {
		var n = window.location.hash;
		window.location.hash = '#home';
		window.location.hash = n.replace('#','#/');
		moveTo(n.replace('#',''));
	}
	
	// Go to link
	moveTo(window.location.hash.replace('#/',''));
	
	// Click events for nav
	$('.home').click(function() {
		$('.active').removeClass('active');
		$('#contents').animate({left:0});
		window.location.hash = '#/home';
		return false;
	});
	$('#main_menu a').click(function() {
		if ($(this).attr('target') === '_blank') {
			return true; // External links
		} else {
			$('.active').removeClass('active');
			$(this).addClass('active');
			var p = $(this).attr('href').replace('#','');
			moveTo(p);
			window.location.hash = '#/' + p;
			return false;
		}
	});
	
	function moveTo(id) {
		var navTo = '-' + contentArray[id] + 'px';
		$('#contents').stop().animate({left:navTo}, 800, 'easeOutExpo');
	}
});

function maillink(addy,subject,cssclass) {
 //this function adds feature that if first character of email address is
 //a minus-sign (-) then the word "email" will be used for the link
 //rather than the actual address, and if the first character is a plus
 //sign (+) then the link will do a popup box to reveal the address rather
 //than be an email link.
 linkclass='link2';
 disaddy=1;
 if (addy.substring(0,1) == '-') {
   addy=addy.substring(1,addy.length);
   disaddy=0;
 } else {
     if (addy.substring(0,1) == '+') {
     addy=addy.substring(1,addy.length);
     disaddy=2;
   }
 }
 if (typeof(cssclass) != 'undefined' && cssclass != '') {linkclass=cssclass;}
 if (disaddy == 1 || disaddy == 0) {
   document.write('<a href="mailto:' + addy + '@nookcreperie.ca');
   if (typeof(subject) != 'undefined' && subject !='') {document.write('?subject=' + subject);}
   if (disaddy == 1) {
     document.write('" class="' + linkclass + '">' + addy + '@nookcreperie.ca</a>');
   } else {
     document.write('" class="' + linkclass + '">Email</a>');
   }
 } else {
   if (disaddy == 2) {
     document.write('<a href="javascript:mailalert(\'' + addy);
     //document.write('<a href="javascript:alert(\'' + addy + '@nookcreperie.ca');
     //document.write('<a href="javascript:prompt(\'Email Address:\',\'' + addy + '@nookcreperie.ca');
     document.write('\');" class="' + linkclass + '">Email</a>');
     //document.write('<input type="button" onClick="prompt(\'Copy the email address. Click OK to close.\',\'' + addy + '@nookcreperie.ca\')"');
     //document.write(' value="Email">');

   }
 }
}

