
jQuery(document).ready(function () {
	
	center_me();
	//Cufon.replace('.font', { hover: true , hoverables: { span: true } });
	
	jQuery(".history_back").click(function(){
		history.back();
		return false;
	});
	
	img_rounded_corners();
								 
	jQuery(".radio-box a").click(function(){ check_radio( jQuery(this).attr("id") ); });
		
	menu_actions();
	do_select();
	jQuery("div.checkbox").buttonset();
	
	jQuery('#page-gallery').cycle({ 
		fx:     'fade',
		speed:  'fast',
		prev:   '#prev1',
		next:   '#next1',
		timeout: 10000 
	});
	
	jQuery('.p-gallery').after('<div class="p-nav">').cycle({ 
		fx:     'fade',
		speed:  'fast',
		timeout: 10000,
		pager:  '.p-nav'
	});

	jQuery(".main-box,.link-box-1 .box,.nav a,.p-nav a, span.search-word").corner("5px");
	jQuery(".link-box-1 .box").corner("9px");
	jQuery(".news-date span.date").corner("10px");
	jQuery(".menu-modul .menu li a").corner("left 5px");
	jQuery(".p-gallery-container").corner("bottom 9px");
	jQuery("#contact .right .submit").corner("3px");
	
	jQuery("span.span-link-next,span.span-link-prev,span.span-link-before").each(function () {
		
		jQuery(this).parent("a:first").css( "text-decoration" , "none" );
						   
	});
	
	jQuery("#ShowNewsHiddenTxt").click(function () {
		jQuery("#NewsHiddenTxt").toggle("slow");
		if( jQuery(this).html() == 'Lees meer' )
		{
			jQuery(this).html('Sluiten');
			jQuery(this).removeClass('more');
			jQuery(this).addClass('back');
		}
		else
		{
			jQuery(this).html('Lees meer');
			jQuery(this).removeClass('back');
			jQuery(this).addClass('more');
		}
		return false;
	});  

	elements_height( ".main-box .push" , 9 );
	elements_height( ".main-box .main-txt" , 0 );

	setTimeout( "center_me()", 1 );
	
// END ON LOAD
});

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").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( idk )
{

	var and_what = 0;
	var brochures = 0;

	jQuery( "#"+idk+" .check" ).each(function ( loop ) {

			//alert (jQuery(this).attr("type") + ' === ' + jQuery(this).val() );


			if( jQuery(this).attr('type') != 'checkbox' && ( jQuery(this).val() == '' || ( jQuery(this).hasClass("email") && !IsEmailCorrect( jQuery(this).val() ) ) ) )
			{
				jQuery(this).addClass("error");
				and_what = 1;
			}
			else if( jQuery(this).attr('type') == 'checkbox' && !jQuery(this).parent().find('input[type="checkbox"]').is(':checked') )
			{
        		jQuery(this).parent().find('input[type="checkbox"]').addClass("error");
        		and_what = 1;
        		brochures = 1;
   		    }
			else
			{
				jQuery(this).removeClass("error");
			}

	});

	if( and_what == 1 && brochures == 0 )
	{
		alert("Vul de verplichte velden.");
		return false;
	}
	else if( and_what == 1 && brochures == 1 )
	{
		alert("Vul de verplichte velden.\nGraag minimaal één brochure aanvinken.");
		return false;
	}
	else
	{
		jQuery( "#"+idk ).submit();
	}
	
return false;

}


