/* GLOBAL */
var sitebase = "";
var telRegExp = /([0-9-]+){11}|([0-9]+){10}/; 
var timeRegExp = /^(\d{1,2}):(\d{2})$/;
var emailRegExp = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.([a-zA-Z]){2,4})$/;
var postcodeRegExp = /^([0-9]){4}([a-zA-Z]){2}$/;

/* FUNCTIONS */
	
function goto(url) {
	window.location = url;
}

function confirm_goto(question, url) {
	var cbox = confirm(question);
	if(cbox == true) {
		window.location = url;
	}
}

function change_size(variant_id, size, old_price, price, stock){
	
	old_price_int = old_price.replace('.', '');
	old_price_int = old_price_int.replace(',', '.');
	price_int = price.replace('.', '');
	price_int = price_int.replace(',', '.');
	
	$('.sizes a').removeClass('active');
	$('#size_'+variant_id).addClass('active');
	
	$('#variant_id').val(variant_id);
	$('#selected_size').html(size);
	
	if(parseFloat(price_int) < parseFloat(old_price_int)){
		$('#old_price_sum').html(old_price);
		$('.old_price').show();
		$('.current_price').addClass('action');
	} else {
		$('.current_price').removeClass('action');
		$('.old_price').hide();
	}	

	$('#price_sum').html(price);
	
	var options = '';
	for(s=1; s<=stock; s++){
		options += '<option value="'+s+'">'+s+'</option>\n';
	}
	
	$('#amount').html(options);
	
	Cufon.refresh();
}


/* JQUERY */
$(document).ready(function(){	
	if($(".slider ul").length > 0){
		$(".slider").easySlider({	
			auto: 			true, 
			continuous: 	true,
			numeric:		false,
			pause:			4000,
			speed:			300,
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next'
		});
	}
	
	$('.product').hover(function(){
		position = $(this).position();
		$(this).find('.sizes').show();
	}, function(){
		$(this).find('.sizes').hide();
	});
	
	$('#more_info_tabs').tabs({
		onShow: function() {
			alert('moi');
		}
	});
	$(function() {
		/* Initialize Tabs */
		$("#more_info_tabs").tabs("#more_info_tabs > div", { effect: 'fade' });
			$("#more_info_tabs a").click(function(){
			Cufon.refresh();
		});
	}); 
	$('#more_info_tabs').bind('tabsshow', function() {
		Cufon.refresh('.ui-tabs .ui-tabs-nav li a');
	});
	
	if($("#contact_form").length > 0){
		$("#contact_form").validate({			
			errorContainer: '#error_container',
			errorLabelContainer: $("ul", '#error_container'),
			wrapper: 'li',
			meta: "validate"
		});
	}
	
	$('.slider_holder').nivoSlider({
		effect: 'random',                
		pauseTime:5000,
		pauseOnHover:false,
		controlNavThumbs:true,
		controlNavThumbsSearch: '_image.jpg',
		controlNavThumbsReplace: '_thumb.jpg',
		directionNav:true,
		directionNavHide: false,
		pauseOnHover:true
	});
	/*$('#product_slider_holder').nivoSlider({
		effect: 'random',                
		pauseTime:5000,
		pauseOnHover:false,
		controlNavThumbs:true,
		controlNavThumbsFromRel:true,
		directionNav:true,
		directionNavHide: false,
		pauseOnHover:true,
		manualAdvance:true
	});*/
	
	$('#newsletter_submit').click(function(){
		submit_newsletter();
	});	
	$('#newsletter_email').keyup(function(e) {
		if(e.keyCode == 13) {
			submit_newsletter();
		}
	});
	$('#newsletter_email').click(function(){
		if($(this).val() == 'voorbeeld@buzzy-bee.nl'){
			$(this).val('').addClass('active');
		}
	});
	
	/*$('#product_slider_holder .nivo-imageLink').jqzoom({  
            zoomType: 'standard',  
            lens:true,  
            preloadImages: true,  
            alwaysOn:false,  
            zoomWidth: 300,  
            zoomHeight: 250,  
            xOffset:90,  
            yOffset:30,  
            position:'left'  
            //...MORE OPTIONS  
    });*/
	
	//$("#product_slider_holder .nivo-imageLink").attr('rel', 'group');
	//$("#product_slider_holder .nivo-imageLink").fancybox();
	
	/*$('.zoom_image').jqzoom({  
            zoomType: 'standard',  
            lens:true,  
            alwaysOn:false,  
            zoomWidth: 298,  
            zoomHeight: 250,  
            xOffset:10,  
            yOffset:0,  
            position:'right',
			preloadText: 'Zoom laden...'
    });*/
	
	$('.cloud-zoom-gallery.thumb').click(function(){
		$('.cloud-zoom-gallery.thumb').removeClass('active');
		$(this).addClass('active');
	});
	
});

function submit_newsletter(){
	if($('#newsletter_email').val() == '' || $('#newsletter_email').val() == 'Vul hier uw e-mail adres in'){
		alert('U heeft geen e-mail adres ingevuld.');
	} else if(!emailRegExp.test($('#newsletter_email').val())){
		alert('U heeft geen geldig e-mail adres ingevuld.');
	} else {
		$.ajax({
			url: ajax_rel_path+'newsletter_action.php',
			type: 'POST',
			data: ({ groupid: $('#newsletter_groupid').val(), email: $('#newsletter_email').val() }),
			success: function(){
				$('#newsletter_email').val('');
				alert('U bent succesvol aangemeld voor onze nieuwsbrief!');
			}
		});
	}
}

/* CUFON */
// example
// Cufon.replace('h1',{ fontFamily: 'Helvetica Neue LT Pro', hover: true});
Cufon.replace('h1, h2, h3',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#newsletter_submit',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#shop_nav li a',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#top_tiles > a span',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#bottom_slider .slider li > a span',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#crumbpath',{ fontFamily: 'Arial', hover: true});
Cufon.replace('.submenu a',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('.overview a span',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('#product_order .price .current_price, #product_order .price .old_price, #more_info #more_info_tabs > ul li, #related_products a span.title, #related_products a span.price',{ fontFamily: 'Akzidenz-Grotesk BQ', hover: true});
Cufon.replace('.product span.title, .product span.sub_title, .product span.oldprice, .product span.price',{ fontFamily: 'Arial', hover: true});
