var iTop;
var iMax;
var scrolling;

$(document).ready(

	function()

	{
		if ($.browser.version.charAt(0) < 7 && $.browser.msie){$("#mainnav li").hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});}
		bindProject();		
		bindSubnav();
		bindNav();


		bindLeft();
		
bindScroll();
	
	}

);

/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}


function bindLeft()
{
	$("#layout-left a").click(
		function(e)
		{
			e.preventDefault();
			
			var img = $(this).attr("href");
			
			$("#content-container img").attr("src", img);
			
			$("#layout-left ul li.active").removeClass("active");
			$(this).parent().addClass("active");
		}
	)
}



function bindProject()

{
	$("ul#projecten li a").click(
		function()
		{
			if (!$(this).parent().hasClass("active"))
			{
				var cur = $("ul#projecten li.active");
				var next = $(this).parent();
				
				cur.animate(
						{
							width: "38px"
						},
						250
				);
			

				next.animate(
					{
						width: "684px"
						},
						250
				);
				
				cur.removeClass('active');
				next.addClass('active');
			}
		}
	);
}

function bindSubnav()
{
	var cur;
	
	$("#subnav li").hover(
			function()
			{
				cur = $(this).find("img").attr("src");
				
				$(this).find("img").attr("src", "/gfx/tmpl/subnav-hover.gif");
			},
			function()
			{
				$(this).find("img").attr("src", cur);				
			}
	);
			
}

function bindNav()
{
		$(".left a, .right a").click(
				function(e)
				{
					e.preventDefault();
					$.get(	$(this).attr("href"),
							function(data)
							{
								window.location.href = data;
							}
					);

				}

		);
}

function moveUp()
{
	iTop += 2;
	
	if (iTop > 0)
	{
		iTop = 0;
	}
	
	$("#content-main").css("top", iTop+"px");
}

function moveDown()
{
	iTop -= 2;
	
	if (iTop < iMax)
	{
		iTop = iMax;
	}
	
	$("#content-main").css("top", iTop+"px");
}

function bindScroll()
{
	var iHeight = $("#content-main").height();
	iMax = ((iHeight - 477 ) * -1)-50;
	var pos = $("#content-main").position();
	iTop = pos.top;
	
	$(".up").click(
		function()
		{
			moveUp();
		}
	).mousedown(
		function()
		{
			scrolling = setInterval("moveUp()", 15);			
		}
	).mouseup(
		function()
		{
			clearInterval(scrolling);
		}
	);
	
	$(".down").click(
		function()
		{
			moveDown();
		}
	).mousedown(
		function()
		{
			scrolling = setInterval("moveDown()", 15);			
		}
	).mouseup(
		function()
		{
			clearInterval(scrolling);
		}
	);
}
