$(function() {
	
	// $.include(['js/jquery.color.js','styles/contact.css']);
	// 
	// if(parseInt(jQuery.browser.version) == 6) {
	// 	$.include(['styles/ie-fix.css']);
	// }
	
	
	$("a[href^='http://']:not([href*=ronduitnederlands.nl])").attr("rel","external");
	$("a[rel=external]").attr("target","_blank").addClass('external').each(function(i) {
		var title = $(this).attr("title") ? $(this).attr("title") : $('img', this).attr("title");
		title = $.trim(title) ? $.trim(title) : $.trim($(this).text());
		if (title) $(this).attr("title", title + " (Externe link)");
		else $(this).attr("title", "Externe link");
	}).filter(":has(img), .portal-klant").removeClass('external').removeClass('pdf');

	$("img[src$='png'], .png, #top, #picture2, #main_top").ifixpng();
	
	
	var mainHeight = $('#main_container').height();
	
	var ran1 = Math.floor(Math.random()*(mainHeight/2))+100;
	var ran2 = Math.floor(Math.random()*(mainHeight/2));
	
	$('#circle1').css({top: ran1+'px'});
	$('#circle2').css({bottom: ran2+'px'});
	
	$('#circle1').animate({top: 70}, 5000);
	$('#circle2').animate({bottom: 0}, 10000);
	
	
	$("#navmain li:not('#active') a").fadeColors({backgroundColor:'#b90000'});
	
	$("#nav_content li:not('#activepage') a").fadeColors({backgroundColor:'#1a1a1a',color:'white'});
	

	$('#navhead li:last').css('border','none');
	
	
	// $("#nav_content li#activepage a").append("<span>&rsaquo;</span>");
	
	
	$('#nav_content a:first').addClass('ronding');
	$('#nav_content a:last').addClass('ronding2');
	
	
	
	var contactForm = $("#contact").validate({
		groups: {
			pc_plaats: "pc_cijfers pc_letters plaats"
		},
		errorPlacement: function(error, element) {
			if (element.attr("name") == "pc_cijfers" || element.attr("name") == "pc_letters" )
				error.insertAfter("#plaats");
			else
				error.insertAfter(element);
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				success: function() {
					var naam = " " + $('#naam').fieldValue();
					var bedankt = "<h1>Bedankt" + naam + "!</h1>\n<p>Bedankt voor het versturen van het contactformulier. Wij zullen uw verzoek binnen 1 werkdag verwerken.</p>";
					$('#content').html(bedankt);
				}
			});
		}
	});
	
/*	
	$('.contact-load').ajaxStart(function() {
		$(this).show();
		// alert('start');
	}).ajaxSuccess(function() {
		$(this).hide();
	});
*/	
	
	
	$("a[href$='media/presentatie/']").popUp({width:800,height:600});
	
	$('#quick').quickNews();
	
});


/*
 * Translated default messages for the jQuery validation plugin.
 * Language: NL
 */
jQuery.extend(jQuery.validator.messages, {
        required: "Dit is een verplicht veld.",
        remote: "Controleer dit veld.",
        email: "Vul hier een geldig email adres in.",
        url: "Vul hier een geldige URL in.",
        date: "Vul hier een geldige datum in.",
        dateISO: "Vul hier een geldige datum in (ISO).",
        number: "Vul hier een geldig nummer in.",
        digits: "Vul hier alleen nummers in.",
        creditcard: "Vul hier een geldig credit card nummer in.",
        equalTo: "Vul hier dezelfde waarde in.",
        accept: "Vul hier een waarde in met een geldige extensie.",
        maxlength: jQuery.format("Vul hier maximaal {0} tekens in."),
        minlength: jQuery.format("Vul hier minimaal {0} tekens in."),
        rangelength: jQuery.format("Vul hier een waarde in van minimaal {0} en maximaal {1} tekens."),
        range: jQuery.format("Vul hier een waarde in van minimaal {0} en maximaal {1}."),
        max: jQuery.format("Vul hier een waarde in kleiner dan of gelijk aan {0}."),
        min: jQuery.format("Vul hier een waarde in groter dan of gelijk aan {0}.")
});


jQuery.fn.hellip = function() {
	return this.each(function() {
		var txt = $(this).text();
		count = txt.length;
		if (count >= 26) {
			txt = txt.substring(0,20);
			$(this).html(txt+'&hellip;');
		}
	});
};


jQuery.fn.fadeColors = function(settings) {
	settings = jQuery.extend({
		color: null,
		backgroundColor: null,
		duration: 200
	}, settings);
	
	return this.each(function() {

		var _backgroundColor = $(this).css('backgroundColor');
		var _color = $(this).css('color');

		$(this).hover(function() {
		
			!settings.backgroundColor?settings.backgroundColor=$(this).css('backgroundColor'):settings.backgroundColor;
			!settings.color?settings.color=$(this).css('color'):settings.color;
			
			$(this).css({backgroundColor:_backgroundColor,color:_color}).stop().animate({backgroundColor:settings.backgroundColor,color:settings.color},settings.duration);
		},function() {
			$(this).stop().animate({backgroundColor:_backgroundColor,color: _color},settings.duration);
		});
		
	});
};


jQuery.fn.popUp = function(settings) {
	return this.each(function() {
		$(this).click(function() {
    		settings = jQuery.extend({
				name: 'popup',
				width: 600,
				height: 400,
				scrollbars: 0,
				resizable: 0,
				toolbar: 0,
				location: 0,
				statusbar: 0,
				menubar: 0	
			}, settings);
	
			var url = this.href;
			var left = (screen.availWidth - settings.width)/2;
			var top = (screen.availHeight - settings.height)/2;
	
			var props = 'width='+settings.width+',height='+settings.height+',left='+left+',top='+top+',toolbar='+settings.toolbar+',scrollbars='+settings.scrollbars+',location='+settings.location+',statusbar='+settings.statusbar+',menubar='+settings.menubar+',resizable='+settings.resizable+',directories=0';
	

			if (url) {
				window.open(url, settings.name, props).focus();
			} else {
				alert(url);
			}
		
			return false;
		});
	});
};

jQuery.fn.quickNews = function(settings) {	
	return this.each(function() {
		settings = jQuery.extend({
			delay: 10000,
			transition: 1000
		}, settings);
		
		var $this = $(this);
		var $list = $this.find('ul');
		var $quick = $(this).find('li');
		var current = 0;
		var over = false;
		$this.show();
		
		function slide() {
			current = current < $quick.length ? current : 0;
			if (!over) {
				$list.empty().html($quick[current]).find('li').show().delayAnimation(settings.transition/2).css({left:$this.width()}).animate({left:0},settings.transition);
				current++;
			}
			
			$this.delayAnimation(settings.delay,function() {
				if (!over) $this.find('li').fadeOut(settings.transition/2,slide);
				else slide();
			});
		}
		slide();
		
		$this.hover(function() { over = true; },function() { over = false; });	
		
	});
};

