$(document).ready(function() {
	$('div.category_box').live('mouseenter',
		function () {
	    	$(this).addClass('category_box_hover');
			
			if($(this).has('ul li').size())
			{
				$('div', this).hide();
				$('ul', this).show();
			}
		} 
	);
	$('div.category_box').live('mouseleave',
		function () {
	    	$(this).removeClass('category_box_hover');
			$('ul', $(this)).hide();
			$('div', this).show();
	    }
	);
	$('div.profile_box').live('mouseenter',
		function () {
	    	$(this).addClass('profile_box_hover');
			
			if($(this).has('ul li').size())
			{
				$('div', this).hide();
				$('ul', this).show();
			}
		} 
	);
	$('div.profile_box').live('mouseleave',
		function () {
	    	$(this).removeClass('profile_box_hover');
			$('ul', $(this)).hide();
			$('div', this).show();
	    }
	);
	
	var category_click_handler = function(event){
		$(event.currentTarget).unbind('click');
		$('a', event.currentTarget).click();
		$(event.currentTarget).bind('click', category_click_handler);
		return false;
	};
	
	$('div.category_box').not(':has(ul li)').css('cursor', 'pointer').bind('click', category_click_handler);
	
});

function choose_category(sender, id, name, translated_name)
{
	var tab = $('ul.steps li.active a');
	tab.text(translated_name);
	
	$('input:hidden[name=category_id]').val(id);
	$('input:hidden[name=category]').val(name);
	
	var next_tab = $('a', tab.parent().next('li'));

	var body = $('div.tab_content#' + next_tab.attr('id').substr(4));
	body.html('<img src="/img/front/loading.gif"/> Keuze wordt verwerkt... <BR><BR><BR><BR><BR><BR><BR>');
	
	$(next_tab).click();
	//body.load('/nl/ajax/price_range/'+id);
	body.load('/nl/ajax/profiles/'+id);
	
	return false;
}

function choose_budget(sender)
{
	sender = $(sender);

	if($('p.amout_info strong.price', sender).text() == 'Alle Prijzen'){
		alert('test');
		$('input:hidden[name=budget]').val('&plusmn; &euro 5000');
	}
	else {		
		$('input:hidden[name=budget]').val($('p.amout_info strong.price', sender).text());
	}

	var body = $('div.tab_content#');
	body.html('<img src="/img/front/loading.gif"/> <h2>We vergelijken nu alle producten van 52 webshops</h2><BR>LET OP: dit kan tot 10 seconden duren.<BR><BR><BR><BR><BR><BR><BR>');
	$('form#step_form').submit();
	return false;
}

function choose_profile(sender, name, display_name)
{
	sender = $(sender);
	$('input:hidden[name=profile]').val(name);
	
	var tab = $('ul.steps li.active a');
	var next_tab = $('a', tab.parent().next('li'));
	
	tab.text(display_name);
	
	var body = $('div.tab_content#' + next_tab.attr('id').substr(4));
	body.html('<img src="/img/front/loading.gif"/><h2>Een ogenblik geduld..</h2><BR> De budget mogelijkheiden worden berekend. <BR><BR><BR><BR><BR><BR><BR>');
	if ($('input:hidden[name=category_id]').val() == 114) {
		var body = $('div.tab_content#');
		body.html('<img src="/img/front/loading.gif"/> <h2>Een ogenblik geduld..</h2><BR>Vanwege de hoeveelheid Kamervragen duurt het vergelijk max 20 sec.<BR><BR><BR>Het vergelijken van Laptop, LCD TV, Camera, etc. gaat veel sneller.<BR><BR><BR><BR><BR><BR><BR>');
		$('input:hidden[name=budget]').val(100000);
		$('form#step_form').submit();
	}
	else {
		body.load('/nl/ajax/price_range/' + $('input:hidden[name=category_id]').val() + '/' + name);
		$(next_tab).click();
	}
	return false;
}
