// JavaScript Document

$(document).ready(function()
{
	p = 0;
	w = 0;
	Start = true;
	Reverse = false;
	StartSlide = true;
	
	slideBanner();
});

function BreedBeeld()
{
	MaxWidth 	= 	Math.max(Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
					Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
					Math.max(document.body.clientWidth, document.documentElement.clientWidth));
				
	if(MaxWidth > 1300)
	{
		location.href = MaxWidth + '/';
	}
}

function slideBanner()
{
	if(StartSlide)
	{
		p += 1;
		StartSlide = false;
	}
	
	mleft = (p * -490) + 490;
	
	slide = setTimeout(function()
	{
		if(!Reverse)
		{
			if(p < highlights)
			{
				$('#highlight-holder').animate({ marginLeft: mleft + 'px'}, 700, function()
				{
						p += 1;
						slideBanner();
				});
			}
			else
			{
				Reverse = true;
				slideBanner();
			}
		}
		else
		{
			if(p > 1)
			{
				$('#highlight-holder').animate({ marginLeft: mleft + 'px'}, 700, function()
				{
					p -= 1;
					slideBanner();
				});
			}
			else
			{
				Reverse = false;
				slideBanner();
			}
		}
	}, 2500);
}


function weergeefMeerWerk(way)
{
	if($('#meerwerk').is(':hidden') == true)
	{
		$('#MeerWerk').fadeOut(300,function()
		{
			$('#WerkNext').fadeIn(300);
			
		});
		$('#submenu-holder').animate({height : 67});
		$('#meerwerk').slideDown(500);
		$('#meerwerk-optie-close').slideDown(300);
	}
	else
	{
		if(w == 0)
		{
			$('#WerkBack').fadeOut();
		}
		
		//true is vooruit
		if(way == true)
		{
			//Slide
			if(w < MaxWerk)
			{
				if((w + 1) != MaxWerk)
				{
					$('#meerwerk-holder').animate({marginLeft : -((w * 840) + 840)}, 500);
					w += 1;
				}
			}

		}// false is terug
		else if(way == false)
		{
			if(w >= 0)
			{
				if((w - 1) != -1)
				{
					$('#meerwerk-holder').animate({marginLeft : -(w * 840)}, 500);
					w -= 1;
				}
			}
		}
		
		if(w > 0)
		{
			$('#WerkBack').fadeIn();
		}
		
		//alert(w);
	}
}

function sluitMeerWerk()
{
	$('#WerkNext').fadeOut(300);
	$('#MeerWerk').fadeIn(300);
	$('#submenu-holder').animate({height : 27});
	$('#WerkBack').fadeOut();
	$('#meerwerk').slideUp(500, function()
	{
		$('#meerwerk-holder').animate({marginLeft : 0}, 500);
	});

	$('#meerwerk-optie-close').slideUp(300);
}

function showProjector(img, Imgheight, Imgwidth)
{
	maxheight 			= Math.max(document.documentElement.clientHeight) - 150; // maximum hoogte
	maxwidth 			= Math.max(document.documentElement.clientWidth) - 50; // maximum breedte
	mgimg 				= 50; // Margin om plaatje
	
	MaxHeight 			= 	Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
							Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
							Math.max(document.body.clientHeight, document.documentElement.clientHeight)); // echt 100% hoog.
				
	height 				= 	Imgheight;
	width 				= 	Imgwidth;
	
	if(width > maxwidth)
	{
		diff 			= 	width - (maxwidth - mgimg);
		percnt_reduced 	= 	((diff / width) * 100);
		ht 				= 	height - ((percnt_reduced * height) / 100);
		wd 				= 	width - diff;
		Imgwidth 		= 	wd;
		Imgheight 		= 	ht;
	}
	
	if(height > maxheight)
	{
		diff 			= 	height - (maxheight - mgimg);
		percnt_reduced 	= 	((diff / height) * 100);
		wd 				= 	width - ((percnt_reduced * width) / 100);
		ht 				= 	height - diff;
		Imgwidth 		= 	wd;
		Imgheight 		= 	ht;
	}
	
	$('.projector_bg').css({ 	width : (Imgwidth + mgimg) + 'px', 
							 	height : (Imgheight + mgimg) + 'px', 
							 	marginTop : -((Imgheight + mgimg) / 2) + 'px', 
							 	marginLeft : -((Imgwidth + mgimg) / 2) + 'px'});
							 
	document.getElementById('projector_img').src = img;
	
	$('.projector_img').css({	width : Imgwidth + 'px', 
	 							height : Imgheight + 'px', 
	 							marginTop : ((mgimg - 15) / 2) + 'px', 
								marginLeft : (mgimg / 2) + 'px', 
								marginRight : (mgimg / 2) + 'px'});
						 
	$('.projector').css({		width : '100%', 
								height : MaxHeight + 'px'});
	$('.projector').slideDown(1000, 'easeOutBounce');

	$('html, body').animate({scrollTop : 0}, 500);

	fade = setTimeout(function()
	{
		$('.projector_img').fadeIn(700);
		$('.projector_bg').fadeIn(300);
	}, 700);
}

function hideProjector()
{
	$('.projector_bg').fadeOut(300, function()
	{	
		$('.projector_img').fadeOut(700, function()
		{
			$('.projector').slideUp(700);
		});
	});
}

function meerTekst(id)
{
	if($('#nieuws' + id + ' .overons-nieuws-tekst').height() > 310)
	{
		$('#nieuws' + id + ' .overons-nieuws-tekst').animate({height : 310});
		$('#nieuws' + id + ' .overons-nieuws-tekst-more').animate({marginTop : 285});
		$('#minder' + id).css({'display' : 'none'});
		$('#meer' + id).css({'display' : 'block'});
	}
	else
	{
		TekstHeight = $('#nieuws' + id + ' h3').outerHeight(true) + $('#nieuws' + id + ' h2').outerHeight(true) + $('#nieuws' + id + ' p').outerHeight(true) + $('#nieuws' + id + ' .overons-nieuws-tekst-more').height() + 10;
	
		$('#nieuws' + id + ' .overons-nieuws-tekst').animate({height : TekstHeight});
		$('#nieuws' + id + ' .overons-nieuws-tekst-more').animate({marginTop : (TekstHeight - 25)});
		
		$('#meer' + id).css({'display' : 'none'});
		$('#minder' + id).css({'display' : 'block'});
	}
}

function showProjectPop(id)
{
	$('.ThreeCases_popup').css( { marginTop : "121px" } );
	
	$('#ThreeCases_item_'+id+' .ThreeCases_popup').animate( { marginTop : "96px" }, 200 );
	$('#ThreeCases_item_'+id+' .ThreeCases_popup').animate( { marginTop : "101px" },100 );
}
function hideProjectPop(id)
{
	$('#ThreeCases_item_'+id+' .ThreeCases_popup').animate( { marginTop : '96px' }, 100 );
	$('#ThreeCases_item_'+id+' .ThreeCases_popup').animate( { marginTop : '121px' },200 );
}

function contactTekstLeesVerder()
{
	length = document.getElementById('contactTekstTekst').offsetHeight;
	
	position = $('#contactTekstTekst').css( "marginTop" );
	position = position.replace("px","");
	position = position.replace(" ","");
	position = position.replace("-","");
	
	document.getElementById("contactTekstMeer").innerHTML = 'Lees verder';
	
	if( length > 250 )
	{
		if( 235 < (length - position) )
		{
			position = parseInt(position) + 120;
			$('#contactTekstTekst').animate( { "marginTop" : "-"+position+"px" }, 500 );
			
			if( 235 > (length - position) )
			{
				document.getElementById("contactTekstMeer").innerHTML = 'Terug';
			}
		}
		else
		{
			$('#contactTekstTekst').animate( { "marginTop" : "0px" }, 500 );
		}
	}
}
function contactFormButton()
{
	if( document.getElementById('naam').value != 'Naam' && document.getElementById('email').value != 'E-mail' && document.getElementById('onderwerp').value != 'Onderwerp' )
	{
		document.getElementById('contactForm').submit();
	}
	else
	{
		alert('Vul alstublieft alle velden in.');
	}
}

function openPortfolioPopup(id)
{
	if( id == 0 )
	{
		$(".portfolioPopup").css( { display : "none", marginTop : "0px", height : "0px" } );
	}
	else
	{
		$(".portfolioPopup").css( { display : "none" } );
		$(".portfolioPopup#portfolioPopup-"+id).css( { display : "block", height : "0px" } );
		$(".portfolioPopup#portfolioPopup-"+id).animate( { marginTop : "-94px", height : "82px", paddingTop : "10px" }, 100 );
		$(".portfolioPopup#portfolioPopup-"+id).animate( { marginTop : "-84px" }, 100 );
	}
}

function makeURL(url)
{
	document.location = 'http://www.u-lab.nl/'+url+'';
}


// Dit is voor de movieplayer

var currentPosition = 0; 
var currentVolume = 80; 


var player = null;
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	addListeners();
}


function addListeners() {
	if (player) { 
		player.addModelListener("TIME", "positionListener");
		player.addControllerListener("VOLUME", "volumeListener");
	} else {
		setTimeout("addListeners()",100);
	}
}


function positionListener(obj) { 
	currentPosition = obj.position; 
	var tmp = document.getElementById("posit");
	if (tmp) { tmp.innerHTML = "position: " + currentPosition; }
}


function volumeListener(obj) { 
	currentVolume = obj.percentage; 
	var tmp = document.getElementById("vol");
	if (tmp) { tmp.innerHTML = "volume: " + currentVolume; }
}

function createPlayer() {
	var flashvars = {
		//file:"http://content.longtailvideo.com/videos/flvplayer.flv",
		file:"http://www.bepositive.nl/flash/proffer.flv",
		autostart:"false",
        controlbar:"none",
		playlist:"none",
		image: "./userfiles/breedbeeld/Proffer-(12).jpg"
	}
			
	var params = {
		allowfullscreen:"true",
		allowscriptaccess:"always",
		wmode: "opaque"
	}

	var attributes = {
		id:"player1",  
		name:"player1"
	}

	swfobject.embedSWF("./flash/proffer.swf", "placeholder1", "250", "200", "9.0.115", false, flashvars, params, attributes);

}

function createPlayer2() {
	var flashvars = {
		file:"http://www.bepositive.nl/flash/proffer.flv",
		autostart:"true",
		image: "./userfiles/breedbeeld/Proffer-(12).jpg"
	}
			
	var params = {
		allowfullscreen:"true",
		allowscriptaccess:"always"
	}

	var attributes = {
		id:"player1",  
		name:"player1"
	}

	swfobject.embedSWF("./flash/proffer.swf", "placeholder2", "440", "400", "9.0.115", false, flashvars, params, attributes);
}

function profferLink()
{
	document.location.href='http://www.bepositive.nl/werk/proffer';
}
