var deleteItem=0;
	$(document).ready(function(){
		$('#cartbuttons #removeitem').click(function(){
			if (deleteItem==0){
				$('#cartbuttons #removeitem').html('X CLICK ITEM');
				$('#cartbuttons #removeitem').css({'border':'1px solid red'});
				$('.carttable .content').css({'cursor':'not-allowed'});
				deleteItem=1;
			}
			return false;
		});
		$(document).click(function(){
			if (deleteItem==1){
				$('#cartbuttons #removeitem').css({'border':'1px solid black'});
				$('#cartbuttons #removeitem').html('X REMOVE ITEM');
				$('.carttable .content').css({'cursor':'default'});
				deleteItem=0;
			}
		});
		$('.carttable .content').click(function(){
			if (deleteItem==1){
				$.ajax({
					type: "POST",
					url: "/include/cart/deleteItem.php",
					data: "cartId="+$(this).attr('rel'),
					success: function(msg){
						location.reload(true);
					}
				});
			}
		});
		
		$('.submitcontact').click(function(){
			if($('#msg').val()=='' || $('#email').val()=='')$('.errormessages').fadeIn('fast');
			else $('#contactpageform').submit();
		});
		
		$('.poplink').popupWindow({ 
			height:1000, 
			width:700, 
			top:50, 
			left:50,
			scrollbars:1
		}); 
		$('.poplink2').popupWindow({ 
			height:500, 
			width:700, 
			top:50, 
			left:50,
			scrollbars:1
		}); 

		$('#fancybox').fancybox({
            overlayShow: true,
            frameWidth:640,
            frameHeight:360
        });
		if ($('#login').length>0){
			$('input[title]').each(function(){
				$(this).val($(this).attr('title'));
			});
			$('#username').focus(function(){
				if($(this).val() == $(this).attr('title')){
					$(this).val('');
				}
			});
			$('#username').blur(function() {
				if($(this).val() == '') {
					$(this).addClass('hinting').val($(this).attr('title'));
					$(this).one('focus', function() {
						$(this).removeClass('hinting').val('');
					});
				}
			}).trigger('blur');
			$('#password').one('focus',function(){
		  		var newPass = $(this).clone();
		  		newPass.attr('type','password');
		  		newPass.attr('id','npassword');
		  		newPass.val('');
		  		newPass.insertBefore($(this));
		  		$(this).remove();
		  		newPass.attr('id','password');
		  		newPass.focus();
		  	});
			$('.slideButton').click(function(){
				if ($('#radio2:checked').val()){
					$('#registernew').slideDown('def');
				} else {
					$('#registernew').slideUp('def');
				}
			});
			$('.collectionsLink').click(function(){
				//$('.col').slideDown();
				//return false;
			});
			$('#submit').click(function(){
				if ($('#email').val() == '')$('.errormessages').fadeIn('def');
				else if ($('#msg').val() == '') $('.errormessages').fadeIn('def');
				else $('#contactForm').submit();
			});
			$('#loginuser').click(function(){
				$('.errorMsg').fadeOut('fast');
				var go = 1;
				if ($('#username').value == ''){
					go = 0;
					$('#logemailErr').fadeIn('def');
				}
				if ($('#username').val() == 'Your email address'){
					go = 0;
					$('#logemailErr').fadeIn('def');
				}
				if ($('#password').val() == ''){
					go = 0;
					$('#logpassErr').fadeIn('def');
				}
				if ($('#password').val() == 'Your password'){
					go = 0;
					$('#logpassErr').fadeIn('def');
				} 
				if (go == 1) $('#login-form').submit();
			});
			$('#newreg').click(function(){
				$('.errorMsg').fadeOut('fast');
				var go = 1;
				if ($('#newfirstname').val() == ''){
					go = 0;
					$('#firstnameErr').fadeIn('def');
				}
				if ($('#newlastname').val() == ''){
					go = 0;
					$('#lastnameErr').fadeIn('def');
				}
				if ($('#newphone').val() == ''){
					go = 0;
					$('#phoneErr').fadeIn('def');
				}
				if ($('#newemail').val() == ''){
					go = 0;
					$('#emailErr').fadeIn('def');
				}
				if ($('#newcity').val() == ''){
					go = 0;
					$('#cityErr').fadeIn('def');
				}
				if ($('#newcountry').val() == ''){
					go = 0;
					$('#Err').fadeIn('def');
				}
				if ($('#newpost_code').val() == ''){
					go = 0;
					$('#post_codeErr').fadeIn('def');
				}
				if ($('#newpassword').val() == ''){
					go = 0;
					$('#passwordErr').fadeIn('def');
				}
				if ($('#newcpassword').val() == ''){
					go = 0;
					$('#cpasswordErr').fadeIn('def');
				}
				if ($('#newpassword').val() != $('#newcpassword').val()){
					go = 0;
					$('#cpasswordmatchErr').fadeIn('def');
				}
				alert(go);
				if (go == 1) $('#signup-form').submit();
			});
		}
	});