var $j=jQuery.noConflict();

$j(document).ready(function() {
// ESCONDO LA CORTINA
	$j("#cortina").hide("fast");
// RESETEO LOS HOVERS
	$j("#home").attr("id","homeVisit");
	$j("#hotelVisit").attr("id","hotel");
	$j("#habitVisit").attr("id","habit");
	$j("#ubicaVisit").attr("id","ubica");
	$j("#contaVisit").attr("id","conta");
$j("#eventosVisit").attr("id","eventos");
//$j("#promoVisit").attr("id","promo");
$j("#galeriaVisit").attr("id","galeria");
$j("#restoVisit").attr("id","resto");

// ARRANCA EL CLICK

    $j('div#menu ul li a').click(function(){

	//$j("#homeVisit").attr("id","home");
	$j("#hotelVisit").attr("id","hotel");
	$j("#habitVisit").attr("id","habit");
	$j("#ubicaVisit").attr("id","ubica");
	$j("#contaVisit").attr("id","conta");
$j("#eventosVisit").attr("id","eventos");
//$j("#promoVisit").attr("id","promo");
$j("#galeriaVisit").attr("id","galeria");
$j("#restoVisit").attr("id","resto");    
    	var toLoad = $j(this).attr('id')+'.html';
   		var toVisit =$j(this).attr('id')+'Visit';
    
if($j(this).attr('id')=='home') {
	$j('#cortina').slideUp('slow');
	$j(this).attr("id",toVisit);
}else{
/*agregado para hacer promociones un div*/
if($j(this).attr('id')!= 'promos'){

if($j(this).attr('id')== 'hotel' || 'habit') { 
			$j('#cortina').slideUp('slow',loadContenth);
			
				}else{
			$j('#cortina').slideUp('slow',loadContent);
		}
	$j(this).attr("id",toVisit);
    return;

/*agregado para hacer promociones un div*/
}


}
  
    function loadContent() {
    	$j('#cortCont').load(toLoad,'',showNewContent())
    }

    function loadContenth() {
    	$j('#cortCont').load(toLoad,'',function(){
  			$j('#cortina').slideDown('slow');
  				// GALERIA DE IMAGNES

			$j('#thumbs a').click(function(){
			$j('#grande').html("<img src="+$j(this).attr("href")+" />").slideUp('fast');
			$j("#grande img").load(function() { 
				$j("#grande").slideDown("fast");
			});
	
			return false;
			});
			// SIMULO EN EL PRIMERO
			$j("#thumbs a:first").click(); 	
			$j('#cortina').slideDown('slow');
 		});
    }    
    
    function showNewContent() {
    	$j('#cortina').slideDown('slow');
    }

    function showNewContenth() {
    	$j('#cortina').slideDown('slow', cargaGallery());
    }

	function cargaGallery() {
	$j('#thumbs a').click(function(){
		$j('#grande').html("<img src="+$j(this).attr("href")+" />").hide();
		$j("#grande img").load(function() { 
			$j("#grande").show("slow");
				});
		return false;
		});
// SIMULO EN EL PRIMERO
		$j("#thumbs a:first").click(); 	
	}


    return false;
    
    });




// ENVIO DE FORMULARIO AJAXXXXX
 $j().ajaxStart(function() {
        $j('.formenviar').show();
     }).ajaxStop(function() {
       // $j('.formenviar').hide();
    });
    $j('#form, #formulario, #fo').submit(function() {
        $j.ajax({
            type: 'POST',
            url: $j(this).attr('action'),
            data: $j(this).serialize(),
            success: function(data) {
             $j('#result').html(data);
            // alert("El formulario ha sido enviado con exito!");
            //	$j("#cortina").slideUp("slow");
			//	$j(this).attr("id","homeVisit");
			// return false;
            // $j('#formulario').hide();
               

            }
        })
        
        return false;
    }); 

//
    
    
    
});

function slideSwitch() {
    var $active = $j('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $j('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $j('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $j( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$j(function() {
    setInterval( "slideSwitch()", 5000 );
});

