document.observe('dom:loaded',DomLoaded);

Event.observe(window, 'load', WindowLoaded);

var FlashIsLoaded = false;

var Rotators = [
	{id: 'Paddling', type: 'img', img: '/shared/images/frontpage/paddling.jpg', current: true},
	{id: 'Camping', type: 'img', img: '/shared/images/frontpage/camping.jpg', current: false},
	{id: 'Diving', type: 'img', img: '/shared/images/frontpage/diving.jpg', current:false},
	{id: 'Fishing', type: 'img', img: '/shared/images/frontpage/boating.jpg', current:false},
	{id: 'FLASH', type: 'flash', href:'/shared/flash/default_intro.swf', current:false}
]

function WindowLoaded(){
	LoadElement(1);
}

function LoadElement(Index){
	if(Rotators[Index].type == 'img')
		Element2 = new Element('img',{id:Rotators[Index].id, src:Rotators[Index].img, style:'display:none;'});
	else{
		Element2 = new Element('div',{id:Rotators[Index].id, style:'display:none;'});
	}
	$('Images').appendChild(Element2);
	
	
	if(Index < Rotators.size() - 1)
		Element2.observe('load',function(){
			LoadElement(Index+1);
		});
}

function DomLoaded(){
	
	pe = new PeriodicalExecuter(Animate,5);
	
	$$('#Images ul').each(function(item){
		item.setOpacity(0.6);
	});
	
	$('PaddlingMenu').observe('mouseover', function(){
		ClearSubMenu();
		$('PaddlingSub').style.display = 'block';
		this.style.background = 'url(/shared/images/frontpage/header_pointer.gif) no-repeat bottom center';
	});
	
	$('FishingMenu').observe('mouseover', function(){
		ClearSubMenu();
		$('FishingSub').style.display = 'block';
		this.style.background = 'url(/shared/images/frontpage/header_pointer.gif) no-repeat bottom center';
	});
	
	$('DivingMenu').observe('mouseover', function(){
		ClearSubMenu();
		$('DivingSub').style.display = 'block';
		this.style.background = 'url(/shared/images/frontpage/header_pointer.gif) no-repeat bottom center';
	});
	
	$('CampingMenu').observe('mouseover', function(){
		ClearSubMenu();
		$('CampingSub').style.display = 'block';
		this.style.background = 'url(/shared/images/frontpage/header_pointer.gif) no-repeat bottom center';
	});
	
	
	$('AboutMenu').observe('mouseover', ClearSubMenu);
	$('ManagementMenu').observe('mouseover', ClearSubMenu);
	$('NewsMenu').observe('mouseover', ClearSubMenu);
	$('ContactMenu').observe('mouseover', ClearSubMenu);
	
	$$('#Images li a, #Ads a').each(function(item){
		item.observe('click', function(event){
			window.open(this.href);
			Event.stop(event);
		})
	})
	
	
}

function ClearSubMenu(){
	$$('#Images ul').each(function(item){
		item.style.display = 'none';
	});
	
	
	$$('#Header ul li').each(function(item){
		item.style.background = 'none';
	});

}

function Animate(){

	CurrentIndex = -1;

	Rotators.each(function(item, index){
		
		if(CurrentIndex > -1) return;	
		
		if(item.current == true) {
			CurrentIndex = index;
			item.current = false;
			
			if(Rotators.size() -1 == index)
				Rotators[0].current = true;
			else
				Rotators[index+1].current = true;
				
		}			
	});

	ToIndex = (Rotators.size() -1 == CurrentIndex) ? 0 : CurrentIndex + 1;

	if($(Rotators[ToIndex].type == 'img')){

		if($(Rotators[CurrentIndex].id).complete && $(Rotators[ToIndex].id).complete){
			$(Rotators[CurrentIndex].id).fade({duration:3.0});
			$(Rotators[ToIndex].id).appear({duration:3.0});
		}else{
			// If the image isn't loaded yet, reset and try again at the next interval
			Rotators.each(function(item){ item.current = false; });
			Rotators[CurrentIndex].current = true;
		}
		
	}else{
		
			
			
			swfobject.embedSWF('/shared/flash/default_intro.swf', 'FLASH', '960', '542', '8',null,null,{wmode: "opaque"});
			
		
	}
		
}


function FlashStart() {
	
	pe.stop();
		
	$('Ads').fade({duration:1.0});
	$(Rotators[3].id).fade({duration:1.0});
	$('FLASH').appear({duration:1.0});
}



function FlashComplete() {
	
		$('FLASH').fade({duration:3.0});
		$(Rotators[0].id).appear({duration:3.0});
		Rotators[1].current = true;
		$('Ads').appear({duration:3.0});
		new PeriodicalExecuter(Animate,5);
		Rotators.splice(4, 1);
}

