/* REGULAR EXPRESSIONS */
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 switch_product_img(product, img_nr){

	if(img_nr == 'prev'){
	
		var total_images = $('#product_img_'+product+' img').length;
		var active_img = $('#product_img_'+product+' img.visible').attr('id');
		active_img = active_img.replace('product_img_'+product+'_', '');
		new_image = parseInt(active_img) - 1;
		
		$('#product_img_'+product+' img').removeClass('visible');
		$('#img_controls_'+product+' a').removeClass('current');
		if(active_img == 1){
			$('#product_img_'+product+'_'+total_images).addClass('visible');
			$('#img_controls_'+product+'_'+total_images).addClass('current');
		} else {
			$('#product_img_'+product+'_'+new_image).addClass('visible');
			$('#img_controls_'+product+'_'+new_image).addClass('current');
		}
	
	} else if(img_nr == 'next'){
	
		var total_images = $('#product_img_'+product+' img').length;
		var active_img = $('#product_img_'+product+' img.visible').attr('id');
		active_img = active_img.replace('product_img_'+product+'_', '');
		new_image = parseInt(active_img) + 1;
		
		$('#product_img_'+product+' img').removeClass('visible');
		$('#img_controls_'+product+' a').removeClass('current');
		if(active_img == total_images){
			$('#product_img_'+product+'_1').addClass('visible');
			$('#img_controls_'+product+'_1').addClass('current');
		} else {
			$('#product_img_'+product+'_'+new_image).addClass('visible');
			$('#img_controls_'+product+'_'+new_image).addClass('current');
		}
	
	} else {

		$('#product_img_'+product+' img').removeClass('visible');
		$('#product_img_'+product+'_'+img_nr).addClass('visible');
		$('#img_controls_'+product+' a').removeClass('current');
		$('#img_controls_'+product+'_'+img_nr).addClass('current');
		
	}
	
}

function switch_cms_img(item_id, img_nr){

	if(img_nr == 'prev'){
	
		var total_images = $('#cms_img_'+item_id+' img').length;
		var active_img = $('#cms_img_'+item_id+' img.visible').attr('id');
		active_img = active_img.replace('cms_img_'+item_id+'_', '');
		new_image = parseInt(active_img) - 1;
		
		$('#cms_img_'+item_id+' img').removeClass('visible');
		$('#img_controls_'+item_id+' a').removeClass('current');
		if(active_img == 1){
			$('#cms_img_'+item_id+'_'+total_images).addClass('visible');
			$('#img_controls_'+item_id+'_'+total_images).addClass('current');
		} else {
			$('#cms_img_'+item_id+'_'+new_image).addClass('visible');
			$('#img_controls_'+item_id+'_'+new_image).addClass('current');
		}
	
	} else if(img_nr == 'next'){
	
		var total_images = $('#cms_img_'+item_id+' img').length;
		var active_img = $('#cms_img_'+item_id+' img.visible').attr('id');
		active_img = active_img.replace('cms_img_'+item_id+'_', '');
		new_image = parseInt(active_img) + 1;
		
		$('#cms_img_'+item_id+' img').removeClass('visible');
		$('#img_controls_'+item_id+' a').removeClass('current');
		if(active_img == total_images){
			$('#cms_img_'+item_id+'_1').addClass('visible');
			$('#img_controls_'+item_id+'_1').addClass('current');
		} else {
			$('#cms_img_'+item_id+'_'+new_image).addClass('visible');
			$('#img_controls_'+item_id+'_'+new_image).addClass('current');
		}
	
	} else {
	
		$('#cms_img_'+item_id+' img').removeClass('visible');
		$('#cms_img_'+item_id+'_'+img_nr).addClass('visible');
		$('#img_controls_'+item_id+' a').removeClass('current');
		$('#img_controls_'+item_id+'_'+img_nr).addClass('current');
		
	}
	
}

$(document).ready(function(){

	/*$('#email_subscribe').click(function(){
		
		var error = '';
		if($('#email_subscribe_email').val() == '' || $('#email_subscribe_email').val() == 'email'){
			error = 'You have no e-mail address entered';
		} else if(!emailRegExp.test($('#email_subscribe_email').val())){
			error = 'You have not entered a valid e-mail address';
		}

		if(error != ''){
			alert(error);
		} else {
			$('#email_subscribe_form').submit();
		}

		return false;
	});

	$("#product_images").easySlider({
		speed: 0,
		numeric: true,
		continuous: true,
		controlsBefore: '<span>Aditional views - </span>'
	});
*/
	$('.focus').each(function(){
		var value = $(this).attr("value")
		
		//focus on input
		$(this).focus(function() {
			if($(this).val() == value){
				$(this).val('');
				$(this).removeClass('focus');
			}
			$(this).addClass('active');
		});
		
		//focus lost on input
		$(this).blur(function() {
			if($(this).val() == value) {
				$(this).val(value);
				$(this).removeClass('active');
			}
		});
	});
	
	
	$('.password').each(function() {
		var pass = $(this);
		var id = $(this).attr('id');
		var div = pass.wrap('<div/>').parent();
		if(id == 'password'){
			var defvalue = 'password';		
		} else if(id == 'repass'){
			var defvalue = 're-enter password';
		} else {
			var defvalue = '';
		}
		var label = $('<label/>').attr('for', pass.attr('id')).text(defvalue).prependTo(div);
		
		div.css({
			display: 'inline',
			position: 'relative',
			float: 'left'
		});
		
		label.css({
			color: '#fff',
			fontSize: '11px',
			position: 'absolute',
			left: '3px',
			bottom: '1px',
			fontFamily: 'georgia,garamond,serif'
		});
		
		pass.focus(function() {
			label.hide();
			pass.addClass('active');
		}).blur(function() {
			if(pass.val() == '') {
				label.show();
				pass.removeClass('active');
			}
		});
	});
});

/* Cufon */
Cufon.replace('h1.title', { fontFamily: 'TradeGothic' });
Cufon.replace('#menu li a', { fontFamily: 'TradeGothic' });
Cufon.replace('#shop_menu li a', { fontFamily: 'TradeGothic' });
