// Image preloader
jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$.preloadImages('/images/loading.gif');

$(document).ready(function() {
	// Tabs bij aanbieders
	$("#tabs").tabs();

	// Standaard tab instellen
	if ($('.active').attr('id')) {
		var tab_id = parseInt($('.active').attr('id').replace('tab_',''));
		$('#tabs').tabs('select', tab_id);
	}

	// Overzichten met aanbieders
	$('.aanbieders tr').hover(
		function() {
			$(this).addClass('active');
		}, 
		function() {
			$(this).removeClass('active');
		}
	);

	$('.aanbieders .logo').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id').replace('logo_','');
			window.open('/link/' + id);			
		});
	});

	$('.aanbieders .status').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id').replace('status_','');
			window.open('/link/' + id);			
		});
	});

	$('.aanbieders .status_tekst').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id').replace('status_tekst_','');
			window.open('/link/' + id);			
		});
	});

	$('.meer_info').each(function() {
		$(this).click(function() {
			var id = $(this).attr('id').replace('id_','');
			
			$('#meer_informatie').removeClass('ui-tabs-hide');
			$('#tabs').tabs('select', 5);
			$('#meerinfo_tekst').html('Hieronder treft u meer informatie over de aangeboden diensten en producten. <br />Als u de site in een nieuw venster wilt openen, <a href="/link/' + id + '" rel="nofollow" target="_blank">klikt u hier</a>.');

			$('iframe').each(function() {
				$(this).addClass('hide');
			});

			$('#frame_' + id).removeClass('hide');
		});
	});
	
	// Details van de storingen 
	$('.storing li .title').hover(
		function() {
			$(this).addClass('link');
		}, 
		function() {
			$(this).removeClass('link');
		}
	);

	$('.storing li .title').click(function() {
		$(this).next('.hide').toggle();
	});
	
	// Advies
	$('.advies_provider').change(function() {
		if (this.value == 'other') {
			$('.advies_provider_other').show();
		}
		else {
			$('.advies_provider_other').hide();
		}
	});
	
	$('.advies_extra_table').hide();
	
	$('.advies_extra').click(function() {
		$('.advies_extra_table').toggle();
	});
	
	// Ervaring toevoegen
	$('#provider').change(function() {
		if (this.value == 'other') {
			$('.provider_other').show();
		}
		else {
			$('.provider_other').hide();
		}
	});

	// Anchor koppelen aan tab
	var query = location.href.split('#');

	if (query[1] == 'ervaring') {
		$('#tabs').tabs('select', 3);
	}

	if (query[1] == 'toevoegen') {
		$('#tabs').tabs('select', 4);
	}	
});