var Site = {
	
	start: function(){
		
		//Site.appearText();
		if ($('feature-wrap')) Site.featureCarousel();
	
	},
	
	featureCarousel: function() {
		var wrapper = $('feature-wrap'); // The outer wrapper
		var carousel = $('feature-carousel'); // The inner wrapper
		var items = $$('#feature-carousel div.feature-item'); // The different elements, this is an array
		var item_width = 880; // The full width of a single item (incl. borders, padding, etc ... if there is any)
		var max_margin = items.length * item_width - item_width;
		
		var animation = new Fx.Tween(carousel, {duration: 400});
		
		var repeat = function() {
			var position = parseInt(carousel.getStyle('margin-left'));
			next_item(position);
		};
		repeat.periodical(10000);
		
		// The function to browse forward
		function next_item(pos){
			if(pos == -max_margin){
				animation.start('margin-left', 0);
			} else { 
				var newposition = pos - item_width;
				animation.start('margin-left', newposition);
			}
		}

		// The function to browse backward
		function previous_item(pos){
			if(pos == 0){
				animation.start('margin-left', -max_margin);
			} else { 
				var newposition = pos + item_width;
				animation.start('margin-left', newposition);
			}
		}

		// Set up the 'next' and 'previous' buttons
		$('feature-next').addEvent('click', function(){
			var position = parseInt(carousel.getStyle('margin-left'));
			next_item(position);
			return false;
		});
		
		// Previous item not activated
		//$('feature-previous').addEvent('click', function(){
		//	var position = parseInt(carousel.getStyle('margin-left'));
		//	previous_item(position);
		//	return false;
		//});
		
	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#topnav li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			//el.setStyle('margin-left', '-176px');
			el.setStyle('margin-left', '0px');
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-left', {
				duration: 100,
				transition: Fx.Transitions.quadOut,
				wait: false,
				onComplete: Site.createOver.pass([el, i])
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
	},
	
	createOver: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a') return;
		var overfxs = new Fx.Styles(el, {'duration': 200, transition: Fx.Transitions.quadOut, 'wait': false});
		if (first.hasClass('selected')){
			var tocolor = '#000';
			var fromcolor = '#505153';
		} else {
			var tocolor = '#000';
			var fromcolor = '#505153';
		}
		el.addEvent('mouseover', function(){
			overfxs.start({
				'margin-top': -150,
				'height': 173
			});
			first.style.backgroundColor = tocolor;
			first.style.height = '100%';
		});
		el.addEvent('mouseout', function(){
			overfxs.start({
				'margin-top': 0,
				'height': 23
			});
			first.style.backgroundColor = fromcolor;
			first.style.height = 'auto';
		});
	}	
	
};

window.addEvent('domready', Site.start);

function TellAColleague(lastPageTitle)
{
	var path = document.location.href;
	if (path.indexOf('?lastPagePath=') > 0) path = path.substring(0, path.indexOf('?lastPagePath='));
	document.location.href='/Tip+en+ven?lastPagePath=' + escape(path) + '&lastPageTitle=' + escape(lastPageTitle);
}

function fncToggleShow(pDiv) {
	document.getElementById(pDiv).style.display=(document.getElementById(pDiv).style.display=='none')? 'block':'none';
}


