var MinisiteNoel = new Class({
	
	options: {
		specops: 0,
		page : 0,
		scrollingpane: null,
		view: null,
		onComplete: Class.empty
	},
	
	items : 0,
	
	initialize: function( options ) {
		this.setOptions( options );
		
		new Ajax(
			'./request.php?nt=1', {
				method: 'post',
				data: 	'o=' 		+ this.options.specops 
					  + '&page='	+ this.options.page
					  + '&action=list',
				onComplete: this.addItems.bind(this)
			}
			
		).request();
	},
	
	addItems: function( items ) {
		switch( typeof items) {
			case 'string': // JSON
				try { items = Json.evaluate(items); } catch( ex ) { return; }
			case 'object' : 
				$A(items).each(function( item ) {
					if(this.items == 0 ) {
						this.showItem( item.numkey );
					}
					this.addItem( item );
					this.items++;
				}, this);
				this.onComplete();
			break;
		}
	},
	
	
	addItem: function( item ) {
		this.options.scrollingpane.adopt(
			new Element( 'div', { 
				 'class' : 'thumb' 
				,'title' : item.marque + ' :: ' + item.nom 
			}).adopt([
				new Element( 'a'	, { 'href' : item.link , events: { 'click' :  function(event) { event.stop(); this.showItem( item.numkey ); }.bindWithEvent(this)  } } ).setHTML( item.image_thumb )
			])
		);
	},
	
	showItem: function( id ) {
		new Ajax(
			'./request.php?nt=1', {
				method: 'post',
				data: 	'o=' 		+ this.options.specops 
					  + '&page='	+ this.options.page
					  + '&action=produit'
					  + '&produit=' + id ,
				update: this.options.view
			}
		).request();
	},
	
	onComplete : function() {
		var scrolling = this.options.scrollingpane;
		var anItem = $E('div.thumb', scrolling);
		//scrolling.setStyle('height'	,(anItem.getSize().size.y + anItem.getStyle('margin-top').toInt()+ anItem.getStyle('margin-bottom').toInt() ) * this.items);
		this.fireEvent('onComplete');
	}
	
});

MinisiteNoel.implement(new Options, new Events);