
jQuery(document).ready(function () {

	Cufon.replace('.font,h1,.rm-2 h3.title', { hover: true , hoverables: { a: true , span: true } });
	
	menu_height();
	
	if ( jQuery.browser.msie )
	{
		jQuery("body").addClass('ie-browser');
		jQuery("body").addClass('ie-browser-'+parseInt( jQuery.browser.version ));
	}
	
	jQuery(".history_back").click(function(){
		history.back();
		return false;
	});

	jQuery("#top-1 .top-menu a,.button-1,.corner").corner("5px");
	
	//element_height(".height-1");
	
	center_me();
	
	var options3 = {
            caption:    'permanent',
            opacity:    1
        }
    
    $('.ppy3').popeye(options3);
    
    $(".faq-box .right h3.question").click(function () { 
      $(this).parent().find('.answer').toggle("slow"); 
    });
    
    
    // CONTACT CLIENT SCRIPT

	$("#contact-form .client-radio label").click(function(){

		var labelFor = $(this).attr('for');

		if( labelFor == 'radio-1' && $("#contact-form input[name='customer_number']").hasClass("required") )
		{

			$("input[name='customer_number']").removeClass('required');

			var clientLabel = $("input[name='customer_number']").parent().find("label");

			var labelText = $(clientLabel).html();
			labelText = labelText.substring(0, labelText.length - 1);
			$(clientLabel).html(labelText);

		}
		else if( labelFor == 'radio-0' && !$("#contact-form input[name='customer_number']").hasClass("required") )
		{

			$("input[name='customer_number']").addClass('required');
			$("input[name='customer_number']").parent().find("label").append("*");

		}

	});
    
//################# END ON LOAD
});

function element_height( element )
{

	var height = 0;
	
	jQuery(element).each(function ()
	{
		
		if ( jQuery(this).height() > height )
			height = jQuery(this).height();
				
			//alert(height);

	});
	
	jQuery(element).height( height );
	
}

function menu_height()
{

	var height = 0;
	
	jQuery( "#top-2 .menu li" ).each(function ()
	{
	
		if ( jQuery(this).height() > height )
			height = jQuery(this).height();
			
			//alert(height);

	});
	
	jQuery( "#top-2 .menu li a" ).height( height );
	jQuery( "#top-2 .menu li .line" ).height( height );

}

function img_rounded_corners()
{
	
	jQuery("img.rounded").each( function () {
		var img = jQuery(this);
		
		// build wrapper
		var wrapper = jQuery('<div class="rounded_wrapper"></div>');
		wrapper.width(img.width());
		wrapper.height(img.height());
		
		// move CSS properties from img to wrapper
		wrapper.css('float', img.css('float'));
		img.css('float', 'none')
		
		wrapper.css('margin-right', img.css('margin-right'));
		img.css('margin-right', '0')
	
		wrapper.css('margin-left', img.css('margin-left'));
		img.css('margin-left', '0')
	
		wrapper.css('margin-bottom', img.css('margin-bottom'));
		img.css('margin-bottom', '0')
	
		wrapper.css('margin-top', img.css('margin-top'));
		img.css('margin-top', '0')
	
		wrapper.css('display', 'block');
		img.css('display', 'block')
	
		// wrap image
		img.wrap(wrapper);
		
		// add rounded corners
		img.after('<div class="tl"></div>');
		img.after('<div class="tr"></div>');
		img.after('<div class="bl"></div>');
		img.after('<div class="br"></div>');
		
	});
	
}

function do_select()
{
	
	jQuery('.querySelect').click(function() {
	
			jQuery(this).parent().children( ".f-box" ).slideDown("slow");

	});
	
	jQuery(".querySelect").parent().find(".f-box li" ).click(function() {
				
		jQuery(this).parent().parent().find(".querySelect").val( jQuery(this).html() );
		jQuery(this).parent().parent().find( ".f-box" ).slideUp("slow");
	
	});
	
	jQuery(".select").hover(
		function () {

		}, 
		function () {
			jQuery(this).find( ".f-box" ).slideUp("slow");
		}
	);

	
}

function check_radio( id )
{
	
	var htmlVal = '';
	
	jQuery(".radio-box a").each(function() {
		
		if( jQuery(this).attr("id") == id )
			jQuery(this).addClass("selected");
		else
			jQuery(this).removeClass("selected");
			
		htmlVal = jQuery( "#" + id + " .check_me " ).html();
		jQuery(".radio-box input").attr( "value" , htmlVal );
										
	});
	
	return false;
	
}

function center_me() {

	jQuery(".center-me-x").each(function(i){
		var aw = jQuery(this).width();
		var pw = jQuery(this).parent().width();
		var mw = (pw - aw) / 2;
		//alert(aw);
		jQuery(this).css('margin-left', mw);
	});

	jQuery(".center-me-y").each(function(i){
		var ah = jQuery(this).height();
		var ph = jQuery(this).parent().height();
		var mh = (ph - ah) / 2;
		//alert(ah);
		jQuery(this).css('margin-top', mh);
	});
	
};

function elements_height( element , extra )
{

	var height = 0;
	
	jQuery( element ).each(function ()
	{
	
		if ( jQuery(this).height() > height )
			height = jQuery(this).height();
			
			//alert(height);

	});
	
	jQuery( element ).height(height+extra);

}

function menu_actions()
{
	
	jQuery(".main-box").hover(
      function () {
        jQuery(this).addClass("main-hover");
      }, 
      function () {
        jQuery(this).removeClass("main-hover");
      }
    );
	
}

/* FORM CHECK */

function IsEmailCorrect(email) {

  return email.match(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/)!=null;

}

function check_form( elem )
{

	var and_what = 0;

	jQuery( elem+" .required" ).each(function ( loop )
	{

			if( jQuery(this).val() == '' || ( jQuery(this).hasClass("email") && !IsEmailCorrect( jQuery(this).val() ) ) )
			{
				jQuery(this).addClass("error");
				and_what = 1;
			}
			else
			{
				jQuery(this).removeClass("error");
			}

	});

	if(and_what == 1)
	{
		alert("Vul de verplichte velden.");
		
	}
	else
	{
		//jQuery( elem ).submit();
		return true;
	}
	
return false;

}

function get_fields( elem )
{

	$( elem+" input,"+elem+" select,"+elem+" textarea" ).each(function(key){
	
		if( $(this).attr('type') == 'radio' && $(this+":checked") )
			console.log(this);
	
	});

}

function send_complaint()
{

	if( check_form( "#complaint-form" ) == true )
	{
	
		$( "#complaint-form" ).submit();
	
	}

}

function send_contact_form()
{

	if( check_form( "#contact-form" ) == true )
	{
	
		$( "#contact-form" ).submit();
	
	}

}

function send_register_form()
{

	if( check_form( "#register-form" ) == true )
	{
	
		$( "#register-form" ).submit();
	
	}

}

function getReference()
{

	var id = $("#main-reference").attr( 'rel' );
	$.ajax({
		type: "POST",
		url: "/ajax.php5",
		data: "action=reference&lastID="+id,
		success: function(msg){
			var ref = msg.split('<!~>');
			
			$("#main-reference").attr( 'rel' , ref[0] );
			$("#main-reference #ref-1").html( ref[1] );
			$("#main-reference #ref-2").html( ref[2] );
			$("#main-reference #ref-3").html( ref[3] );
			
		}
	});
	
	return false;

}

function next_step( item , info )
{

  $("body").addClass('block');
  $("body").append('<div class="blocker"></div>');
	$(item).parent().find("a.button-2").removeClass('active');
	$(item).addClass('active');
	var position = $(item).parent().index();
	$("#complaint-box .inner-box:gt("+position+")").remove();

	$.ajax({
		type: "POST",
		url: "/ajax.php5",
		data: "action=cf&info="+info,
		success: function(msg)
		{
			
			$("body").removeClass('block');
			var step = $("#complaint-box .step:last").text();
			step = step.split(' ');
			$("#complaint-box").append(msg);
			var elem = $("#complaint-box .nodisplay");
			$(elem).find('.step').append(parseInt(step[1])+1);
			$(elem).slideUp('slow');
			$(elem).removeClass('nodisplay');
			
		}
	});
	
	return false;

}

function check_radio( elem )
{

	$(elem).parent().find(".dlabel").removeClass('selected');
	$(elem).addClass("selected");

}

function check_checkbox( elem )
{

	$(elem).toggleClass("selected");

}

function change_cform( elem , form )
{

	var memory = '';
	var temp = '';

	$(".field-line a").removeClass('active');
	$(elem).addClass('active');
	memory = $("#memory").html();
	temp = $("#mf-contact").html();
	$("#memory").html(temp);
	$("#mf-contact").html(memory);

}

function newsletter()
{

	if( check_form( '#newsletter' ) != true )
		return false;

	$('#newsletter .button-2').slideUp();
	$('#newsletter .loading').slideDown();

	var fields = '';

	$("#newsletter .field").each(function(key)
	{

		if( fields == '' )
			fields = $(this).attr("name")+'='+$(this).val();
		else
			fields = fields+'&'+$(this).attr("name")+'='+$(this).val();

	});

	$.ajax({

		type: "POST",
		url: "/bdr/ajax.php5",
		data: "action=newsletter&"+fields,
		success: function( msg )
		{
			
			$('#newsletter .loading').slideUp();
			if( msg == 1 )
			{
				$('#newsletter #nl-form').slideUp();
				$('#newsletter #nl-exist').slideUp();
				$('#newsletter #nl-thak-you').slideDown();
			}
			else if( msg == 214 )
			{
				$('#newsletter .button-2').slideDown();
				$('#newsletter #nl-exist').slideDown();
			}

			return false;
		}

	});
	return false;

}

