/******************* CAROUSEL VERTICAL *****************************/

var active_carousel = 1;

function mycarousel_initCallback(carousel) {

	$('#control2-1').addClass('selected');
	
	$('.opcion a').bind('click', function() {

		var s = new String($(this).attr('id'));
		var indice = s.split('-');
		indice=indice[1];

		$('#control2-'+active_carousel).removeClass();    
		$('#control2-'+$.jcarousel.intval(indice)).addClass('selected');		

		carousel.scroll($.jcarousel.intval(indice));	
		active_carousel=indice;
	 
		return false;	        
	});

	$('.opcion a').bind('mouseleave', function() {

		var s = new String($(this).attr('id'));
		var indice = s.split('-');
		indice=indice[1];
		if (indice!=active_carousel){
			$('#control2-'+indice).removeClass('selected');
			$('#control2-'+indice).removeClass('pngFix');
		}

		return false;		    
	});  

}	

/******************* CAROUSEL HORZONTAL *****************************/

var active_carousel_horizontal = 1;
var max_carousel = 11;		

var activo = false;
var down = false;

function final(){
	if (down){
		activo=true;
		down=false;
		if ($.browser.msie){				
			$(this).animate({marginTop:168}, "slow", "linear", final);				
		}else{
			$(this).animate({marginTop:178}, "slow", "linear", final);
		}		
	}else{			
		if (activo){
			activo=false;					
		}else{
			activo=true;
		}
	}
}

function mycarouselhorizontal_initCallback(carousel) {
	
	$('#control-1').addClass('selected');
				
	$('.jcarousel-prev').addClass('pngFix')
	$('.jcarousel-next').addClass('pngFix')
									
	if ($.browser.msie){
	
		$('.cortina2-hor').bind('mouseover', function() {	
			if (!activo){
				activo=true;
				$(this).animate({marginTop:143}, "slow", "linear", final);
			}			
			return false;
		});		
		
		$('.cortina2-hor').bind('mouseleave', function() {	
			if (!activo){
				activo=true;
				$(this).animate({marginTop:168}, "slow", "linear", final);
			}else{
				down=true;
			}			
			return false;
		});				
	
	}else{
		
		$('.cortina2-hor').bind('mouseover', function() {	
			if (!activo){
				activo=true;
				$(this).animate({marginTop:153}, "slow", "linear", final);
			}			
			return false;
		});		
		
		$('.cortina2-hor').bind('mouseleave', function() {	
			if (!activo){
				activo=true;
				$(this).animate({marginTop:178}, "slow", "linear", final);
			}else{
				down=true;
			}			
			return false;
		});			
		
	}

	$('.opcion_horizontal').bind('click', function() {
		$('#control-'+active_carousel_horizontal).removeClass('selected');				
		var s = new String($(this).attr('id'));
		var indice = s.split('-');
		indice=indice[1];												
		carousel.scroll($.jcarousel.intval(indice));
		active_carousel_horizontal = $.jcarousel.intval(indice);
		$('#control-'+active_carousel_horizontal).addClass('selected');
		return false;
	});

	$('.jcarousel-prev').bind('click', function() {	
		var tmp = active_carousel_horizontal-2;		
		if (tmp>=1){
			$('#control-'+active_carousel_horizontal).removeClass('selected');
			active_carousel_horizontal=active_carousel_horizontal-2;
			$('#control-'+active_carousel_horizontal).addClass('selected');
		}
		return false;
	});

	$('.jcarousel-next').bind('click', function() {
		var tmp = active_carousel_horizontal+2;
		if (tmp<=max_carousel){
			$('#control-'+active_carousel_horizontal).removeClass('selected');
			active_carousel_horizontal=active_carousel_horizontal+2;
			$('#control-'+active_carousel_horizontal).addClass('selected');
		}
		return false;
	});		

}

/******************* CAROUSEL HORIZONTAL CENTRAL*****************************/

var activo_central = new Array(false,false,false);
var down_central = new Array(false,false,false);

var activo_central = false;
var down_central = false;

function final_central(opcion){
	if (down_central[opcion]){
		activo_central[opcion]=true;
		down_central[opcion]=false;
		if ($.browser.msie){	
			$(this).animate({marginTop:158}, "fast", "linear", function(){final_central(opcion)});
		}else{
			$(this).animate({marginTop:157}, "fast", "linear", function(){final_central(opcion)});
		}
	}else{			
		if (activo_central[opcion]){
			activo_central[opcion]=false;					
		}else{
			activo_central[opcion]=true;
		}
	}
}

function mycarousel_central_initCallback(carousel) {
		
	if ($.browser.msie){
		
		$('.cortina-central').bind('mouseover', function() {	
			var s = new String($(this).attr('id'));
			var indice = s.split('-');
			indice=indice[1];
			
			if (!activo_central[indice]){
				activo_central[indice]=true;
				$(this).animate({marginTop:145}, "fast", "linear", function(){final_central(indice)});
			}			
			return false;
		});		
		
		$('.cortina-central').bind('mouseleave', function() {	
			var s = new String($(this).attr('id'));
			var indice = s.split('-');
			indice=indice[1];			
			if (!activo_central[indice]){
				activo_central[indice]=true;
				$(this).animate({marginTop:158}, "fast", "linear", function(){final_central(indice)});
			}else{
				down_central[indice]=true;
			}			
			return false;
		});									
	}else{		
		
		$('.cortina-central').bind('mouseover', function() {
			var s = new String($(this).attr('id'));			
			var indice = s.split('-');
			indice=indice[1];			
			if (!activo_central[indice]){
				activo_central[indice]=true;
				$(this).animate({marginTop:143}, "fast", "linear", function(){final_central(indice)});
			}			
			return false;
		});				
		$('.cortina-central').bind('mouseleave', function() {	
			var s = new String($(this).attr('id'));
			var indice = s.split('-');
			indice=indice[1];				
			if (!activo_central[indice]){
				activo_central[indice]=true;
				$(this).animate({marginTop:157}, "fast", "linear", function(){final_central(indice)});
			}else{
				down_central[indice]=true;
			}			
			return false;
		});					
	}
	
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        //carousel.options.scroll = 2*jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
    	// 2 * el numero de fichas de scroll
        carousel.options.scroll = 2*1; 
        return false;
    });

    jQuery('#mycarousel-central-next').bind('click', function() {	
    	if (carousel.options.size!=carousel.last){
    		carousel.next();
    	}
        return false;
    });

    jQuery('#mycarousel-central-prev').bind('click', function() {
        carousel.prev();
        return false;
    });

};

function carousel_destacats(){

	jQuery('#mycarousel').jcarousel({
		scroll: 2,
		visible: 2,
		vertical: true,
		initCallback: mycarousel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});

}

