$(document).ready(function(){
	init();
	
	$('#mugshotsmap area').each(function()
		{
			$(this).qtip(
				{
					content: { 
						text: $("<img/>").attr("src",$(this).attr('title')),
						title:{ text:false, button:false},
						prerender:true
					},
					style: { 
						width: 700,
						height:438,
						padding:0	
					},
					show: {
						when: { 
							event: 'mouseover'
							},
						delay:0,
						effect:{
							type:'fade',
							length:400
						}	
					},
					hide: { 
						when: { 
							event: 'mouseout'
						},
						delay:0,
						fixed:true,
						effect:{ 
							type:'fade',
							length:200
						}	
					},
					position: {
						target:$('#header_container'),
						type:'absolute',
						tooltip:'bottomLeft',
						adjust:{ 
							x:-839,
							y:-150
						}
					}
				}		
			)
		}
	)
	
	$("#sjonic_team_img, #vacature_homepage_overlay").click(function(){
		window.location='vacature-php-programmeur-ijsselstein-bij-utrecht';
	});
	
	//lightbox voor klanten pagina
	prevclass = 'leeg';
	$('a[class^=\'project\']').each(function(){
		if($(this).attr('class')!=prevclass){
			$("."+$(this).attr('class')).lightBox({fixedNavigation:true});
		}
		prevclass = $(this).attr('class');
	})
	
	
	// light box
	$('#lightbox1 li a').lightBox({fixedNavigation:true});
	$('#lightbox2 li a').lightBox({fixedNavigation:true});
	$('#lightbox3 li a').lightBox({fixedNavigation:true});
	$('#lightbox4 li a').lightBox({fixedNavigation:true});
	$('#lightbox5 li a').lightBox({fixedNavigation:true});
	$('#lightbox6 li a').lightBox({fixedNavigation:true});
	$('#lightbox7 li a').lightBox({fixedNavigation:true});
	$('#lightbox8 li a').lightBox({fixedNavigation:true});
	$('#lightbox9 li a').lightBox({fixedNavigation:true});
	$('#lightbox10 li a').lightBox({fixedNavigation:true});
	$('#lightbox11 li a').lightBox({fixedNavigation:true});
	$('#lightbox12 li a').lightBox({fixedNavigation:true});
	$('#lightbox13 li a').lightBox({fixedNavigation:true});
	$('#lightbox14 li a').lightBox({fixedNavigation:true});
	$('#lightbox15 li a').lightBox({fixedNavigation:true});
	
	
	//fotos opening
	$('.imglink').lightBox({fixedNavigation:true,
		txtImage: 'Foto',
		txtOf: 'van'
	});

/*	
	$("#header_container a[href*='mugshots']").lightBox({fixedNavigation:true,
		txtImage: 'Foto',
		txtOf: 'van'
	});
*/

	
	$(".imglink img").mouseover(function(){
		$(this).css({ border: "5px #f39912 solid"});
	}).mouseout(function(){
		$(this).css({ border: "5px #fff solid"});
	});
	
	$("#gallery_previous img[src='img/button_arrowleft.gif']").mouseover(function(){
		$(this).attr({ src: "img/button_arrowleft_hover.gif"});
	}).mouseout(function(){
		$(this).attr({ src: "img/button_arrowleft.gif"});
	});
	
	$("#gallery_next img[src='img/button_arrowright.gif']").mouseover(function(){
		$(this).attr({ src: "img/button_arrowright_hover.gif"});
	}).mouseout(function(){
		$(this).attr({ src: "img/button_arrowright.gif"});
	});
	
	maxprj = 7;
	imgwidth = 243;
	projectSlide();
	
	$("#projectpane_navigation li a").click(function() {
		$(".activeprj").removeClass('activeprj');
		$("#projectpane_image_container").stopTime("projectslide");
		if(parseInt(($(this).attr('name'))-1)*imgwidth != parseInt($("#projectpane_image_container").css('marginLeft'))){
			$("#projectpane_description_container").animate({
				marginLeft: "-"+parseInt(($(this).attr('name'))-1)*imgwidth+"px"
			},800,"easeOutBack");
			
			$("#projectpane_image_container").animate({
				marginLeft: "-"+parseInt(($(this).attr('name'))-1)*imgwidth+"px"
			},800,"easeOutBack",projectSlide);
		}
		$(this).addClass('activeprj');
	});
});

function init (){
	$('#sneeuw, #kerstbal1, #kerstbal2, #mistletoe').css('behavior', 'url(css/iepngfix.htc)');
	//behavior: url(css/iepngfix.htc);
	
	$('#header_container img').fadeIn(2000);
	
	// submit hovers
	$("#verstuursubmit").mouseover(function(){
		$(this).attr({ src: "img/button_verzenden2.gif" });
	}).mouseout(function(){
		$(this).attr({ src: "img/button_verzenden1.gif" });
	});
	
	// contact form submit ajax
	$('#jq_contactformulier').submit(function() {
    	var data = $(this).formSerialize();
		var div = '#jq_contactformulier_container';
		var action = 'php/contactformulier.php';
		ajaxCall(data, div, action);
		return false;
	});
	// return contact form
	$('#jq_show_contactform').click(function() {
		var div = '#jq_contactformulier_container';
		var action = 'php/contactformulier.php';
		ajaxCall('', div, action);
		return false;
	});
	
	// empty contact form fields

	$('#jq_contactformulier input, #jq_contactformulier textarea').focus(function() {
		if ($(this).val()==$(this).attr('id')) $(this).val('');
	});
	$('#jq_contactformulier input, #jq_contactformulier textarea').blur(function() {
		if ($(this).val()=='') $(this).val($(this).attr('id'));
	});

	$('.list-images li a').click(function() {
		$('.photo-box-display').hide();
		$('.photo-box-display').html('<img src="'+$(this).attr('href')+'" />');
		$('.photo-box-display').fadeIn('fast');
		return false;
	});
	
	$('.nieuwsitem[name]').click(function(){
		window.location = $(this).attr('name');
	})
	
	$('.nieuwsitem[name]').each(function(){
		$(this).attr({ style: "cursor:pointer"});
	})
	
	$('.nieuwsitem[name]').mouseover(function(){
		//something
	}).mouseout(function(){
		//something
	});
	
}

function ajaxCall(data, div, action){
	$.ajax({
        type: "POST", url: action, data: data,
        error: function(msg){
        },
        success: function(msg){
        	$(div).html(msg);
        	init();
        }
    });
}

function projectSlide(){
	$("#projectpane_image_container").everyTime(5000,"projectslide",function(i){
		if(parseInt('-'+(imgwidth*(maxprj-1))) < parseInt($("#projectpane_image_container").css('marginLeft'))){
			slidemargin = parseInt($("#projectpane_image_container").css('marginLeft'))-imgwidth;
			
			$("#projectpane_description_container,#projectpane_image_container").animate({
				marginLeft: slidemargin+"px"
			},800,"easeOutBack");
			
			if(parseInt($(".activeprj").attr('name')) <= maxprj){
				newactive = parseInt($(".activeprj").attr('name'))+1;
				$(".activeprj").removeClass('activeprj');
				$("#projectpane_navigation li a[name='"+newactive+"']").addClass('activeprj');
			}
		}
		else{
			$(".activeprj").removeClass('activeprj');
			$("#projectpane_navigation li a[name='1']").addClass('activeprj');
			$("#projectpane_description_container,#projectpane_image_container").animate({
				marginLeft: "0"
			},800,"easeOutBack");
		}
	});
}

function removeKerstkaart(){
	$("#kertstkaart_flash").remove();
}
