//*********************
//	SIDEBAR 100%
//*********************
function SetDivSizes(){
	var theheight = getPageHeight();
	var thewidth = document.body.scrollWidth;
	// MINIMAL HEIGHT
	if (theheight < 500){
		theheight = 500; 
		document.body.scroll="yes";
	}
	else{
		document.body.scroll="no";
	} 
	// EXPAND BACKGROUND
	document.getElementById('content').style.height = theheight+"px" ;

	// POSITION FOOTER
	document.getElementById('footer').style.marginLeft = ((thewidth-750)/2)+"px";

	// EXPAND LEFTBAR+RIGHTBAR

	document.getElementById('leftBarBg').style.height = theheight+"px" ;

	if(document.getElementById('portfolioList')){
		if($('#portfolioListWrapper').height() != (theheight-69)){
			$('#portfolioListWrapper').height(theheight-69);
		}
	}
	setTimeout(function(){	
		$('#omschrijvingContent').jScrollPane({scrollbarWidth:18,showArrows:true});
		$('.jScrollPaneDrag').css('width','16px');
		makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
	}, 500);
	/*		if(document.getElementById('omschrijving')){
		$('#omschrijving').css('height',(theheight-169)+"px");
		$('#omschrijvingContent').css('height',(theheight-169)+"px");

		$('.jScrollPaneContainer').css('height', (theheight-169)+"px");
	} */

}

//*********************
//	HULPFUNCTIES
//*********************

function getPageHeight() {
	if (window.innerHeight && window.scrollMaxY) { // Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
	}
	return yWithScroll;
}


//*********************
//	POPUPS POSITIONEREN
//*********************

$(document).ready(function () {

	var ieDiff = ($.browser.msie ? 7 : 0);

	$('a.showPopupL').mouseenter(function(){
		$('#popupL').stop(true,true).html($(this).prev().html()).show().animate({opacity:0.6},100).animate({opacity:1},1000).fadeOut(100);
	});

	$('a.showPopupR').mouseenter(function(){
		$('#popupR').stop(true,true).html($(this).prev().html()).show().animate({opacity:0.7},100).animate({opacity:1},1000).fadeOut(100);
	});
	
	$('body').mousemove(function(e){
		$('#popupR').css({top:e.pageY-10+ieDiff+'px'});
		$('#popupL').css({top:e.pageY-140+ieDiff+'px'});
	});
	
	
	$('#omschrijving').hover(function(){
		$(this).stop(true,true).animate({opacity: 1},800);

	},function(){
		$(this).stop(true,true).animate({opacity: 0.05},800);
	}); 

	// zorgen dat de breedte overeen komt met het viewport zodat de effecten geen scrollbalken veroorzaken
	$(window).resize(function() {
		$('#mainHolder').css('width',$(window).width()+'px');	
	});

	$('#mainHolder').effect('fold',{mode:'show'},1000,function(){
		$('#flash').show();
	});

	$('a.showPopupL, a.showPopupR').click(function(){
		var a  = this;
		$('#mainHolder').effect('fold',{mode:'hide'},750,function(){
			document.location= $(a).attr('href');
		});
	});
	SetDivSizes();

	// omschrijving hoogte goed zetten
	$(window).resize(function() {
		positionOmschrijving();
	});
	positionOmschrijving(); 
}); 

function positionOmschrijving(){
	var innerHeight = $('#foreground').height()+"px";
	var maxHeight = $(window).height()-158;
	$('#omschrijvingContent').jScrollPaneRemove();

	if(innerHeight < maxHeight){
		$('#omschrijvingContent').height(innerHeight);
	}else{
		$('#omschrijvingContent').height(maxHeight);
		setTimeout(function(){$('#omschrijvingContent').jScrollPane({scrollbarWidth:18,showArrows:true});},1000);
	}	
	
}

function makeScrollable(wrapper, scrollable){
	// Get jQuery elements
	var wrapper = $(wrapper), scrollable = $(scrollable);
	// height of area at the top at bottom, that don't respond to mousemove
	var inactiveMargin = 99;					
	// Cache for performance
	var wrapperWidth = wrapper.width();
	var wrapperHeight = wrapper.height();
	// Using outer height to include padding too
	var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
	// Do not cache wrapperOffset, because it can change when user resizes window
	// We could use onresize event, but it's just not worth doing that 
	// var wrapperOffset = wrapper.offset();	
	var lastTarget;
	//When user move mouse over menu			
	wrapper.mousemove(function(e){
		var wrapperOffset = wrapper.offset();
		// Scroll menu

		$('#debug').html(wrapper.height());

		var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
		if (top < 0){
			top = 0;
		}			
		wrapper.scrollTop(top);
	});
	

}

//*********************
// Verwijder image
//*********************

function delImage(form,target){

	if (document.forms[form][target].checked ){

		document.forms[form][target].checked = false; 
		}
	else{
		document.forms[form][target].checked = true; 
		}
}

