window.onload = function()
{
	// fix for goolge calendar
    $('calendar').hide();
	$('calendar').style.position = 'static';
    var pageNames = ['home',
                      'villas',
                      'amenities',
                      'rates',
                      'booking',
                      'calendar',
                      'location',
                      'gallery',
                      'faq',
                      'contact'
                     ];
    $A(pageNames).each(function(pageName){
        if($('nav_'+pageName)){ Event.observe('nav_'+pageName,'click', function(e){activatePage(pageName,e);}.bind(this)); }
    }.bind(this));
    activatePage = function (targetPage,e){
        if (e && Event.element(e).hasClassName('activeBtn'))
        {
            Event.stop(e);
        }
        else 
        {
            activePage = targetPage;
            location.hash='#' + targetPage;
            if($('nav_'+targetPage) && $('nav_'+targetPage).hasClassName('navButton'))
            {
                // Find the navButton that is active and make it inactive
                var activeBtn = $('navigation').getElementsByClassName('activeBtn');
                if(activeBtn.length)
                {
                    var btn = activeBtn[0];
                    $(btn).removeClassName('activeBtn');
                    $(btn).addClassName('navButton');
                    $(btn).style.color = '#000';
                }
                // Find the section that is visible and hide it
                var sections = $('content').getElementsByClassName('section');
                var section = $A(sections).find(function(section){ return section.visible()==true; });
                if (section) { $(section).hide(); }
                //change navButton
                //new Effect.Pulsate($(ele), {duration: 1, from: 0.3, pulses: 1});
                new Effect.BlindDown($(targetPage),{duration:2});
                
                $('nav_'+targetPage).style.color = '#FFF';
                $('nav_'+targetPage).removeClassName('navButton');
                $('nav_'+targetPage).addClassName('activeBtn');
            }
        }
    };
    // If trying to access a hash page
    if (location.hash)
    {
        var page = location.hash.substr('1');
        if (page.charAt(0) == 'q')
        {
            activatePage('faq');
        }
        else
        {
            activatePage(page);
        }
    }
    Event.observe('container','click', function(e) {
		var ele = Event.element(e);
		if($(ele).hasClassName('accom'))
		{
			var section = $('villas').getElementsByClassName('activeVilla');
			if(section.length)
			{
				$(section[0]).removeClassName('activeVilla');
			}
			var sections = $('villas').getElementsByClassName('villa_section');
			var section = $A(sections).find(function(section){ return section.visible()==true; });
			if (section) { $(section).hide(); }
			$('villa_'+ele.title).show();
			ele.addClassName('activeVilla');
		
		}
		else if($(ele).hasClassName('imageThumb'))
		{
			new Effect.Fade($('photoAlbum').down('.imageHolder'), {afterFinish:function() {
				$('photoAlbum').down('.imageHolder').down('img').src = $(ele).getAttribute('src');
				new Effect.Appear($('photoAlbum').down('.imageHolder'));
			}.bind(this)});
		}
		
		else if($(ele).hasClassName('vipAmenities'))
		{
			var offset = Position.cumulativeOffset($(ele));
			var dim = $(ele).getDimensions();
			$('vipHolder').style.left = offset[0]+'px';
			$('vipHolder').style.top = offset[1]+30+'px';
			new Effect.Appear($('vipHolder'));
		}
		else if($(ele).hasClassName('closeVipHolder'))
		{
			new Effect.Fade($('vipHolder'));
		}
	}.bind(this));
	Event.observe('container','mouseover', function(e) {
		var ele = Event.element(e);
		if($(ele).hasClassName('navButton'))
		{
			$(ele).style.backgroundImage = 'url(images/palmThumb_silver.jpg)';
			$(ele).style.backgroundColor = '#C0C0C0';
			//    if($(ele).next('ul')){ 
					//new Effect.BlindDown($(ele).next('ul')); 
			//		$(ele).next('ul').show();
			//	}
		}
	}.bind(this));
	Event.observe('navigation','mouseout', function(e) {
		var ele = Event.element(e);
		if($(ele).hasClassName('navButton'))
		{
			$(ele).style.backgroundImage = 'url(images/palmThumb.jpg)';
			$(ele).style.backgroundColor = '#87CEFA';
			//	if($(ele).next('ul')){ 
					//new Effect.BlindUp($(ele).next('ul'));
			//		$(ele).next('ul').hide();
			//	}
		}
		else if($(ele).hasClassName('activeBtn'))
		{
			$(ele).style.backgroundImage = 'url(images/palmThumb.jpg)';
			$(ele).style.backgroundColor = '#87CEFA';
		}
	}.bind(this));
}