var api;
var autoScroll;
var size = 5;
var currentLocation = window.location.toString();  // find out what page we are on
var hostName = 'http://'+ window.location.hostname; // find our current domain name
var uriString = currentLocation.replace(hostName, '');  // get our segments minus our domain name
var uriSegments = uriString.split('/'); //create our segment array
uriSegments.shift();
if (uriSegments[0]==='www.alco') uriSegments.shift();

/* 
 * Google Analytics Tracking
 */
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23852583-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

$(function() 
{
	$('ul.sf-menu').superfish();
	initMenu();
	$('#lightbox a').lightBox();
	$('a[rel=lightbox]').lightBox();
	
	/* 
	 * initialize scroller
	 */
	if ($("#scroller").size()) {
		$(".scrollable").scrollable({ circular:true });
		api = $(".scrollable").data("scrollable");
		if (api.getSize() > 1) {
			autoScroll = setInterval(doScroll, 4000);
		} else {
			$("#scroller .browse").css('visibility','hidden');
		}
		
		// setup mouseover actions for scroller
		$("#scroller").mouseenter(function() {
			clearInterval(autoScroll);
		}).mouseleave(function() {
			if (api.getSize() > 1) autoScroll = setInterval(doScroll, 4000);
		});
	}
});

function doScroll() 
{
	api.move(1);
}

function initMenu() 
{
	$('#nav ul').hide();
	//<? if ($Url->part(1)!='') : ?>
	//$('ul #submenu-<?=$Url->part(1)?>').show();
	//<? else : ?>
	if (uriSegments[0] != '') {
		$('ul #submenu-'+uriSegments[0]).show();
	} else {
		$('#nav ul:first').show();
	}
	//<? endif ?>
	
	$('#nav li a').click(
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#nav ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	)
}
