function manageShipCosts(){
	
	var toggleShipCost = $$('.shipcost');
	toggleShipCost.removeEvents('click');
	var shipInfo = $$('.shipinfo');
//	/shipInfo.show();
	toggleShipCost.each(function( el, index){
		//shipInfo[index].hide();
		
		el.addEvent('click',function(e){
			e = new Event(e);
			e.preventDefault();
			//console.log(shipInfo[index]);
			
			//shipInfo[index].toggle();
			//console.log(shipInfo[index]);
			/**/
			if(!$defined(shipInfo[index].smoothfx))
				shipInfo[index].smoothfx = new Fx.Reveal(shipInfo[index],{display : 'inline-block'});
				shipInfo[index].smoothfx.toggle();
		})
	})
}				

var CartManager = new Class({
	
	
	Implements: [Options],

	//options
	container : 'car',
	snippet : '',
	emptyContainer : '',
	url : '/be/main.php',
	options: {
		label: {
			addItem : 'Aggiungi',
			removeItem : 'Elimina',
			totalPrice : 'Prezzo totale',
			roar:null
		}
	},
	
	//initialization
	initialize: function(container,remoteUrl,itemSnippet,itemSnippet2,options) {
		//set options
		this.setOptions(options);
		this.container = $(container);
		this.url = remoteUrl;
		this.snippet = itemSnippet;
		this.snippetMulti = itemSnippet2;
		this.emptyContainer = this.container.get('html');
		this.buildCart();
	},
	
	showEmptyCart : function(){
		this.container.addClass('off');
		this.container.removeClass('on');
		this.container.getPrevious().addClass('off');
		this.container.getPrevious().removeClass('on');
		this.container.getNext().addClass('off');
		this.container.getNext().removeClass('on');
		this.container.set('html',this.emptyContainer);
	},
	hideEmptyCart : function(){
		this.container.empty();
		this.container.removeClass('off');
		this.container.addClass('on');
		this.container.getPrevious().removeClass('off');
		this.container.getPrevious().addClass('on');
		this.container.getNext().removeClass('off');
		this.container.getNext().addClass('on');
	},
	
	//a method that does whatever you want
	buildCart: function() {
		var jsonRequest = new Request.JSON({
			url: this.url, 
			onSuccess: this.afterBuildCart.bind(this)
		}).get({'page': 'cart.getItemInfoHTML'});
	},
	afterBuildCart : function(resp){
		
		if(resp.items.length > 0){
			if(this.container.hasClass('off')){
				this.hideEmptyCart();
			}
			resp.items.each(function(el){
				if($type(el.thumb) == 'array'){//multiitem ha piœ immagini, dal json chiappo direttamente il tag img
					elem = Elements.from(this.snippetMulti.substitute(el));
					
				}else{//item semplice, mi passo solo l'url dell'immagine
					elem = Elements.from(this.snippet.substitute(el));
					
				}
				elem[0].inject(this.container,'bottom');
			}.bind(this));
		
			this.container.getNext().getFirst('.tot').set('html',this.options.label.totalPrice+':<br /><strong>&euro; '+resp.globalPrice+'</strong>');
			this.container.getElements('a.close').each(function(el){
				
				el.addEvent('click',function(e){
					e = new Event(e);
					e.preventDefault();
					this.removeItem($(e.target));
					
				}.bind(this));
			
				
			}.bind(this));
			if($defined(this.options.afterBuildCart)){
				this.options.afterBuildCart();
			}
		}
	},
	
	
	addMultiItem : function(){
		new Request.JSON({
			url: this.url, 
			onSuccess: this.afterAddItem.bind(this)
		}).post({
			'page': 'cart.addMultiItem',
			'code': id
		});
	},
	
	addItem: function(id) {
		present = ($$('input[name="scelta"][checked]').length>0 ? $$('input[name="scelta"][checked]')[0].get('value') : '');
		
		
			 
		
		new Request.JSON({
			url: this.url, 
			onSuccess: this.afterAddItem.bind(this)
		}).post({
			'page': 'cart.addItem',
			'code': id,
            'present': present
		});
	},
	afterAddItem : function(resp){
		
		this.options.roar.alert('Abbonati online',this.options.label.addItem);
		el  = resp.items
		if(this.container.hasClass('off')){
			this.hideEmptyCart();
		}
		if($type(el.thumb)=='array'){
			elem = Elements.from(this.snippetMulti.substitute(el));
		}else{
			elem = Elements.from(this.snippet.substitute(el));
		}
		removeBtn = elem[0].getElement('a.close'); 
		removeBtn.addEvent('click',function(e){
			e = new Event(e);
			e.preventDefault();
			this.removeItem($(e.target));
		}.bind(this));
		elem[0].inject(this.container,'bottom');
		
		if($defined(this.options.afterBuildCart)){
			this.options.afterBuildCart();
		}
		
		this.container.getNext().getFirst('.tot').set('html',this.options.label.totalPrice+':<br /><strong>&euro; '+resp.globalPrice+'</strong>');
		
		if($defined($$('.aggiungi')[0])){
			$$('.aggiungi')[0].unspin();
		}
		
		
	},
	
	
	
	
	removeItem: function(elem) {
		id = elem.get('rel');
		var jsonRequest = new Request.JSON({
			url: this.url, 
			onSuccess: this.afterRemoveItem.bind(this)
		}).get({
			'page': 'cart.removeItem',
			'code' : id
		});
	},
	afterRemoveItem : function(resp){
		
			this.container.getNext().getFirst('.tot').set('html',this.options.label.totalPrice+':<br /><strong>&euro; '+resp.globalPrice+'</strong>');
			this.container.getFirst('div#'+resp.code+'_carrItem').nix();
			if(resp.count <= 0){
				window.location.reload();
			}
	}
	
	
});


var LightboxPrivacy = new Class({
	 
	 Implements: Options,
	 
	 el: $empty(),
	 
	 options: {
		url: '/be/main.php?page=offerta.conversione',
		cancelClass : Â 'btnCC',
		acceptClass : Â 'btnConcludi',
	 onCancel: null,
	 Â onConfirm: null
	 },
	 
	 initialize: function($options) {
	 Â this.setOptions($options); Â 
	 Â this._init(); 
	 },
	 
	 _init:function() {
	 Â new Request({ url: this.options.url, onSuccess: this._onRequestSuccess.bind(this) }).send();
	 },
	 
	 _onRequestSuccess: function($resp) {
	 Â this.el = Elements.from($resp)[0];
	 Â this.el.getElement(".lb-bg").setOpacity(.5);
	 Â this.el.getElement(".content-bg").setOpacity(.8);
	 Â 
	 
	 
	 Â if($defined(this.el.getElement("a."+this.options.cancelClass))){
		
		 this.el.getElement("a."+this.options.cancelClass).addEvent("click", this.cancel.bind(this));
		 
	 }
	 Â Â if($defined(this.el.getElement("a."+this.options.acceptClass))){
		 
		 this.el.getElement("a."+this.options.acceptClass).addEvent("click", this.accept.bind(this));
	 }
	 Â this.el.inject(document.getElement("body"));
	 Â this.show();
	 },
	 
	 show: function() { Â 
	 Â this.el.removeClass("hidden");
	 this.el.getElement(".content-bg").setStyle('height' ,this.el.getElement(".content").getSize().y+25);
	 },
	 
	 hide: function() {
	 Â this.el.addClass("hidden");
	 },
	 
	 cancel: function() {
	  this.hide();
	 Â 	Â if($defined(this.options.onCancel))
	 	this.options.onCancel();
	 },
	 
	 accept: function() {
		 this.hide();
	 Â if($defined(this.options.onConfirm))
		 this.options.onConfirm();
	 }

	});

function addItemFlashWrapper(id,testata){
	if($defined(cart)){
		cart.addItem(id);
	}
	if($defined(pageTracker)){
		pageTracker._trackEvent('Home', 'Aggiungi', 'flash '+testata);
	}
}

function addItemRivistaWrapper(id,url){
	if($defined(cart)){
		cart.addItem(id);
	}
	if($defined(pageTracker)){
		pageTracker._trackEvent('Testata', 'Aggiungi', url);
	}
}

