var minContentHeight = 300;

$(window).load(function() {
	// init top tab menu
	$('.menu li ').each(function() {
		$(this).bind('mouseover', function() {
			if (this.className != 'hover active')
				this.className = this.className.replace(/\s*/,'') + 'hover';
		});
		$(this).bind('mouseout', function() {
			if (this.className != 'hover active')
				this.className = this.className.replace(/\s*hover\s*/,'');
		});
		$(this).bind('click', function() {
			location.href = this.firstChild.nextSibling.firstChild.href;
		});
	});
	
	// set min content height
	if($('#content').height() < minContentHeight)
		$('#content').css({'height':minContentHeight+'px'});
});

otherSaysToggleInit	= function(target)
{
	
	$(target + ' > div.title > a').each(function() {
		$(this).bind('click', function() {
			// hide first all items
			$(target + ' > div.desc').hide('slow');
			// show the clicked one
			if(jQuery.browser.msie)
				$(this.parentNode.nextSibling).get(0).style.removeAttribute('filter');

			$(this.parentNode.nextSibling).toggle('slow');
			return false;
		});
	});
}

var Scroller = {

	currentNumber 		: 4,
	totalAmount			: 0,
	itemsPerView 		: 4,
	
	init	: function(totalAmount) 
	{
		this.totalAmount = totalAmount;
		var handler = this;
		// set first the opacity of the prev button to 0.33
		$('#viewer_prev').fadeTo("fast", 0.33);
		//by default, the scroll is only done vertically ('y'), change it to both.
		$.scrollTo.defaults.axis = 'xy'; 			
		//this one is important, many browsers don't reset scroll on refreshes
		$('div.pane').scrollTo( 0 );//reset all scrollable panes to (0,0)
		$.scrollTo( 0 );//reset the screen to (0,0)
		//Target examples bindings
		$('#next').click(function(){			
			if (handler.currentNumber < handler.totalAmount) {
		  		$('#viewer').stop().scrollTo( {top:'-=0', left:'+=620'}, 800 )
	   			handler.currentNumber = handler.currentNumber + 4;
			}
			
			if (handler.currentNumber < handler.totalAmount) {
				$('#viewer_next').fadeTo("slow", 1);
				$('#viewer_prev').fadeTo("slow", 1);
			} else {
				$('#viewer_next').fadeTo("slow", 0.33);
				$('#viewer_prev').fadeTo("slow", 1);
			}		
			return false;
		});
		
		$('#prev').click(function(){
		  	if (handler.currentNumber > 4) {
	  			$('#viewer').stop().scrollTo( {top:'-=0', left:'-=620'}, 800 )
	  			handler.currentNumber = handler.currentNumber - 4;
	  		}
	  		if (handler.currentNumber < handler.totalAmount) {
	  			if (parseInt(handler.currentNumber)-parseInt(handler.itemsPerView) == 0) {
					$('#viewer_prev').fadeTo("slow", 0.33);
				} else {
					$('#viewer_next').fadeTo("slow", 1);
				}
			} 
	  		return false;
		});
	}	
};

var Portfolio = {
	
	contentContainerId	: '#portfolio_content_container',
	_ajaxServer 		:  '/ajax_server.php',
	clicked				: false,
	
	init				: function(parentObj)
	{
		$(parentObj + ' > li > a').each(function(){
			$(this).bind('click', function() {
				return Portfolio.displayInformation(this.id.replace('f_', ''));
			});
		});
	},
	
	displayInformation	: function(id)
	{
		if (!this.clicked) {
			this.clicked = true;
			// first show animation gif
			//$('#ajax_loader').html('<img src="/img/loadingAnimation.gif" alt="Een moment geduld alstublieft.." />');
			var handle = this;
			$.get(this._ajaxServer + '?app=portfolio',
			{
				id			: id,
				json		: true
			}, 
		  	function(data){
		  		if (data) {
		  			var objectData = eval('(' + data + ')');
		  			$(handle.contentContainerId).hide();
		  			/* $(handle.contentContainerId).empty(); */
		  			$(handle.contentContainerId).parent().html(objectData.data).fadeIn('slow');
		  			handle.clicked = false;
		  			return false;
		  		};
		  	});
		}
		return false;
	},
	
	toggleNow			: function(imageId)
	{
		var obj = $('#portfolio_content_container div#middle img');
		if (obj.fadeOut('slow')) {  
			obj.attr({'src':'/foto/' + imageId + '/375/image.jpg'});
			obj.fadeIn('slow');
		}
	}
}