this.imagePreview = function(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 30;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");	
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

var scrollLeft = function() {
	$('#thumbnail').animate(function() {
			left: '+=160'
		}, 500, 'linear', function() {
			scrollLeft();
	});
};

var scrollRight = function() {
	$('#thumbnail').animate(function() {
			left: '-=160'
		}, 500, 'linear', function() {
			scrollRight();
	});
};

$(document).ready(function() 
{
	imagePreview();
	
	/* Make the height fixed: */
	var contentMinHeight = $(document).height()-88;
	if( $('#content_left').height() < contentMinHeight )
	{
		$('#content_left').height(contentMinHeight);
		$('#content_right').height(contentMinHeight);
	}

	if( $('#tS2').length != 0 )
	{
		$("#tS2").thumbnailScroller({ 
			scrollerType:"clickButtons", 
			scrollerOrientation:"horizontal", 
			scrollSpeed:2, 
			scrollEasing:"easeOutCirc", 
			scrollEasingAmount:600, 
			acceleration:4, 
			scrollSpeed:800, 
			noScrollCenterSpace:10, 
			autoScrolling:0, 
			autoScrollingSpeed:2000, 
			autoScrollingEasing:"easeInOutQuad", 
			autoScrollingDelay:500 
		});
	}

	if( $('#scrollcount').length != 0 )
	{
		$('.jTscrollerPrevButton').mousedown(function() {
		  $.get("portfolio/clickcount/"+$('#scrollcount').attr('name')+"/prev/");
		});
		$('.jTscrollerNextButton').mousedown(function() {
			$.get("portfolio/clickcount/"+$('#scrollcount').attr('name')+"/next/");
		});
		if( $('#scrollcount').val() > 0 )
		{
			$('.jTscrollerNextButton').click();
		}
	}

	$(window).resize(function() {

		var contentMinHeight = $(document).height()-88;

		if( $('#content_left').height() < contentMinHeight )
		{
			$('#content_left').height(contentMinHeight);
			$('#content_right').height(contentMinHeight);
		}
	});



	if( $('#overlays').length != 0 )

	{

		var randomArray = new Array();

		$("#overlays div.item div.underlay").each(function() {
			counter = 0;
			$(this).children("IMG.underlay").each(function() 
			{
				counter++;
				if( counter > 1 )
				{	
					if(jQuery.inArray( $(this).parent().attr('id') ,randomArray) > -1) 
					{

					}

					else

					{

						randomArray.push( $(this).parent().attr('id') );

					}

				}

			});

		});

		

		if( randomArray.length > 0 )
		{		
			$('#'+randomArray[ Math.floor(Math.random()*randomArray.length) ] ).cycle({
				fx:    'fade', 
				speed:  1500 
			});
		}
	}


	$('.button_left').mouseover(function() {
		Scroll(true, true);
	}).mouseout(function() {
		Scroll(false, true);
	});


	$('.button_right').mouseover(function() {
		Scroll(true, false);
	}).mouseout(function() {
		Scroll(false, false);
	});
});



function Scroll(blnStart, blnDirection_Right)

{

	if (blnStart)

	{

		if (blnDirection_Right)

		{

			intTimer_Scroll = setTimeout("_Scroll_Move(true)", 100);

		}

		else

		{

			intTimer_Scroll = setTimeout("_Scroll_Move(false)", 100);

		}

	}

	else

	{

		clearTimeout(intTimer_Scroll);

		intTimer_Scroll = false;

	}

	return true;

}

function _Scroll_Move(blnDirection_Right)

{

	if (blnDirection_Right)

	{

		$scrollto = $('#thumbnail').scrollLeft()+6;

		$('#thumbnail').scrollLeft( $scrollto );

		intTimer_Scroll = setTimeout("_Scroll_Move(true)", 20);

	}

	else

	{

		$scrollto = $('#thumbnail').scrollLeft()-6;

		$('#thumbnail').scrollLeft( $scrollto );

		intTimer_Scroll = setTimeout("_Scroll_Move(false)", 20);

	}

	return true;

}



function buildSearch( label, action ) 

{

	var target	= label.toLowerCase();

	var action	= action.toLowerCase();

	$('#search').html('<form method="post" action="'+ action +'"><label for="zoeken">'+ label +'</label><div class="input_txt"><input type="text" id="zoeken" name="srch" size="10" /></div><div class="input_btn"><input class="submit" type="image" src="images/search_btn.jpg" height="17" width="17" border="0" alt="" /></div></form>');

}


