 jQuery(document).ready(function($) {			

	$('#nav li').each(function(index) {
		$(this).bind('click', function(event) {
			
			// if this element isnt within a .shown ul, fadeout the old element and continue
			
			if($('ul.shown > li',$(this).parent()).size() > 0) {
				$('ul.shown > li',$(this).parent()).fadeOut();	
			}
			
			//also remove the active class
			$('li > a',$(this).parent()).removeClass('active');
			
			// sets class for current clicked element
			$('> a', $(this)).addClass('active');
			
			// lets set a marginleft for the next ul element
			$('> ul', $(this)).addClass('shown').css({ marginLeft: '0px'});
			
			// slide out the next ul and its li's
			$('> ul > li', $(this)).show('slide');
			
			if($(this).children('ul').hasClass('shown') == true){
				$(this).siblings('li').children('ul').fadeOut();
			}
			
			$('> ul', $(this)).show('slide');
			
			var $page = $('a', $(this)).attr('href');
			document.location = $page;
			
			return false
			
		});
	});
	
	ImageRotator('top1').OnReady = function(){
	
		ImageRotator('top1').Start();
		
		ImageRotator('top1').OnImageChange = function(){
			var index = ImageRotator('top1').GetCurrentIndex();
			if(index == 0){
				ImageRotator('top1').Pause();
				ImageRotator('top2').Start();
			}
		}
		
		ImageRotator('top2').OnImageChange = function(){
			var index = ImageRotator('top2').GetCurrentIndex();
			if(index == 0){
				ImageRotator('top2').Pause();
				ImageRotator('top4').Start();
			}
		}
		
		ImageRotator('top3').OnImageChange = function(){
			var index = ImageRotator('top3').GetCurrentIndex();
			if(index == 0){
				ImageRotator('top3').Pause();
				ImageRotator('top1').Start();
			}
		}
		
		ImageRotator('top4').OnImageChange = function(){
			var index = ImageRotator('top4').GetCurrentIndex();
			if(index == 0){
				ImageRotator('top4').Pause();
				ImageRotator('top3').Start();
			}
		}
	}
	
});

$(function () {
	$('marquee').marquee().mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	});
});

function OpenMenu(pageid){
	$('#page' + pageid).parent().show();
	$('#page' + pageid).addClass('active');
	$('#page' + pageid).parent().parent().addClass('shown');
	$('#page' + pageid).parent().parent().parent().show();
	$('#page' + pageid).parent().parent().parent().siblings().show();
	$('#page' + pageid).parent().siblings().show();
}

