$(document).ready(function() {
	showChoice();
	resetField();
	initSubmenu();
	initSlideshow();
});

function showChoice() {
	if($('.piece').length > 0) {
		$('.piece').hover(function(){
			if( $(this).hasClass('zetmeel') ){
				$('#image_choice').attr('src', 'images/template/choice2.jpg');	
			} else if( $(this).hasClass('primeur') ){
				$('#image_choice').attr('src', 'images/template/choice3.jpg');	
			} else if( $(this).hasClass('pootgoed') ){
				$('#image_choice').attr('src', 'images/template/choice4.jpg');	
			} else if( $(this).hasClass('biologisch') ){
				$('#image_choice').attr('src', 'images/template/choice5.jpg');	
			} else if( $(this).hasClass('tafel') ){
				$('#image_choice').attr('src', 'images/template/choice6.jpg');	
			} else if( $(this).hasClass('frites') ){
				$('#image_choice').attr('src', 'images/template/choice7.jpg');	
			}
		},function(){
			showDefault();						  
		});
	}
	
}

function showDefault() {
	$('#image_choice').attr('src', 'images/template/choice1.jpg');
}

function resetField() {
	
	$('.search_field').each(function() {
		$(this).focus(function() {
			if(this.value == this.defaultValue) {
				this.value = '';
			}
		}).blur(function() {
			if(!this.value.length) {
				this.value = this.defaultValue;
			}
		});
	});
}

function initSubmenu() {
	var sSubmenu;
	var sClass;
	
	$('.header').hover(function() {
		$('.submenu').hide();	
		if($('#menu ul li').attr('class') == 'rollover') {
			$('#menu ul li').removeClass('rollover');
		}
	});

	$('.submenu').fadeTo(0,0.9);
	if($('.submenu').is(':hidden')) {
		$('#menu ul li a').hover(function() {	
			if($(this).attr('class')) {
				$(this).parent().addClass('rollover');
				$('.submenu').hide();
				sSubmenu = $(this).attr('class');
				$('.'+sSubmenu).show();	 
			} else {
				if($(this).parent().attr('class') == 'rollover') {	
					$(this).parent().removeClass('rollover');
				}
				$('.submenu').hide();
			}
		},function() {
			sClass = $(this).attr('class');
			$('.submenu').hover(function() {
				$('.'+sClass).parent().addClass('rollover');
				$('.'+sClass).show();
			},function() {
				$('.submenu').hide();
				if($('.'+sClass).parent().attr('class') == 'rollover') {	
					$('.'+sClass).parent().removeClass('rollover');
				}
			});
			if($(this).parent().attr('class') == 'rollover') {
				$(this).parent().removeClass('rollover');
			}
		});	
	}
	
}

function initSlideshow() {
	if($('.image').length > 0) {
		$('.image').cycle({
			fx:     'fade',
			timeout: 5000,
			speed:	 1000,
			after: function(){
				sIFR.replace(sifr, {
				selector: '.image_item h5'
				,css: [
				  '.sIFR-root { font-weight: bold; font-size: 23px; color: #ffffff; }'
				],
				wmode: 'transparent'
				});
			}
		});
	}
}

