$(document).ready(function(){
	menu();						
});

$(window).load(function(){
	$('.submenu_top').each(function(){
		var nWidth = $(this).parents('.menu_item').width();
		$(this).css('width',nWidth);
	});
});

function getSort(){
	$('.selectbox-wrapper ul li').click(function(){
		
		var sSelect = $(this).parents('.sorteer').attr('id');
		var aSelect = sSelect.split("_");
		
		var sValue = $(this).attr('id');
		aSort = sValue.split("_")
		var nKey = $(aSort).length;
		sValue = aSort[(nKey -1)];
		
		switch(aSelect[1]) {
			case 'plaats':
				sData = 'sPlaats='+sValue;
			break;
			case 'prijs':
				sData = 'sPrijs='+sValue;
			break;
			case 'soort':
				sData = 'sSoort='+sValue;
			break;
			case 'type':
				sData = 'sType='+sValue;
			break;
			case 'energie':
				sData = 'sEnergie='+sValue;
			break;
		}
		updateWoningen(sData);
	});
}

function updateWoningen(p_sData){
	$.ajax({
		type: 'POST',
		url: sDomain+'inc/overzicht.inc.php',
		data: p_sData,
		success: function(result){
			$('#ajax').html(result);
		}
	});
}

function menu() {
	$('.menu_item').hover(function() {
		$(this).addClass('active');
		$(this).children('.submenu').show();
	}, function() {
		$(this).removeClass('active');
		$(this).children('.submenu').hide();
	});
}

function sfeerCycle() {
	$('#cycle')
		.after('<div id="nav">')
		.cycle({
			fx:     'fade',
			timeout: 6000,
			speed:	 900,
			pager: '#nav',
			after: function(curr,next,opts) {

			}
	});
}

function initKeuze() {
	$('.opschrift').hover(function() {
		$(this).children('.sub_items').show();
	}, function() {
		$(this).children('.sub_items').hide();
	});
}

function showSubitemTekst(){
	$('.subitem_titel').click(function(){
		var sItem = $(this).attr('id');
		$('#bericht_'+sItem).slideToggle();
	});
}

function customSelect(){
        $("select").each(function(){
               $(this).wrap("<div class='selector'></div>");
               // Store the value of title in the variable spanText
               var spanText = $(this).attr('title');
               // Use the variable span text as the default for the select field
               var span = "<span class='select'>" + spanText + "</span>";
               $(this).before(span)
               .fadeTo(1, 0)
               .focus(function(){
                       $(this).parents(".selector").addClass("focus");
               })
               .change(function(){
                       $(this).siblings("span").text($(this).children(":selected").text());
               }).click ( function (){
                       $(this).siblings("span").text($(this).children(":selected").text());   
               }) 
               .blur(function(){
                       $(this).parents(".selector").removeClass("focus");
               });     
        });
        $('select').trigger("change");
}

function radioButtons() {
	$('.radio').click(function() {
		$('label.radio').removeClass('checked');	
		$('label.radio').find('input').attr('checked','false');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','true');
	});
	$('.radio2').click(function() {
		$('label.radio2').removeClass('checked');	
		$('label.radio2').find('input').attr('checked','');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','checked');
	});
	$('.checkbox').toggle(
		function() {
			$(this).prev().attr('checked','checked');
			$(this).addClass('checked');
			$(this).children('input').val('Ja');
		},
		function(){
			$(this).prev().attr('checked','');
			$(this).removeClass('checked');
			$(this).children('input').val('');
		}	
	);
}
