// JavaScript Document

$(document).ready(function() {	
	
	debugmode 		= true;
		
	$('a[rel="extern"]').attr('target', '_blank');

	/*** FIX STYLE ***/
	$('#content > p, #content > .left > p').eq(0).css({color:'#C0B077', 'font-weight':'bold'});
	$('#content .profile').each(function(){ 
		$(this).find('p').eq(0).css({color:'#C0B077', 'font-weight':'bold'});
	});
	
	$('.input-search').focus(function(){
		if( $(this).val() == "Zoeken in de website..."){
			$(this).val('');
		}
	});
	
	$('#slideShow').innerfade({
        'animationtype': 'fade',
		'speed': 4000,
		'timeout': 5000,
		'type':'sequence'
	});

	/*** PREPARE NICE TEKST ***/

	$('#content h1').qtekst({
		fontSize: 44,
		fontFile: 'DINBol.ttf', 
		color: "#434535", 
		backgroundColor: '#FFFFFF', 
		textShadow: false	
	});
	
	$('#content .profile h2, #content .results h2').qtekst({
		fontSize: 20,
		fontFile: 'DINBol.ttf', 
		color: "#C0B077", 
		backgroundColor: '#FFFFFF', 
		textShadow: false	
	});
	
	$('table.vacatures tr').click(function(){
		var id = $(this).attr('id').substr( $(this).attr('id').indexOf('-')+1 );
		$('div.vacature').hide();
		$('div#item-'+id).show();
	});
	
	$('ul.testimonials li a').click(function(){
		var id = $(this).parent().attr('id').substr( $(this).parent().attr('id').indexOf('-')+1 );
		
		$('ul.testimonials li').css('border', '1px solid #ccc');
		$('ul.testimonials li a').each(function(){
			$(this).css('background', $(this).css('background').replace('/0)','/1)') );
		});
		
		$(this).parent().css('border', '1px solid #B10634');
		$(this).css('background', $(this).css('background').replace('/1)','/0)') );
		
		$('.profiel, .quote, .profile').hide();
		$('#foto-'+id+', #quote-'+id+', #content-'+id).show();
		return false;
	});
	
	$('ul.opdrachtgevers li a').click(function(){
		//return false;						 
	});

	
	var current = $('ul.testimonials li:visible, ul.opdrachtgevers li:visible').length;
	$('.next').click(function(){
		var total = parseInt( $('ul.testimonials li, ul.opdrachtgevers li').length );
		var items = parseInt( $('ul.testimonials li:visible, ul.opdrachtgevers li:visible').length );
		var first = parseInt( $('ul.testimonials li:visible:last, ul.opdrachtgevers li:visible:last').attr('id').substr( $('ul.testimonials li:visible:last, ul.opdrachtgevers li:visible:last').attr('id').indexOf('-')+1 ) );

		first = first + 1;
		last = first + current;
		
		debug('huidig:'+current);
		debug(first+'-'+last+' van de '+total+' ('+items+' zichtbaar)');
		
		if(items < current || first > total){
			first = 1;
			last = first + current;
			items = current;
		}
		
		$('ul.testimonials li:visible, ul.opdrachtgevers li:visible').hide();
		for(first; first < last; first++){
			$('ul.testimonials li#item-'+first+', ul.opdrachtgevers li#item-'+first).show();
		}
		
		return false;
	});

// Form checker
	
	$('form').submit(function(){					
		var txt = '';


		// standaard form check
		$(this).find('input, textarea').each(function(){
			if( $(this).attr('title') && $(this).val().length == 0 ){
				txt += ' - ' + $(this).attr('title') + '\n';
			}
		});
		
		
		if(txt && txt.length > 0){
			var header = '___________________________________________________________\n\n De volgende velden zijn verplicht: \n\n';
			var footer = '___________________________________________________________\n\n ';
			alert(header + txt + footer);
			return false;
		}
	});
	
	
	// IE6 PNG HACKS 
	if($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent)){
		
		$.ifixpng('/images/common/pixel.gif');
		$('img.blaadje, #menu ul li img.active').ifixpng();
		
	
	}
	
	
});

var getColor = function(color){
	
	if( color && color.indexOf('#') < 0 ){
		return eval( color+';' );
	}
	else{
		return color ;
	}
}

var rgb = function(r,g,b){
	var RGB = new Array(256);
	var k = 0;
	var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	
	for (var i = 0; i < 16; i++) {	
		for (var j = 0; j < 16; j++) {		
			RGB[k] = hex[i] + hex[j];
			k++;
		}
	}
	
	if ((r > 255) || (r < 0)) {
		r = 0;
	}
	if ((g > 255) || (g < 0)) {
		g = 0;
	}		
	if ((b > 255) || (b < 0)) {
		b = 0;
	}
	r = dropLeadingZeros(r);
	g = dropLeadingZeros(g);
	b = dropLeadingZeros(b);
	var rr = RGB[r];
	var gg = RGB[g];
	var bb = RGB[b];
	
	return "#" + rr + gg + bb;	
}

var dropLeadingZeros = function(num){
	num = String(num);
	while (num.charAt(0) == "0") {
		newTerm = num.substring(1, num.length);
		num = newTerm;
	}
	if (num == "") 
		num = "0";
	return num;
}

var fotoalbum = function(oud, nieuw){
	
	$('#foto-'+oud).fadeOut('slow', function(){ });
	$('#foto-'+nieuw).fadeIn('slow');
	
	$('.counter').html(nieuw).qtekst({
		fontSize: 17,
		fontFile: 'GothiOneOneCon.ttf', 
		color: "#FFFFFF", 
		backgroundColor: '#030304', 
		textShadow: false	
	});
	
	$('#carousel li img').removeClass('active');
	$('#crs-'+nieuw).addClass('active');

}

// debug functie
var debug = function(text){
	
	if(debugmode == true){		
		if($.browser.mozilla){
			console.info(text);	
		}
	}
}

