// JavaScript Document
var speed = 30;
var pic, numImgs, arrLeft, i, totalWidth, n, myInterval;
jQuery(document).ready(function($) {
		pic = $("#Slider").children("img");
		numImgs = pic.length;
		arrLeft = new Array(numImgs);
	
		for (i=0;i<numImgs;i++){
	
			totalWidth=0;
			for(n=0;n<i;n++){
				totalWidth += $(pic[n]).width()+10;
			}
	
			arrLeft[i] = totalWidth;
			$(pic[i]).css("left",totalWidth);
		}
	
		myInterval = setInterval("flexiScroll()",speed);
		$(pic).show();
		
		initMenus();
		function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		var cookie = $.cookie(this.id);
		if(cookie === null || String(cookie).length < 1) {
			$('#' + this.id + '.expandfirst ul:first').show();
		}
		else {			
			$('#' + this.id + ' .' + cookie).next().show();
		}
	});
	$('ul.menu li a').click(
		function() {

			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				if((String(parent).length > 0) && (String(this.className).length > 0)) {
					if($(this).next().is(':visible')) {
						$.cookie(parent, null);
					}
					else {
						$.cookie(parent, this.className);
					}
					$(this).next().slideToggle('normal');
				}				
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				if((String(parent).length > 0) && (String(this.className).length > 0)) {
					$.cookie(parent, this.className);
				}
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
});
	
function flexiScroll(){
	
		for (i=0;i<numImgs;i++){
			arrLeft[i] -= 1;		
	
			if (arrLeft[i] == -(jQuery(pic[i]).width())){
				totalWidth = 0;
				for (n=0;n<numImgs;n++){
					if (n!=i){
						totalWidth += jQuery(pic[n]).width()+10;
					}
				}
				arrLeft[i] =  totalWidth+10;
			}
			jQuery(pic[i]).css("left",arrLeft[i]);
		}
}

