$(document).ready(function(){
    refreshCufon();
    Cufon.now(); 
    
    $("#slider").imageScroll({width: 480});
    $("#slider_mini").imageScroll({width: 240});
    
    $(".boton-reserva-actividad").click( function(){
    	var id= ($(this).attr("id")).replace("boton-reserva-actividad-", "");
    	
    	$("#actividad-descripcion-text-" + id).slideToggle(300, function(){
    		$("#actividad-reserva-" + id).slideToggle(300);
    	});
    });
    
    
    $(".reservar-formacion-trigger").click (function(){
    	
    	var elemento = $(this);
    	var formulario = elemento.nextUntil("hr", ".reservar-formacion");
    	
    	elemento.slideToggle(100, function(){
    		formulario.slideToggle(400);
    	});
    });
 
    //RESIZES THE CONTENT  AND FOOTER, TO UPDATE THE BACKGROUND
    resizes();
    $(window).resize(resizes);
 
    // RESIZES THE ACTIVITY CONTAINER IF IS BIGGER
    $(".items").resize(function() {
        var newHeight = $(this).height();
        
        //UPDATE CONTENT BACKGROUND
         resizeContent(newHeight);
     
        $("#actividades").animate({ height: newHeight }, 600); 
       
       // $("#actividades").height(newHeight);
       //  resizes();
    });

    
    $(".ico_prev").add(".ico_next").hover( function() {
    	$(this).addClass("ico-selected");
    }, function(){
    	$(this).removeClass("ico-selected");
    });	
    
    $("a.slide-images").fancybox({
		'speedIn'		: 600, 
		'speedOut'		: 200,
		'overlayColor'	: '#e84d15',
		'showNavArrows'	: true,
		'cyclic'		: true
	});
	
	$("#slider_mini img").load( function(){
		$(this).fadeIn(500);
	});
	
	$("#slider img").load( function(){
		$(this).fadeIn(500);
	});
	
 });
 
function resizes(){
        
    //SET CONTENTS HEIGHT
    var height = $("#content").height();
    var padding = 10;
    $("#contentLeft").height(height+padding);
    $("#contentRight").height(height+padding);
    
    //SET FOOTER HEIGHT
    var footerPos = $("#footer").position();
    var bodyHeight = $("body").height();

    var total = bodyHeight-footerPos.top;
    
    if (total > 100)
     $("#footer").height(total);
}
function resizeContent(iHeight){
    
    //SET CONTENTS HEIGHT
    var padding = 100;
    var cHeight = $("#content").height();
    
    if (iHeight  > (cHeight-20)) {
    $("#contentLeft").height(iHeight+padding);
    $("#contentRight").height(iHeight+padding);        
    }

 
}
 
function refreshCufon(){

    Cufon.replace('#top_menu .menu_sup', { 
                    fontFamily: 'DIN Next Rounded LT Pro' 

                    });

    Cufon.replace('h1,h2');
/*
    Cufon.replace('#top_menu .menu_items a',{
            hover: {FontSize: '15px'}});
    */
    Cufon.replace('#text_contenido .ttitol',{
            fontSize:'40',color:'white'
            });	
    Cufon.replace('#quote, h2',{fontSize:'40px',fontFamily: 'Sauna'});
	
} 



/* --------- MENU WAIT ------------- */
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 
