// JavaScript Document

$(function(){
		   
	if( $('#footer').attr('class') && $('#footer').attr('class') == 'trigger_mail' ){
		alert('uw mail is verzonden.');
	}
	

//	$('#site-menu ul li').sifr({ path: '/images/flash', font: 'InfoOffBold', after: function(param) { 
	//	$('a embed').click(function(){ alert('jo'); window.location = $(this).parents('li').find('a').attr('href');  });
//	}});
	$('#site > #site-container > #content-center > h1 > strong, h1.titel').sifr({ path: '/images/flash', font: 'InfoOffBold', textAlign: 'left', height:18, width:330, flashvars: { h: 18  }  });
	$('#site > #site-container > #content-right > h1 > strong').sifr({ path: '/images/flash', font: 'InfoOffBold', textAlign: 'left', height:18, width:165, flashvars: { h: 18  } });
	
	$('#site-container h1 span, #header-solliciteer, #header-kaart > img').pngfix();
	
	// clear default values
	$('.site_search').focus(function(){
		if( $(this).val() == 'zoeken...' ){
			$(this).val('');	
		}
	});
	 
	$('.nieuws_search').focus(function(){
		if( $(this).val() == 'zoek in nieuwsberichten...' ){
			$(this).val('');	
		}
	});
	
	$('textarea[name="motivatie"]').focus(function(){ 
		if( $(this).val() == 'Typ hier uw motivatie of voeg in onderstaand venster uw sollicitatiebrief toe' ){
			$(this).val('');	
		}
	});
	
	$('a#land').click(function(){
		$(this).parent().html('<span><input type="text" name="land" title="Land" class="input_text" /></span> *').prev().html('Land');
		return false;
	});
	
	//actions
	$('a[href="/printen.php"]').click(function(){
		window.open('/printen.php', 'printen', 'width=400,height=300,scrollbars=yes,toolbar=yes,location=yes, resizable=yes');
		return false;
	});
	
	$('a.send_mail').click(function(){
		$('#mailen_bg').css('display','block');				 
		$('#mailen').css('display','block');
		return false;
	});
	
	$('a.close').click(function(){
		$('#mailen_bg').css('display','none');				 
		$('#mailen').css('display','none');				 
		return false;
	});
	
	$('#header-kaart ul li a').click(function(){
		$('img'+$('#header-kaart ul li a.visible').removeClass('visible').attr('href')).fadeOut("slow");
		$('img'+$(this).addClass('visible').attr('href')).fadeIn("slow");

		return false;
	});
	
	$('#header-kaart ul li a').eq(0).click();
	
	// tabs main
	$("ul.tabs").tabs({
		select: function(ui) {
											
			$('form.vacature input, form.vacature textarea').each(function(){
				if( $(this).attr('type') == 'radio' && $(this).attr('checked')){
					$('#input_'+$(this).attr('name')).html($(this).val());
				}
				if( $(this).attr('type') == 'text' && $(this).val().length > 0){
					$('#input_'+$(this).attr('name')).html($(this).val()).css('display','block').prev().css('display','block');
				}
				if( $(this).attr('type') == 'file'  && $(this).val().length > 0){
					$('#input_'+$(this).attr('name')).html('Ja');
				}
				if( $(this).attr('class') == 'input_textarea' ){
					$('#input_'+$(this).attr('name')).html($(this).val());
				}
			});
		},show: function(){
			if($('ul.tabs').data('selected.tabs') == 0){
				$('.p1').css('display','block');
				$('.p2, .p3').css('display','none');
			}
			if($('ul.tabs').data('selected.tabs') == 1){
				$('.p2').css('display','block');
				$('.p1, .p3').css('display','none');
			}
			if($('ul.tabs').data('selected.tabs') == 2){
				$('.p3').css('display','block');
				$('.p2, .p1').css('display','none');
			}
	}});
	
	// tabs nav
	$('.p1 a').eq(0).click(function(){
		$('ul.tabs').tabs('select', 0);
		return false;
	});
	$('.p1 a').eq(1).click(function(){
		$('ul.tabs').tabs('select', 1);
		return false;
	});
	$('.p2 a').eq(0).click(function(){
		$('ul.tabs').tabs('select', 0);
		return false;
	});
	$('.p2 a').eq(1).click(function(){
		$('ul.tabs').tabs('select', 2);
		return false;
	});
	$('.p3 a').eq(0).click(function(){
		$('ul.tabs').tabs('select', 1);
		return false;
	});
	$('.p3 a').eq(1).click(function(){
		$('form.vacature').submit(); 
		return false;
	});
	
	// google maps
	$('#header-gmaps').click(function(){
		$('#google_maps').jmap('init', {mapZoom:9, mapCenter:[51.991491,4.393158], mapShowjMapIcon:false}, function(el, options){
       		$('#header-small-image').jmap('addMarker', {pointLatLng:[52.025498,4.538834], pointHTML:'Hoofdvestiging<br /><br />Klappolder 1<br /><br />2665 LP Bleiswijk'});
       		$('#header-small-image').jmap('addMarker', {pointLatLng:[51.944455,4.245368], pointHTML:'Herenlaan 27<br /><br />3155 DC Maasland'});
		});
		
		$('#header-show_header').css('display','block');
		$(this).css('display','none');
		
		return false;
	});
	
	$('#feest-gmaps').click(function(){
		$('#google_maps').jmap('init', {mapZoom:13, mapCenter:[52.033568, 4.488675], mapShowjMapIcon:false}, function(el, options){
       		$('#header-small-image').jmap('addMarker', {pointLatLng:[52.033568, 4.488675], pointHTML:'Sport Party, <br /> Conferentiecentrum Dekker<br /><br />Scheglaan 12<br />2718 KZ<br />Zoetermeer'});
		});
		
		$('#header-show_header').css('display','block');
		$(this).css('display','none');
		
		return false;
	});
		
	$('#header-show_header').click(function(){
		$('#header-gmaps, #feest-gmaps').css('display','block');
		$('#google_maps').html('').attr('style','');
		$(this).css('display','none');
	});
	
	if( $('#site-container').attr('class', 'trigger_gmaps_contact') ){
		$('#header-gmaps, #feest-gmaps').click();
	}
	 
	// form check
	$('form').submit(function(){ 
		
		var txt = '';
		$(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;
		}					
	});

	$('input, textarea').each(function(){
		if( $(this).attr('title') && $(this).attr('title').length > 0 ){
			$(this).parents('dd').append(' <sup>*</sup>');
		}
	});

	// input file
	$("input[type=file]").filestyle({ 
    	image: "/images/buttons/choose-file.png",
    	imageheight : 23,
    	imagewidth : 80,
    	width : 235
	});
	
	// interne link fixen
	var temp = '';
	var url = '';
	$('a').each(function(){
		url = $(this).attr('href');	
		if( url.indexOf('?') > 0 ){
			$(this).attr('href', url+'&a=true');
		}
	});
	
	// externe link fixen
	$('a[rel=extern]').attr('target','_blank');
	
	var temp = parseInt( $('#content-center').css('padding-bottom') );
		
	$('.fake_button').toggle(function(){
									  
		$('#header-solliciteer').css('display', 'none');
		$(this).next().slideDown('slow', function(){
			
			var height = 0;
			$(this).find('ul li a').each(function(){
				height = height + $(this).height();
			});
			
			if($.browser.msie){ $('#site').css('padding-bottom',height-temp+'px'); }
		});
	}, function(){
	
		$(this).next().slideUp('slow', function(){
			$('#header-solliciteer').css('display', 'block');
			if($.browser.msie){ $('#site').css('padding-bottom','0px'); }
		});
	});
	
	
	$('#content-center .content:has(a img.fotoalbum)').css('text-align','center');
	
	$('.foto-overzicht a').click(function(){
		$('#content-center .content a:has(img.fotoalbum)').replaceWith('<a href="'+$(this).attr('href').replace('&size=500','')+'" id="'+$(this).attr('id').replace('item', 'foto')+'" target="_blank"><img class="fotoalbum" src="'+$(this).attr('href')+'" /></a>');
		
		return false;									 
	});
	
	$('#content-center .next').click(function(){
		var id = $('#content-center a:has(img.fotoalbum)').attr('id').substr( $('#content-center a:has(img.fotoalbum)').attr('id').indexOf('-')+1 );
				
		if( $('.foto-overzicht a#item-'+id).next().length > 0 ){
			$('.foto-overzicht a#item-'+id).next().click();
		}
		else{
			$('.foto-overzicht a').eq( 0 ).click();
		}
		
		return false;
	});
	
	$('#content-center .prev').click(function(){
		var id = $('#content-center a:has(img.fotoalbum)').attr('id').substr( $('#content-center a:has(img.fotoalbum)').attr('id').indexOf('-')+1 );
		
		if( !$('.foto-overzicht a#item-'+id).prev().length ){
			$('.foto-overzicht a').eq( $('.foto-overzicht a').length-1 ).click();
		}
		else{
			$('.foto-overzicht a#item-'+id).prev().click();
		}
		return false;
	});
	
	
	 
});
