$(document).ready(function() {
	accordionsubmenu();
	
	$("#FilterAddForm select").change(function(){
		$(this).parent().parent().submit();
	});
	
	//admin products images
	$('.new_image').mouseover(function(){
		$(this).fadeTo(400,0.9);
	}).mouseout(function(){
		$(this).fadeTo(400,0.0);
	});
	
	//admin products images
	$('.new_image').click(function(){
		if($('input[name="data[Image][place]"]').attr('value')!=$(this).attr('name')){
			if($('input[name="data[Image][place]"]').attr('value')!=''){
				//$('div [style="1px #e80979 solid"]').css('border','1px #000 solid');
				$('img[name="'+$('input[name="data[Image][place]"]').attr('value')+'"]').parent().css('border','1px #b7b9bb solid');
				$('input[name="data[Image][place]"]').attr('value','');
				$('#placenumber').html('');
				$('#admin_products #upload_form').slideToggle(100);
			}
			$('input[name="data[Image][place]"]').attr('value',$(this).attr('name'));
			$('#placenumber').html('[Plaats '+$(this).attr('name')+']');
			$('#admin_products #upload_form').slideToggle(400);
			$(this).parent().css('border','1px #e10218 solid');
		}
	});
	
	$('#action').click(function(){
		//alert($(this).attr('name'));
		window.location = $(this).attr('name');
	});
	
	
	//product images
	$('.photo a[href*=img], #thumbs .thumb a[href*=img]').lightBox({
		imageLoading: webroot+'img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: webroot+'img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev : webroot+'img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext : webroot+'img/lightbox/lightbox-btn-next.gif',
		imageBlank : webroot+'img/lightbox/lightbox-blank.gif',
		txtImage : 'Afbeelding',
		txtOf : 'van',
		containerResizeSpeed: 300
	});
	
	$("#ProductFilterForm select").change(function(){			
		filterProducts($("#ProductFilterForm select").serialize());
	});
	
	homeStartSlider(true);
	
	$.each({name:'Naam', address:'Adres',email:'E-mailadres', postalcode:'Postcode',phone:'Telefoonnummer', city:'Plaats', productnumber:'Artikelnummer/Omschrijving'}, function(index, value) {
		$("form#Samplerequestform input[rel=" + index + "]").click(function() {
			if ($(this).attr('value') == value){
				$(this).attr('value', '');
			}
			$(this).blur(function() {
				if ($(this).attr('value') == '') {
					$(this).attr('value', value);
				}
			});
		});
	});
	
	$('.front_product_category').click(function(){
		homeFadeOut();
		$("#front_category_hover").stopTime("slidechoice");
		newmargin = ($(this).attr('name')*margin_increments)+margin_default;
		active_highlight = $(this).attr('name');
		$("#front_category_hover").animate({
			marginLeft:newmargin+'px',
			queue:false
		},animation_duration,'easeOutBack',function(){ homeClickCallback(); } );
	});
	
	//clear the filters when clicking a main menu item
	$('ul#submenu li a[name=\'submenu_mainbutton\']').click(function(){
		$.ajax({
			type: "POST",
			url: webroot+'products/clearfilters',
			data: '',
			error: function(msg){
			},
			success: function(msg){
			}
		});
	});
	
	/*
	$('#submenu li a[name=\'submenu_mainbutton\']').click(function(){
		//alert($(this).attr('rel'));
		window.location = webroot+'products/index/'+$(this).attr('rel');
		//alert(webroot+'products/index/'+$(this).attr('rel'));
		//alert('test');
	});
	*/
	
	if($('#image_cycle').length){
		$('#image_cycle').cycle({
			fx: 'fade',
			timeout:5000
		});
	}
	
	$('#SearchKeyword').click(function(){
		if($(this).attr('value')=='Zoek op product of trefwoord'){
			$(this).attr('value','');
		}
		
		$(this).blur(function() {
			if($(this).attr('value') == ''){
				$(this).attr('value','Zoek op product of trefwoord');
			}
		});
	});
	
})
