var nrProjects;
var projectIndex = 1;
var iv;
var menuIV;
var wallDirection = -1;
var ophis = 
{
	initProjects : function (nr, offset)
	{
		$('#project_wrapper').css('left', '0px');
		
		nrProjects = nr;
		projectIndex = (offset + 1);
		$('a.prev').click(function()
		{
			projectIndex = Math.max(1, projectIndex - 1);
			ophis.slideProjects();
			return false;
		});
		
		$('a.next').click(function()
		{
			projectIndex = Math.min(nrProjects, projectIndex + 1);
			ophis.slideProjects();
			return false;
		});
		
		$('#pager a').click(function()
		{
			projectIndex = $(this).attr('rel');
			ophis.slideProjects();
			return false;
		});
		
		this.slideProjects();
	},
	
	slideProjects : function()
	{
		//var $target = $('#project_' + projectIndex);
		$('#projecten').stop().scrollTo('li:eq(' + (projectIndex-1) + ')', 850, {axis:'x', margin:false});
		this.updateNav();
	},
	
	updateNav : function()
	{
		$('#pager a.current').removeClass('current');
		$('#pager a#page_' + projectIndex).addClass('current');
		if (projectIndex == 1)
		{
			$('a.prev').hide(200);
		}
		else if ($('a.prev').is(':hidden'))
		{			
			$('a.prev').show(200);
		}
		if (projectIndex >= nrProjects)
		{
			$('a.next').hide(200);
		}
		else if ($('a.next').is(':hidden'))
		{
			$('a.next').show(200);
		}
	},

	initWall : function()
	{
		$('a.down').mouseenter(function() 
		{
			iv = setInterval('ophis.moveWall()', 20);
			wallDirection = 1;
		}).mouseleave(function() 
		{
			clearInterval(iv);
		}).click(function()
		{
			return false;
		});
		
		$('a.up').mouseenter(function() 
		{
			iv = setInterval('ophis.moveWall()', 20);
			wallDirection = -1;
		}).mouseleave(function() 
		{
			clearInterval(iv);
		}).click(function()
		{
			return false;
		});
	},
	
	moveWall : function()
	{
		var newTop = $('#wallposts').scrollTop() + wallDirection * 5;
		$('#wallposts').scrollTop(newTop);
	},
	
	initProjectMenu : function()
	{
		$('#watwedoennav a').mouseenter(function()
		{
			var rel = $(this).attr('rel');
			clearTimeout(menuIV);
			if (rel)
			{
				$('ul.sub').hide();
				$('#menu_' + rel).show();
			}
		}).mouseleave(function()
		{
			menuIV = setTimeout('ophis.hideSubs()', 500);
		});
	},
	
	hideSubs : function()
	{
		$('ul.sub').hide();
		$('ul.active').show();
		clearInterval(menuIV);
	},
	
	initImageZoom : function(web_dir)
	{
		$("div#content img").removeAttr('title');
		$.each($("div#content img.enableZoom"), function() 
		{
			var isLink = false;
			var parent = $(this).parent();
			while (parent)
			{
				isLink |= parent.is('a');
				if (parent.attr('id') == 'content')
					parent = null;
				else
					parent = parent.parent();
			}			
			if (!isLink)
			{
				var id;
				do
				{
					id = 'lb_' + Math.round(Math.random() * 1000);
				} while ($('a#' + id).length > 0);
				
				var src_props 	= $(this).attr('src').match(/\/(\d+)_([a-zA-Z0-9]+)_(\d+)_(\d+)\.([a-zA-Z0-9]+)/);
				var large_img 	= 'image/' + src_props[1] + '_' + src_props[2] + '_large.' + src_props[5];
				var link	 	= '<a id="' + id + '" class="pp" href="' + large_img + '"></a>';
				$(this).before(link);
				//$('a#' + id).attr('title', $(this).attr('title'));
				$('a#' + id).append($(this).remove());
			}
		});
		$('a.pp').prettyPhoto({
			opacity: 0.40, /* Value between 0 and 1 */
			show_title: false, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			theme: 'light_square', /* pp_default / light_rounded / dark_rounded / light_square / dark_square / facebook */
			overlay_gallery: false, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
			social_tools: ''
		});
	}
}
