
/*** Cufon *****/
Cufon.replace('.header .members-area .login-form .title');
Cufon.replace('.contactus-title');
Cufon.replace('.header .phone');
Cufon.replace('.welcome-heading .text h1');
Cufon.replace('.welcome-heading .text p');
Cufon.replace('.page-title');
Cufon.replace('.short-news h2');
Cufon.replace('.category-heading .text h1');
Cufon.replace('.heading .text h1');
Cufon.replace('.heading .text .introtext');
Cufon.replace('.category-heading .text .desc');
Cufon.replace('.subcategories .subcategory h2');

$(document).ready(function() {
	/** Left category navigation **/
	$('.block-catlist ul li.active').parents('li').addClass('active-child');
	$('.block-catlist ul li.active:not(.active-child)').addClass('selected');

	/** add to cart button ***/
	$('.add2cart-btn, .wishlist-right .btn-update').click(function() {
		$('#'+$(this).attr('rel')).submit();
		return false;
	});

	/** Product color ***/
//	$('.product-color-btn').click(function() {
//		var color_i = $(this).attr('rel');
//		var image = product_data[color_i]['image'];
//		$('.product-view img.image').attr('src', image);
//		$('#productAddToCartForm input[name=color]').val(color_i);
//		$('#productAddToCartForm .sku span').html(product_data[color_i]['sku']);
//		$('#productAddToCartForm .color span').html(product_data[color_i]['color']);
//		return false;
//	});

	$('.print-page').click(function() {
		window.print();
		return false;
	});

	$('.qty').keyup(function() {

		var q = $(this).val().replace(/[^\d]/, '');
		$(this).val(q);
	}).blur(function(){
		var q = $(this).val().replace(/[^\d]/, '');
		if(!(q>0)) $(this).val(1);
	});

	$('.subcategories .subcategory').mouseenter(function() {
		$(this).find('img.splash').show();
	});
	$('.subcategories .subcategory').mouseleave(function() {
		$(this).find('img.splash').hide();
	});
	$('.subcategories .subcategory').click(function() {
		window.location.href = $(this).find('a').attr('href');
		return false;
	});

	/** Register Form ***/
	$('#o_same').change(function() {
		if ($(this).attr('checked')) {
			$('#o-address-fields input.text').each(function(){
				var val = $($(this).attr('id').replace('o_', '#a_')).val();
				$(this).disable().val(val);
			});
		} else {
			$('#o-address-fields input.text:disabled').enable().val('');
		}
	});

	$('#a-address-fields input.text').keyup(function() {
		if ($('#o_same').attr('checked')) {
			$($(this).attr('id').replace('a_', '#o_')).val($(this).val());
		}
	});

	$('#ts_limited').change(function() {
		var $inputs = $('#sole-trader-fields input.text');
		if ($(this).attr('checked')) {
			$inputs.disable();
		} else {
			$inputs.enable();
		}
	});
	$('#register-form input[name=submit]').disable();
	$('#terms_agree').change(function() {
		if ($(this).attr('checked')) {
			$('#register-form input[name=submit]').enable();
		} else {
			$('#register-form input[name=submit]').disable();
		}
	});
	$('#o_same,#ts_limited,#terms_agree').change(); //Firefox autocomplete

	//$('#q').autotip({text:'code/name'});
	$('#mini-login').autotip({text:'Login'});
	$('#mini-password').autotip({text:'Password'});
	
	if($('.wlpeMessage').size()>0){
		var copy=$('.wlpeMessage .wlpeMessageText').html().replace(/<br\s?\/?>/gi,'\n');
		$('.wlpeMessage').remove();
		alert(copy);
		
	}
	
});


$.fn.disable = function(){
	return $(this).attr('disabled', 'disabled').addClass('disabled');
};

$.fn.enable = function(){
	return $(this).removeAttr('disabled').removeClass('disabled');
};
