var $j = jQuery.noConflict();

$j(document).ready(ap_klant_init);

function ap_klant_init()
{	
	$j('.cboxElement').colorbox({transition:'fade', speed:500});
	
	$j('.cboxElement_video').colorbox({transition:'fade', speed:500});
			
	$j('.all').change(behandel_message_checkboxes);
	
	$j('.incoming').click(function(){
		wissel_berichten_tabel('sent');
	});
	$j('.sent').click(function(){
		wissel_berichten_tabel('incoming');
	});
	
	$j('.uitleg_link').click(function(){
		$j('.community_uitleg').fadeIn();
		$j('.uitleg_link').css('display', 'none');
	});
	
	$j('.uitleg_close_link').click(function(){
		$j('.community_uitleg').fadeOut();
		$j('.uitleg_link').css('display', 'block');
	});
	
	check_checkboxes();
	
	$j('.exhibitor_activiteit').change(check_checkboxes);
	
	$j('.np').change(behandel_uur_selects);
	
	$j('#profile_part_1_link').click(function(){
		$j('#profile_form_part_1').fadeIn();
		$j('#profile_part_1_link').attr('class', 'profile_nav_link current_part');
		$j('#profile_form_part_1').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').hide();
		$j('#profile_part_2_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').hide();
		$j('#profile_part_3_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').hide();
		$j('#profile_part_4_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').attr('class', 'profile_nav_link');
	});
	
	$j('#profile_part_2_link').click(function(){
		$j('#profile_form_part_1').hide();
		$j('#profile_part_1_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_1').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').fadeIn();
		$j('#profile_part_2_link').attr('class', 'profile_nav_link current_part');
		$j('#profile_form_part_2').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').hide();
		$j('#profile_part_3_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').hide();
		$j('#profile_part_4_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').attr('class', 'profile_nav_link');
	});
	
	$j('#profile_part_3_link').click(function(){
		$j('#profile_form_part_1').hide();
		$j('#profile_part_1_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_1').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').hide();
		$j('#profile_part_2_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').fadeIn();
		$j('#profile_part_3_link').attr('class', 'profile_nav_link current_part');
		$j('#profile_form_part_3').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').hide();
		$j('#profile_part_4_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').attr('class', 'profile_nav_link');
	});
	
	$j('#profile_part_4_link').click(function(){
		$j('#profile_form_part_1').hide();
		$j('#profile_part_1_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_1').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').hide();
		$j('#profile_part_2_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_2').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').hide();
		$j('#profile_part_3_link').attr('class', 'profile_nav_link');
		$j('#profile_form_part_3').attr('class', 'profile_nav_link');
		$j('#profile_form_part_4').fadeIn();
		$j('#profile_part_4_link').attr('class', 'profile_nav_link current_part');
		$j('#profile_form_part_4').attr('class', 'profile_nav_link');
	});
}

function behandel_message_checkboxes()
{	
	// eerst uitvinden of de checkbox gechecked is of niet...als hij niet gechecked is moeten we alle checkboxes van de
	// aanwezige messages aanvinken, als hij wel gechecked is moeten we alle aangevinkte messages terug uitvinken.
	var checked = '';
	
	var active_class = $j('.selected').attr('class');
	
	// we halen de klasse op van de knop die bepaalt welke div van berichten die getoond wordt.  Dit moeten we doen omdat
	// we anders het gevaar lopen dat iemand al zijn binnenkomende berichten wil verwijderen en de 'all' checkbox gebruikt
	// om al zijn berichten te selecteren.  Als we niets doen selecteerd dit echter ook zijn verstuurde berichten, daarom
	// halen we de klasse op van de actieve berichten zodat we alleen in deze div kunnen selecteren
	active_class = active_class.replace('selected', '');
	active_class = active_class.replace(' ', '');
	
	if($j('.all').attr('checked') == true)
	{
		$j('#'+active_class+'_messages_container table.community td input').attr('checked', 'checked');
	}
	else
	{
		$j('#'+active_class+'_messages_container table.community td input:checked').attr('checked', '');
	}
}

function wissel_berichten_tabel(type)
{
	// de klassen van de 2 knoppen aanpassen zodat de juiste knop "geselecteerd" staat
	
	// alle checkboxes afvinken (uit veiligheid)
	$j('table.community input:checked').attr('checked', '');
	
	// de tabellen omwissellen
	if(type == 'incoming')
	{
		$j('.sent').attr('class', 'selected sent');
		$j('.incoming').attr('class', type);
		$j('#incoming_messages_container').css('display', 'none');
		$j('#sent_messages_container').css('display', 'block');
		$j('.bericht_div_hidden').attr('value', 'sent');
	}
	else
	{
		$j('.sent').attr('class', type);
		$j('.incoming').attr('class', 'selected incoming');
		$j('#incoming_messages_container').css('display', 'block');
		$j('#sent_messages_container').css('display', 'none');
		$j('.bericht_div_hidden').attr('value', 'incoming');
	}
}

function behandel_uur_selects()
{
	// ophalen welke dag dat we moeten behandelen
	var dag = $j(this).attr('class');
	
	dag = dag.replace('np', '');
	dag = dag.replace(' ', '');
	
	if($j(this).attr('checked') != true)
	{
		$j('#dag_'+dag+'_aankomst').attr('disabled', '');
		$j('#dag_'+dag+'_vertrek').attr('disabled', '');
	}
	else
	{
		$j('#dag_'+dag+'_aankomst').val('0');
		$j('#dag_'+dag+'_vertrek').val('0');
		$j('#dag_'+dag+'_aankomst').attr('disabled', 'disabled');
		$j('#dag_'+dag+'_vertrek').attr('disabled', 'disabled');
	}
}

function countdown()
{
	var today = new Date();
	
	var begin = new Date("May 18, 2010 10:00:00");
	
	// het verschil tussen de 2 datums in milliseconden
	var verschil = (begin.getTime() - today.getTime());
	
	var dagen = Math.floor(verschil / (1000*60*60*24));
	
	verschil = verschil - (dagen *(1000*60*60*24));
	
	var uren = Math.floor(verschil / (1000*60*60));
	
	verschil = verschil - (uren * (1000*60*60));
	
	var minuten = Math.floor(verschil / (1000*60));
	
	verschil = verschil - (minuten + (1000*60));
	
	//var resultaat = dagen+' days '+uren+' hours '+minuten+' minutes';
	var resultaat = 'Realty is open for visitors!';
	
	//$j('.counter').html(resultaat);
	
	setTimeout('countdown()', 10000);
}

function check_checkboxes()
{
	var checked = $j('#profile_form_part_4 input:checked').length;
		
	if(checked >= 3)
	{
		$j('#profile_form_part_4 input:checkbox').attr('disabled', 'disabled');
		$j('#profile_form_part_4 input:checked').attr('disabled', '');
	}
	else
	{
		$j('#profile_form_part_4 input:checkbox').attr('disabled', '');
	}
}
