var hold=false;  var prev = -1;

$$(document).ready(function(){
	//*ACCORDION*/
	
	var prev = 0;
	
	//Definición del elemento que se cerrará en el primer click:
	var toClose = $$('.tourInfo_acc:first');
	toClose.css({'display':'block'});
	//Cual se mostrará, por el momento no sabemos
	
	//Encuentra todos los elementos con la clase 'acc_title'
	$$('body').find('.acc_title').each(function(i){
		//Al hacer click
		$$(this).click(function(){		
		//definimos el elemento padre	
		if($$('.acc_title').index(this) != prev && hold==false){	
			hold = true;	
				$$(toClose).animate({height: '1px'},500,function(){
					$$(toClose).css('display','none');
					$$(toClose).css('height','95px');
					toClose = $$(this);
				});		
				$$(this).next('.tourInfo_acc').slideDown(500,function(){
					//Cual se cerrará ahora:
					toClose = $$(this);
					prev = i;
					hold = false;
				});
		}						
			return false;				
		});
	});
	
	/*//////////////////////*/
	
	/*SLIDER*/
	
	
	 var sliderWidth = (parseInt($$('.toursCell').width())+parseInt($$('.toursCell').css('margin-right')))*$$('.toursCell').length;
	
	$$('.gridSlider').css({	
			'width':sliderWidth
		});
			
	function slideTours(side,control){
		
		var factor = $$('.toursCell').width()+parseInt($$('.toursCell').css('margin-right'));
		var gSlide = $$('.gridSlider');
		var limit = (factor*$$('.toursCell').length)*-1;
		var condition = parseInt(gSlide.css('margin-left'));
		var test = limit+(factor);

		if(parseInt(gSlide.css('margin-left')).toString() == 'NaN'){
			gSlide.css({
				'margin-left':0
			});
		}
				switch (side){
					case '+':
					jQuery.each(jQuery.browser, function(i) {			
						if($$.browser.msie){
							//
						}else{
							$$('.topTours_slide_left').animate({opacity:1},200);	
						}
					});
						$$('.topTours_slide_left').css('cursor','pointer');
						
						//console.log('condition: ' + condition  + '--> Test:' + test);
						
						if(condition!=test && hold == false){
												
							hold = true;
							gSlide.animate({
								marginLeft:	parseInt(gSlide.css('margin-left'))-(factor*2)
							},500,function(){
								if(parseInt(gSlide.css('margin-left'))==test){
								
								jQuery.each(jQuery.browser, function(i) {			
									if($$.browser.msie){
										//
									}else{
										$$('.topTours_slide_right').animate({opacity:.2},200);	
									}
								 });
									$$('.topTours_slide_right').css('cursor','auto');
								}
								hold = false;
							});
						}
					break;
					case '-':
						if(parseInt(gSlide.css('margin-left'))!=0 && hold == false){
						hold = true;
						
							jQuery.each(jQuery.browser, function(i) {			
								if($$.browser.msie){
								//
								}else{
								$$('.topTours_slide_right').animate({opacity:1},200);
								}
							});
						$$('.topTours_slide_right').css('cursor','pointer');
							gSlide.animate({
								marginLeft:	parseInt(gSlide.css('margin-left'))+(factor*2)
							},500,function(){
								if(parseInt(gSlide.css('margin-left'))==0){
									jQuery.each(jQuery.browser, function(i) {			
										if($$.browser.msie){
											//
										}else{
											$$('.topTours_slide_left').animate({opacity:.2},200);	
										}
									});
									control.css('cursor','auto');
								}
								hold = false;
							});
						}	
					break;
				}
	}
	$$('.topTours_slide_right').click(function(){
		slideTours('+',$$(this));
	});
	$$('.topTours_slide_left').click(function(){
		slideTours('-',$$(this));
	});	
	
	jQuery.each(jQuery.browser, function(i) {			
		if($$.browser.msie){
			//
		}else{
			$$('.topTours_slide_left').animate({opacity:.2},200);
		}
	 });
});

