$(document).ready(function() {

	$(".dropdown dt a").click(function() {
		var dt = $(this).parent();
		var dropdown = dt.parent();
		dropdown.find('dd ul').toggle();
	});

	$("dd.content").hide();
  $("dt.toggle a").click(function(){
    $(this).parent().next("dd").toggle();
    return false;
  });

  $('input.numeric').keydown(function(event){
		if ( event.keyCode == 46 || event.keyCode == 8 || 110 == event.keyCode || 190 == event.keyCode ) {
		} else {
			if (event.keyCode < 95) {
				if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 9 ) {
					event.preventDefault();
				}
			} else {
				if ((event.keyCode < 96 || event.keyCode > 105)) {
					event.preventDefault();
				} 
			}
		}
	});
	
//
//	 $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	  	
//	 
//	 $("a#friesland, dd#friesland").hover(function(){
//	    $("dd#friesland").show();
//	    $("dd#overijssel, dd#groningen, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#friesland").mouseout(function(){
//	    $("dd#friesland").hide();
//	    return false;
//  	});
//  	
//  	$("a#groningen, dd#groningen").hover(function(){
//	    $("dd#groningen").show();
//	    	 $("dd#friesland, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#groningen").mouseout(function(){
//	    $("dd#groningen").hide();
//	    return false;
//  	});
//  	
//  	$("a#drenthe, dd#drenthe").hover(function(){
//	    $("dd#drenthe").show();
//	    	 $("dd#friesland, dd#groningen, dd#overijssel, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#drenthe").mouseout(function(){
//	    $("dd#drenthe").hide();
//	    return false;
//  	});
//  	
//  	$("a#overijssel, dd#overijssel").hover(function(){
//	    $("dd#overijssel").show();
//	    	 $("dd#friesland, dd#groningen, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#overijssel").mouseout(function(){
//	    $("dd#overijssel").hide();
//	    return false;
//  	});
//  	
//  	$("a#flevoland, dd#flevoland").hover(function(){
//	    $("dd#flevoland").show();
//	    	 $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#flevoland").mouseout(function(){
//	    $("dd#flevoland").hide();
//	    return false;
//  	});
//  
//  	$("a#gelderland, dd#gelderland").hover(function(){
//	    $("dd#gelderland").show();
//	    	 $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#gelderland").mouseout(function(){
//	    $("dd#gelderland").hide();
//	    return false;
//  	});
//  	
//  	$("a#utrecht, dd#utrecht").hover(function(){
//	    $("dd#utrecht").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#utrecht").mouseout(function(){
//	    $("dd#utrecht").hide();
//	    return false;
//  	});
//  	
//  	$("a#noordholland, dd#noordholland").hover(function(){
//	    $("dd#noordholland").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#zuidholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#noordholland").mouseout(function(){
//	    $("dd#noordholland").hide();
//	    return false;
//  	});
//  	
//  	$("a#zuidholland, dd#zuidholland").hover(function(){
//	    $("dd#zuidholland").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#noordbrabant, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#zuidholland").mouseout(function(){
//	    $("dd#zuidholland").hide();
//	    return false;
//  	});
//  	
//  	$("a#noordbrabant, dd#noordbrabant").hover(function(){
//	    $("dd#noordbrabant").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#zeeland, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#noordbrabant").mouseout(function(){
//	    $("dd#noordbrabant").hide();
//	    return false;
//  	});
//  	
//  	$("a#zeeland, dd#zeeland").hover(function(){
//	    $("dd#zeeland").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#limburg").hide();
//	    return false;
//  	});
//  
//  	$("a#zeeland").mouseout(function(){
//	    $("dd#zeeland").hide();
//	    return false;
//  	});
//  	
//  	$("a#limburg, dd#limburg").hover(function(){
//	    $("dd#limburg").show();
//	    $("dd#friesland, dd#groningen, dd#overijssel, dd#drenthe, dd#flevoland, dd#gelderland, dd#utrecht, dd#noordholland, dd#zuidholland, dd#noordbrabant, dd#zeeland").hide();
//	    return false;
//  	});
//  
//  	$("a#limburg").mouseout(function(){
//	    $("dd#limburg").hide();
//	    return false;
//  	});
//  	
  	

	$(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
		//$(".dropdown dt a span").html(text);
		//$(".dropdown dt dd ul").hide();
		
		var dropdown = $(this).parents().eq(4);
		
		$(dropdown).find("dl dt a span").html(text);		
		$(dropdown).find("dd ul").hide();
	});

	function getSelectedValue(id) {
		return $("#" + id).find("dt a span.value").html();
	}

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
		$(".dropdown dd ul").hide();
	});

	$('a[class="iframehyp"]').each(
	function (i) {
		$(this).replaceWith("<iframe src='" + this.getAttribute("href") + "' frameborder='0' scrolling='no' width='490' height='700'></iframe>");
	});


	//Producten tabs

	$("#productentabs ul li div").hide();
	text = $("#productentabs ul li:first div").html();
	$('.producttextOutput').html(text);


	$('#productentabs ul li').hover(function ()
	{
		$("#productentabs ul li div").hide();
		$("#productentabs ul li").removeClass();
		var text = $(this).find('div').html();
		$('.producttextOutput').html(text);
		$(this).addClass('active');
	});


	//offerte formulier

	$('#offerte div').hide();
	$('#offerte #one').show();

	$('#offerte p.next').click(function() {
		$('#offerte div').hide();
		var next = $(this).attr('id');
		$('#offerte').find('div#'+next).show();
		return false;
	});

	// Partner gegevens verbergen
	$('ol#partnerGegevens').hide();

	// Partner extra velden tonen als
	// er al gepost is.
	if($('#form_request_partner').val() != "[_NULL]")
	{
		$('ol#partnerGegevens').show('normal');
	}

	$('#form_request_partner').change(function() {

		var selectVal = $(this).val();

		if(selectVal != '[_NULL]')
		{
			$('ol#partnerGegevens').show('normal');
		}
		else{
			$('ol#partnerGegevens').hide('normal');
		}

	});

	// Koopwoning gegevens verbergen
	$('ol#offerteKoopwoning').hide();

	// Koopwoning extra velden tonen als
	// er al gepost is.
	if($('#form_request_current_house').val() == "Koopwoning")
	{
		$('ol#offerteKoopwoning').show('normal');
	}

	// Koopwoning extra velden switch
	$('#form_request_current_house').change(function() {

		var selectVal = $(this).val();

		if(selectVal == 'Koopwoning')
		{
			$('ol#offerteKoopwoning').show('normal');
		}
		else{
			$('ol#offerteKoopwoning').hide('normal');
		}

	});

	/** Tooltip **/
	$(".ffitooltip").mouseover(function (e) {
		$('#tooltipffi').remove();
		$(this).ffitooltip(e);
	});

	$(".ffitooltip").mouseout(function (e) {
		removeTooltip();
	});

	/* interest */
	$("#mortgagetype-select dd ul li a").click(function(e) {
		
			var val = $(this).attr("href");
			$(this).getRentes(val);
	
			e.preventDefault();
	});

	if($('#interest-list').length)
	{
		$(this).getRentes(1);
	}	
		
	
	//----------------- Tabs -----------------//
	
	var tabContainers = $('div.tabs > div');
	    
	    $('div.tabs ul.tabNavigation a').click(function () {
	        tabContainers.hide().filter(this.hash).show();
	        
	        $('div.tabs ul.tabNavigation a').removeClass('selected');
	        $(this).addClass('selected');
	        
	        return false;
	    }).filter(':first').click();
	    
	    
});

/* Tool tip */
jQuery.fn.ffitooltip = function (e) {
	bodyTag = document.body;
	x = e.pageX;
	y = e.pageY;

	newel = document.createElement('div');
	newel.id = 'tooltipffi';
	newel.innerHTML = '<p class="tooltiptitle">'+this.attr('title')+this.attr('alt')+'</p>';

	var cssObj = {
	'position' 		: 'absolute',
	'top' 				:	y ,
	'left' 				: x + 5,
	'width' 			: '250px',
	'background'	:	'#1E5A91',
	'margin'			:	'10px 0 0 -250px',
	'z-index' 		: '100'
	}
	newel.style.display = 'none';
	bodyTag.appendChild(newel);

	$('#tooltipffi').css(cssObj);
	$('#tooltipffi').addClass('tooltipstyle');
	$('#tooltipffi').fadeIn(300);
}
/** Bad remove **/
function removeTooltip()
{
	$('#tooltipffi').fadeOut(300).remove();
	return false;
}

jQuery.fn.getRentes = function(mortgagetype_id) {
	$('.loader').show();
	$('.interest-result').hide();

	$.ajax({
		type: "POST",
		url: "/interactive/files/ajax/interest/ajax.interest.list.php",
		cache: false,
		data: { mortgagetype_id : mortgagetype_id },
		success: function(data){ 
			$('.loader').hide();
			$('#mortgagetype-select').removeAttr('disabled');

			// parse json data
			$('.interest-result').html('');
			$('.interest-result').append(data);
			$('.interest-result').fadeIn('slow');
			
			
			//sorteer data
			$("#rentes").tablesorter(
			{
				widgets: ['zebra'],
				headers: 
				{
					0: {sorter: false},
					1: {sorter: false},
					2: {sorter: false},
					3: {sorter: false},
					4: {sorter: false},
					5: {sorter: false},
					6: {sorter: false},
					7: {sorter: false},
					19: {sorter: false}
				}
			}); 
		}
	});

	return false;
};

jQuery(document).ready(function () {

	// Target blank
	$('a[class^="external"]').click(function () {
		this.target = "_blank"
	});

});


