// JavaScript Document

$(document).ready(function() {
		
	
	
		
	$('a[rel="extern"]').attr('target', '_blank');
	
	// IE HACK
	
	if ($.browser.safari) {
		$("#middle, #content, #footer").css('margin','0 11px 0 11px');
	}
	else if ($.browser.msie) {
		$("#middle, #content, #footer").css('margin','0 10px 0 12px');
		
		if (parseInt($.browser.version) < 7) {
		
			var lHeight = $("#content-left").height()+100;
			var rHeight = $("#content-right").height()+100;
			
			if (lHeight > rHeight) {
				$("#content").css('height', rHeight+'px');
			}
			else {
				$("#content").css('height', lHeight+'px');
			}
			
			$("#menu UL.children").css('background','#F2AA0F');
			$("#footer").css('margin','0 0 0 1px');
			$("#content").css('background', 'url(/images/backgrounds/content.png) repeat-y top center white');
		}
	}
	
	// IMAGE ROLLOVER
	
	$("IMG.hover").hover(function() {
		var tmp = $(this).attr('src');
		tmp = tmp.replace('normal','hover');
		$(this).attr('src', tmp);
	},
	function() {
		var tmp = $(this).attr('src');
		tmp = tmp.replace('hover','normal');
		$(this).attr('src', tmp);
	
	});
	
	// ZOEKSCHERM
	
	$("#header-search-input").focus(function() {
		if ($(this).val() == 'Zoeken in de site') {
			$(this).val('');
		}
	});
	
	$("#header-search-input").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Zoeken in de site');
		}
	});
	
	// FLASH
	
	$("H1").each(function() {
		var tekst = $(this).text();
		$(this).text('');
		$(this).flash(
			{src: '/images/flash/h1.swf',
			width: 500,
			height: 30, 
			flashvars: { title: tekst },
			wmode: 'transparent'},
			{ version: 8 }
		);
	});
	
	$("H2").each(function() {
		var tekst = $(this).text();
		$(this).text('');
		$(this).flash(
			{src: '/images/flash/h2.swf',
			width: 200,
			height: 30, 
			flashvars: { title: tekst },
			wmode: 'transparent'},
			{ version: 8 }
		);
	});
	
	
	$("H3").each(function() {
		var tekst = $(this).text();
		$(this).text('');
		$(this).flash(
			{src: '/images/flash/h3.swf',
			width: 500,
			height: 25, 
			flashvars: { title: tekst },
			wmode: 'transparent'},
			{ version: 8 }
		);
	});
	
	// GOOGLE MAPS
	
	var jmaps = $("#jmaps").html();
	
	$('#jmaps').jmap('init', {mapCenter:[51.958858,3.162302], mapShowjMapIcon:false, mapEnableType:true}, function(el, options){							
			$(el).jmap("searchAddress", {address: jmaps}, function(options, point) {								   		
				$("#jmaps").jmap("moveTo", {mapCenter: [point.y, point.x]});
        		$("#jmaps").jmap('addMarker', {pointLatLng:[point.y, point.x], pointHTML: '' + options.address + ' '});
			});
	});
	
	
	// MENU 
	
	
	if ($.browser.msie && parseInt($.browser.version)< 7) {
	    $("#menu ul li").hover(function() {
           	$(this).addClass("sf");
        },
        function() {
			$(this).removeClass("sf");
    	});
	}
	
	
	// FOTOALBUMS
	
	$(".fotoalbum-load").click(function() {
		$("#middle").css('height','496px');
		$("#middle > .container").css('height','496px');
		$("#header").css('height','450px');
		$("#header > .container").css('height','450px');
		$("#header-image").remove();
		$("#fotoalbum, #fotoalbum-next, #fotoalbum-previous").remove();
		
		$('<div id="fotoalbum" class="jcarousel-container"><div class="jcarousel-clip"><ul class="jcarousel-list"></ul></div></div>').appendTo("#header .container");
		
		$('<div id="fotoalbum-next"><img src="/images/icons/next.png" alt="Volgende" />').appendTo("#header .container");
		$('<div id="fotoalbum-previous"><img src="/images/icons/previous.png" alt="Vorige" />').appendTo("#header .container");
		
		$.ajax({
   			type: "GET",
   			url: $(this).attr('href'),
   			async: false,
			dataType: 'json',
   			success: function(data){
     			
				$.each(data, function(i,item) {
					$('<li class="jcarousel-item"><img src="/docs/thumb/'+item.id+'/878/60" alt="'+item.omschrijving+'" /></li>').appendTo("#fotoalbum UL");
				});
				
				$('.jcarousel-list').jcarousel({
					initCallback: mycarousel_initCallback,
					wrap: 'last',
					scroll: 1,
					animation: 'slow'
				});
			}
		});
		
		$(".fotoalbum-load").removeClass('active');
		$(this).addClass('active');		
		
		return false;
	});
	

	
		
	
	/* PNG HACK */
	
	
	$.pngfix('/images/common/pixel.gif');
	$('img[@src$=.png], #footer, #content').pngfix();
		
	
	
	// 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;
		}
	});
	


});


function mycarousel_initCallback(carousel) {
    jQuery('#fotoalbum-previous').bind('click', function() {
        carousel.prev();
        return false;
    });
    jQuery('#fotoalbum-next').bind('click', function() {
        carousel.next();
        return false;
    });
};

