function initShop()
{
	initBuyForms();
	initAsyncBasket();
	initAlert();
	initQuestion();
	initListBuyForm();
	//initCheckout();
	if($('miniSearchForm'))initFormFields("miniSearchForm");
	if($('newsletterForm'))initFormFields('newsletterForm');
}

function initQuestion(){
	shop.questionBox = $('questionBox');
	shop.questionBox.transition = new Fx.Tween( shop.questionBox , 'opacity', {duration:700, wait:true , transition:new Fx.Transition(Fx.Transitions.linear) } );
	
	shop.cuteQuestion = new cuteQuestion();
}

function initAlert()//init vertical movement, transition... of the minibasket
{
	shop.alertDiv = $('alertFloater');
	//shop.basketDiv.movement = new Fx.Tween( shop.basketDiv , 'top', {duration:20, transition:new Fx.Transition(Fx.Transitions.linear) } );
	shop.alertDiv.style.top = '180px';
	
	/*window.addEvent('scroll', function()
										{
												shop.alertDiv.style.top = 180 + document.documentElement.scrollTop + 'px';
												//shop.basketDiv.movement.start('top', parseInt(shop.basketDiv.style.top), 180 + document.documentElement.scrollTop );
										}
	);*/
	
	shop.alertBox = $('alertBox');
	shop.alertBox.transition = new Fx.Tween( shop.alertBox , 'opacity', {duration:700, wait:true , transition:new Fx.Transition(Fx.Transitions.linear) } );
	
	shop.cuteAlert = new cuteAlert();
}


var basketTime;
var basketDisplay;

function initAsyncBasket()//init vertical movement, transition... of the minibasket
{
	shop.asyncBasketBox = $('asyncBasketBox');
	shop.asyncBasketBox.transition = new Fx.Tween( shop.asyncBasketBox , 'opacity', {duration:700, transition:new Fx.Transition(Fx.Transitions.linear) } );
	basketDisplay = "none";
}

function showMiniBasket(){
	if(basketDisplay == "none"){
		basketDisplay = "";
		clearTimeout(basketTime);
		shop.asyncBasketBox.transition.start('opacity',0,100);
		shop.asyncBasketBox.style.display = '';
		/*setTimeout("shop.asyncBasketBox.transition.start('opacity',100,0);", 4000);
		setTimeout("shop.asyncBasketBox.style.display = 'none';", 4700);*/
		basketTime = setTimeout("hideAsyncBasketInShow()", 4000);
	}
}

function hideAsyncBasketInShow()
{
	if(basketDisplay == ""){
		basketDisplay = "none";
		shop.asyncBasketBox.transition.start('opacity',1,0);
	}
}


function hideAsyncBasket()
{
	if(basketDisplay == ""){
		basketDisplay = "none";
		clearTimeout(basketTime);
		shop.asyncBasketBox.transition.start('opacity',1,0);
	}
}

$(window).addEvent('click', function(){ hideAsyncBasket(); } );

function initBuyForms()
{
	$$('.buyForm').each(
	function(form)
	{
		getStockByCombination(form);
		form.addEvent('submit', function()
			{
				//overwrite form action
				this.action = shop.url + '/ajaxTemplates/products/addProduct.cfm';
				if( Spry.Widget.Form.validate(this) )
				{
					return Spry.Utils.submitForm(this, validateAddProduct);
				}
			}
		);
	}
	);
}

function initListBuyForm()
{
	if($('listProductBuyForm')) {	
		var form = $('listProductBuyForm')
		form.addEvent('submit', function()
			{
				//overwrite form action
				this.action = shop.url + '/ajaxTemplates/products/addProducts.cfm';
				if( Spry.Widget.Form.validate(this) )
				{
					return Spry.Utils.submitForm(this, validateAddProduct);
				}
			}
		);
		//initFormFields("listProductBuyForm");
	}
}

function listChangeValue(id, totalItems, position)
{
	var quantity = parseInt($('quantity'+id).value);
	if (isNaN(quantity)) { quantity = 0; }
	var itemPrice = parseFloat($('price'+id).value);
	basePrice = itemPrice * quantity;
	basePrice = Math.round(basePrice*100)/100 ;
	basePrice = basePrice + ' &euro;'
	if($('priceBox'+position))$('priceBox'+position).innerHTML = basePrice;
	var totalPrice = 0;
	for(var i=1; i<=totalItems; i++){
		if($('priceBox'+i)) var basePrice = document.getElementById('priceBox'+i).innerHTML;
		if(isNaN(parseFloat(basePrice))) basePrice = 0;
		totalPrice = totalPrice + parseFloat(basePrice);
	}
	totalPrice = Math.round(totalPrice*100)/100 ;
	totalPrice = totalPrice + ' &euro;';
	document.getElementById('totalPriceBox').innerHTML = totalPrice;
}
