var collections_drawer = false;
var hidden = true;
var view_basket_width = 0;
var shipping_hidden = true;

jQuery.fn.clearValue = function() {
	return this.focus(function() {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	}).blur(function() {
		if (this.value.length == 0) {
			this.value = this.defaultValue;
		}
	});
}

function divSlide(element) {
	
	var list = document.getElementById(element);
	
	if(list.style.display == "none") {
		$(list).slideDown('slow');
	}
	else {
		$(list).slideUp('slow');
	}	
	
	collections_drawer = !collections_drawer;
}

$(document).ready(function () {
	
	$('#collections_drawer').hide();
	$('#jewellery_drawer').hide();
	
	//var basket = document.getElementById("basket");
	//var list = document.getElementById("basket_items");
	
	//var width = ((list.offsetWidth)*-1);
	//basket.style.right = "" + width + "px";
	
	$("#start_date").hide();
	$("#shipping_address_form").hide();
	
	$("#nav_search").clearValue();

});



function listSlide() {

	var list = document.getElementById("basket_items");
	var width = ((list.offsetWidth)*-1);
	

		if(!hidden) {
			
			$("#basket").animate({right: width}, {queue:false, duration:200});
			
			hidden = !hidden;
		}
		else {
			
			$("#basket").animate({right: "0px"}, {queue:false, duration:200});
			
			hidden = !hidden;
		}
}


function cardTypeChoice(element) {
	var selected = element.selectedIndex;
	
	if (selected == 3) {
		$("#start_date").show();
	}
	else {
		$("#start_date").hide();
	}
}


function shippingAddress() {
	if(shipping_hidden) {
		$("#shipping_address_form").show();
	}
	else {
		$("#shipping_address_form").hide();
	}
	
	shipping_hidden = !shipping_hidden;
}


function delete_item(product_id) {
	
	if(confirm("Delete this item?")) {
		var input = document.getElementById('delete_product');
		input.value = product_id;
		document.name.submit();
	}
}

function wopen(url, name, w, h) {

	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=yes, resizable=no');
 
	win.resizeTo(w, h);
	win.focus();
}
