// functie tbv het submitten van het aanmelden nieuwsbrief 'formulier'
function doAanmeldenNieuwsbrief() {
	var sEmail = $('#input_nieuwsbrief').val();
	var sLocatie = $('#input_nieuwsbrief_locatie').val();
	
	if ((jQuery.trim(sEmail) != '') && (sEmail != default_emailadres)) {
		// bouw de url op
		sUrl = baseUrl + 'news/subscribe/' + sEmail + '/';
		if (jQuery.trim(sLocatie) != '') {
			sUrl = sUrl + '?newslocation=' + sLocatie;
		}
		window.location.href = sUrl;
	}
}

$(function() {
	$('#input_nieuwsbrief').each(function() {
		if (this.value == '') {
			this.value = default_emailadres;
		}

		$(this).blur(function() {
			if (this.value == '') {
				this.value = default_emailadres;
			}
		});

		$(this).focus(function() {
			if (this.value == default_emailadres) {
				this.value = '';
			}
		});
	});
	
	$('#search .text_field').each(function() {
		if (this.value == '') {
			this.value = search;
		}

		$(this).blur(function() {
			if (this.value == '') {
				this.value = search;
			}
		});

		$(this).focus(function() {
			if (this.value == search) {
				this.value = '';
			}
		});
	});

	// Bij geslecteerde ul wordt tekst groen ook bij childs, childs doorlopen en
	// tekstkleur aanpassen
	$("#submenu ul li").each(function() {
		if ($(this).hasClass('is_active')) {
			$(this).children('ul').show();
			var ul = $(this).children('ul');
			$(ul).children('li').each(function() {
				$(this).children('a').css('color', '#333333');
			});
		} else {
			$(this).children('ul').hide();
		}
	});

	// parents showen zodat menu niet dichtklapt
	$(".is_active").parents('ul').show();

	// prettyphoto:
	$("a[rel^='cm-fotoblad']").prettyPhoto( {
		animationSpeed : 'fast', /* fast/slow/normal */
		opacity : 0.80, /* Value between 0 and 1 */
		showTitle : true, /* true/false */
		allowresize : true, /* true/false */
		counter_separator_label : '/', /*
										 * The separator for the gallery counter *
										 * 1 "of" 2
										 */
		theme : 'light_square', /*
								 * light_rounded / dark_rounded / light_square / *
								 * dark_square / facebook
								 */
		hideflash : false, /*
							 * Hides all the flash object on a page, set to TRUE
							 * if flash appears over prettyPhoto
							 */
		wmode : 'opaque', /* Set the flash wmode attribute */
		autoplay : true, /* Automatically start videos: True/False */
		modal : false
	});

	$("div.shop_category").click(function() {
		$(this).find('a[href]').eq(0).each(function() {
			document.location.href = $(this).get(0).href;
		});
	});

	$("div.shop_article").click(function() {
		$(this).find('a[href]').eq(0).each(function() {
			document.location.href = $(this).get(0).href;
		});
	});

	// Bij klik dan hoeveelheid lijst openen
	$("div#article_amount input.do_button_down").click(
			function() {
				if ($('.article_amount_options').hasClass(
						'article_amount_options_visible')) {
					$("div.article_amount_options").removeClass(
							'article_amount_options_visible');
				} else {
					$("div.article_amount_options").addClass(
							'article_amount_options_visible');
				}
			});

	// Hoeveelheid van een product in textbox zetten voor de post
	$("div.article_amount_option").click(
			function() {
				$(".article_amount").val($(this).html());
				$("div.article_amount_options").removeClass(
						'article_amount_options_visible');
			});

	// Mouseover voor de tabs op product pagina
	$(".tab").bind('mouseover', function() {
		$(this).addClass('tab_mouseover');
	});

	$(".tab").bind('mouseout', function() {
		$(this).removeClass('tab_mouseover');
	});

	// Bij artikeldetail eerste tab selecteren en ook eerste tab_data tonen
	$("div.tab:first").addClass('tab_selected');
	$("div.tab_data:first").addClass('tab_data_show');

	// Bij klik andere class meegeven zodat de mouseover de class niet kan
	// verwijderen
	$(".tab").bind('click', function() {
		$(this).siblings('.tab').removeClass('tab_selected');
		$(this).addClass('tab_selected');

		$("div.tab_data").each(function() {
			$(this).removeClass('tab_data_show');
		});

		var tab_name = 'content_' + $(this).attr('id');
		$('#' + tab_name).addClass('tab_data_show');
	});

	// Wisselen van de kleine plaatjes met de grote
	$("div#article_small_images img").click(function() {
		width = (screen.width - 400) < 800 ? (screen.width - 400) : 800;
		height = (screen.height - 400) < 800 ? (screen.height - 400) : 800;

		src = $(this).attr('src').replace(/\/[0-9]+\/[0-9]+\//, '/800/800/');
		src2 = $(this).attr('src').replace(/\/[0-9]+\/[0-9]+\//, '/360/360/');

		$("#article_img_big a").attr('href', src);
		$("#article_img_big img").attr('src', src2);
	});
	
	// Filters
	$('div.filter_type').click(function() {
		if($(this).hasClass('filter_active')){
			$(this).removeClass('filter_active');
			$('div.filteroptions_'+$(this).attr('id')).hide();
		} else {
			$('div.filter_active').each(function(){
				$(this).removeClass('filter_active');
				$(this).children('.filteroptions').hide();
			});
			$(this).addClass('filter_active');
			$('div.filteroptions_'+$(this).attr('id')).show();
		}
	});

	// SEARCHTABS
	$(".search_tab").bind('mouseover', function() {
		$(this).addClass('search_tab_mouseover');
	});

	$(".search_tab").bind('mouseout', function() {
		$(this).removeClass('search_tab_mouseover');
	});

	// Bij klik andere class meegeven zodat de mouseover de class niet kan
	// verwijderen
	$(".search_tab").bind('click', function() {
		$(this).siblings('.search_tab').removeClass('search_tab_selected');
		$(this).addClass('search_tab_selected');

		$("div.search_tab_data").each(function() {
			$(this).removeClass('search_tab_data_show');
		});

		var tab_name = 'searchresult_' + $(this).attr('id');
		$('#' + tab_name).addClass('search_tab_data_show');
	});
	
	// vervangen van het 'schoppen'-symbool voor de tas
	$('#cm_content a').each(function() {
		   $(this).html($(this).html().replace(/♠/g,"<span class=\"link_shop\">&nbsp;</span>"));
	});
	
	// jQuery code voor een eenvoudige roll over. Plaats class="img_mo" op een plaaje en zorg dat de rollover dezelfde naam heeft met toevoeging _hover.
	// Dus example.jpg en example_hover.jpg of 
	// nog_een_vb.gif en nog_een_vb_hover.gif
	PEPS.rollover.init();	

});

function doPost(item){
	$(item).siblings('.article_amount').each(function() {
		$(this).attr('disabled', true);
	});
	$(item).parents('form').submit();
}

/* verberen van de popup */
function hidePopup() {
	$('#popup_window').hide(); 
	$('#popup_overlay').hide();	
	// toon het geluidsfragment als dat op de pagina voor komt
	if ($('#geluidsfragment').length == 1) {
		$('#geluidsfragment').show();
	}
}

/** 
 * Ten behoeve van de rollovers op bepaalde plaatjes
 */
PEPS = {};

PEPS.rollover = {
	init: function(){
		this.preload();
		$(".img_mo").hover(
			function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
			function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
		);
	},
	preload: function() {
		$(window).bind('load', function() {
			$('.img_mo').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
		});
	},
	newimage: function(src) {
		return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_hover' + src.match(/(\.[a-z]+)$/)[0];
	},
	oldimage: function(src) {
		return src.replace(/_hover\./, '.');
	}
};	
