/******************* CAROUSEL VERTICAL *****************************/



var active_carousel = 1;

var defaultStadingTime = 10;



var persistentCarousel=null;

var StandingTime = new Array();

//StandingTime[0]=5;

//StandingTime[1]=3;

//StandingTime[2]=5;

//StandingTime[3]=4;



var position =0;

var first=true;





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:168}, "slow", "linear", final);

		}		

	}else{			

		if (activo){

			activo=false;					

		}else{

			activo=true;

		}

	}

}



function mycarouselhorizontal_initCallback(carousel) {

	

	persistentCarousel = carousel;

	if( isNaN(StandingTime[position])) 
	{
		StandingTime[position] = defaultStadingTime;
	}
	myInterval = setInterval("moveNext()",StandingTime[position] * 1000 );

	$('#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: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;

		});			

		

	}



	$('.opcion_horizontal').bind('click', function() {

		window.clearInterval(myInterval);

		$('#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');

		

		position= (Math.round(active_carousel_horizontal/2)-1);

		

		myInterval = setInterval("moveNext()",StandingTime[position] * 1000 );

		

		return false;

	});



	$('.jcarousel-prev').bind('click', function() {	

		window.clearInterval(myInterval);

		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');

			

			position= (Math.round(active_carousel_horizontal/2)-1);

			

			myInterval = setInterval("moveNext()",StandingTime[position] * 1000 );

			

		}

		return false;

	});



	$('.jcarousel-next').bind('click', function() {

		window.clearInterval(myInterval);

		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');

			

			position= (Math.round(active_carousel_horizontal/2)-1);

			

			myInterval = setInterval("moveNext()",StandingTime[position] * 1000 );

		}

		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)});

			$(this).animate({marginTop:111}, "fast", "linear", function(){final_central(opcion)});

		}else{

			//$(this).animate({marginTop:157}, "fast", "linear", function(){final_central(opcion)});

			$(this).animate({marginTop:110}, "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)});

				$(this).animate({marginTop:98}, "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)});

				$(this).animate({marginTop:111}, "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)});

				$(this).animate({marginTop:96}, "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)});

				$(this).animate({marginTop:130}, "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

	});



/***/
	

    jQuery("#mycarousel-central").jcarousel({

        scroll: 6,

        visible: 6,

        initCallback: mycarousel_central_initCallback,

        buttonNextHTML: null,

        buttonPrevHTML: null

    });



    

    if (($.browser.msie)&&($.browser.version=='6.0')){

    	setTimeout("$('.cortina-central').css('width','281px')", 800);

    	setTimeout("$('.cortina-central').css('marginLeft','-293px')", 100);    	

	}       

    
	


}


function buildHeaderCarrousel(){
	jQuery('#mycarousel-horizontal').jcarousel({

		scroll: 2,

		visible: 2,

		initCallback: mycarouselhorizontal_initCallback

	});

	showCarrouselCarefully()
}

function showCarrouselCarefully(){
	jQuery('.sliderOwned').fadeOut('0');
	jQuery('.sliderOwned').fadeIn('1000');
	jQuery('.sliderOwned').removeClass('sliderOwned');	
}



function moveNext()

{

	

	

	

	window.clearInterval(myInterval);

	/*if(position==0 && !first ){

		

		$('#control-'+active_carousel_horizontal).removeClass('selected');

		active_carousel_horizontal=1;

		persistentCarousel.scroll($.jcarousel.intval(1));

		$('#control-'+active_carousel_horizontal).addClass('selected');

		active_carousel_horizontal++;

		

	}

	else{*/

			

			

			if(active_carousel_horizontal+2 < max_carousel){

				$('#control-'+active_carousel_horizontal).removeClass('selected');	

				persistentCarousel.next();

				active_carousel_horizontal=active_carousel_horizontal+2;

				$('#control-'+active_carousel_horizontal).addClass('selected');}

			else

				{

				$('#control-'+active_carousel_horizontal).removeClass('selected');

				active_carousel_horizontal=1;

				

				persistentCarousel.scroll($.jcarousel.intval(1));

				$('#control-'+active_carousel_horizontal).addClass('selected');

				}

			

		

	//}

		

		

	//	position=(position+1)%StandingTime.length;

	position= (Math.round(active_carousel_horizontal/2)-1);

		
	if( isNaN(StandingTime[position])) 
	{
		StandingTime[position] = defaultStadingTime;
	} 
	myInterval = setInterval("moveNext()",StandingTime[position] * 1000 );

	

	

	first=false;			

}




