var Calls = new Class({
		
	_enlace : null,
	
	initialize : function(){
	},
		
	getSubcategoria : function(tipo, link){
		this.load1(defecto._root+'/index.php/es/subcategoria.html',tipo,link,'content-ajax');
	},
	
	getDescripcion : function(tipo, producto){
		this.load2(defecto._root+'/index.php/es/producto.html',tipo, producto,'content-ajax');
	},
	// load2 //////////////////////////////
	load2 : function(url, search1, search2, container) {
		
		var container= $(container);

		// Avoid IE7 bug but don't execute JS in loaded page
		var request = new Request({
					url: url,
					method: 'post',
					data : {'search1' : search1, 'search2' : search2},
					onFailure: function () {alert('error');},
					onComplete: function (response, xml) {
							container.set('html', response);
							calls.initMiniAnimation.delay(0, this);
					}
		});

		request.send();
		return false;
	},
	// /load //////////////////////////////
	
	// load1 //////////////////////////////
	load1 : function(url, search, link, container) {
		
		var container= $(container);
		var enlace = this._enlace;
		if(link!=null)
			var enlace = $(link);

		// Avoid IE7 bug but don't execute JS in loaded page
		var request = new Request({
					url: url,
					method: 'post',
					data : {'search' : search},
					onFailure: function () {alert('error');},
					onComplete: function (response, xml) {
							container.set('html', response);
							if (calls._enlace!=null)
								calls._enlace.removeClass('selected');
							calls._enlace = enlace;
							calls._enlace.addClass('selected');
							calls.initAnimation.delay(0, this);
					}
		});

		request.send();
		return false;
	},
	// /load //////////////////////////////
	
	initAnimation : function (){
		var nS = new noobSlide({
			box: $('photo-diap'),
			items: $$('#photo-diap div'),
			size:600,
			autoPlay: false,
			fxOptions: {
				duration: 1000,
				wait: false
			},
			
			//handles: $$('#controls span'),
			
			addButtons: {
				previous: $('previous'),
				next: $('next')
			},
			onWalk: function(currentItem,currentHandle){
				$('next').setStyles({'visibility':'hidden'});
				$('previous').setStyles({'visibility':'hidden'});
				if(this.items.length > 1) {
					if(this.currentIndex == (this.items.length-1))
						$('previous').setStyles({'visibility':'visible'});
					else{
						if(this.currentIndex == 0)
							$('next').setStyles({'visibility':'visible'});
						else {
							$('next').setStyles({'visibility':'visible'});
							$('previous').setStyles({'visibility':'visible'});
						}
					}
				}	
			}	
		});
	},
	
	initMiniAnimation : function (){
		var nS = new noobSlide({
			box: $('photo-diap'),
			items: $$('#photo-diap div'),
			size:85,
			autoPlay: false,
			fxOptions: {
				duration: 500,
				wait: false
			},
			
			addButtons: {
				previous: $('previous'),
				next: $('next')
			}
			
		});
	}
	
});
