///////////////////////////////////////////////////////
/// change voucher quantity ///
///////////////////////////////////////////////////////	
	// didnt use live as it does not currently suport blur as an event
	function changeVoucherQty(name,price,prevQty, newQty){
		if (newQty!=prevQty){
			$.post('http://'+window.location.hostname+'/en/index/plug-contentvouchersBasket', { changeQty:'yes', name: name, price: price,  qty:newQty},
			function(data){
				$('.BASKETjs').empty().append('<h2 class="title"><span>Your Basket</span></h2>').html(data);
			});
		}
		return false;
	};

///////////////////////////////////////////////////////
$(function() {
///////////////////////////////////////////////////////
/// add to basket ///
///////////////////////////////////////////////////////
	$('.add-to-basket').live('click', function() {
		var form = $(this).parent().parent().attr('class');
		if($("."+form+" #voucherPriceJS").val().replace(/[^0-9.]/g,'')=="" || $("."+form+" #voucherQtyJS").val().replace(/[^0-9]/g,'')==''){
			alert('please enter a voucher price and / or quantity');
		} else {
			$.post('http://'+window.location.hostname+'/en/index/plug-contentvouchersBasket', { name: $("."+form+" #voucherNameJS").val(), price: $("."+form+" #voucherPriceJS").val().replace(/[^0-9.]/g,''), qty: $("."+form+" #voucherQtyJS").val().replace(/[^0-9]/g,'') },
			function(data){
				//alert("Voucher Added");
				$('.BASKETjs').empty().html(data);
				if(form == "block-wrapper"){
					$('.BASKETjs').show();
				} else {
					$('body').append('<div id="loading"></div><div id="ajax"></div>');
					$('#ajax').fadeIn().load('http://'+window.location.hostname+'/en/index/plug-vouchersBasket', function(){ $('#ajax .plugin h2.title span').append('<a href="#" class="ajax-close">x</a>'), $('#loading').remove(), function(data){ $('.BASKETjs').empty().html(data) } } );
					//document.location = "http://"+window.location.hostname+"/en/basket"	
				}
			});
		}
		return false;
	});
///////////////////////////////////////////////////////
/// remove voucher ///
///////////////////////////////////////////////////////	
	$('.remove-voucher').live('click', function() {
		$.post('http://'+window.location.hostname+'/en/index/plug-contentvouchersBasket', { remove: $(this).attr('name')},
		function(data){
			//alert("Voucher removed");
			$('.BASKETjs').empty().html(data);
		});
		return false;
	});	
///////////////////////////////////////////////////////
/// empty basket ///
///////////////////////////////////////////////////////	
	$('.empty-basket').live('click', function() {
		$.post('http://'+window.location.hostname+'/en/index/plug-contentvouchersBasket', { empty: '1' },
		function(data){
			//alert("Voucher Added");
			$('.BASKETjs').empty().html(data);
		});
		return false;
	});									
///////////////////////////////////////////////////////
/// buy a balloon ///
///////////////////////////////////////////////////////
	// this opens the balloon section
	$('#choose-a-balloon').hide(0);
	$('.buy-with-balloon').click(function(){
		var
		href=$(this).attr('rel');
		$('#choose-a-balloon').fadeIn('slow').load(href);
		return false;
	});
	// this closes the balloon section
	$('.#choose-a-balloon .close').live('click',function() {
		$('#choose-a-balloon').hide();
		return false;
	 });
	// this opens the category menus
	$('#balloons li ul').hide(0);
	$('#balloons li a.category').live('click', function(){
		var
		el = this,
		node = $(this).next();
		
		$('#balloons li ul').each(function(){
			if( $(this).is(':visible') && $(this).get(0) != $(node).get(0) )
				$(this).hide();
		});
		if($(node).is(':hidden')){
			$(node).show(0);
			$(el).addClass('expanded');
		} else {
			$(node).hide(0);
			$(el).removeClass('expanded');
		}
		return false;
	});
	// this loads the category images
	$('#balloons li a').live('mouseover',function() {
		var
		rel=$(this).attr('rel');
		$('#balloon').empty().append('<img src="/img/balloons/'+rel+'.jpg" alt="" title="" />');
		return false;
	});
	// this loads the balloon images
	$('#balloons li ul li a').live('mouseover',function() {
		var
		rel=$(this).attr('rel');
		$('#balloon').empty().append('<img src="/img/balloons/'+rel+'.jpg" alt="" title="" />');
		return false;
	})
	// this loads the balloon details
	$('#balloons li ul li a').live('click',function() {
		var
		href=$(this).attr('href');
		$('#balloon-details').empty().load(href).show();
		return false;
	});
	// this closes the balloon details
	$('#balloon-details a.closethis').live('click',function() {
		var
		href=$(this).attr('href');
		$('#balloon-details').hide();
		return false;
	});
///////////////////////////////////////////////////////
});