$(document).ready(function() {
		
		//navegacion por tabs
		//$("#menu1 ul").tabs("#panes > div", {effect: 'fade', fadeOutSpeed: 500});
		//$("#menu1 ul").tabs("#panes > div", {initialIndex: 2, effect: 'fade', fadeOutSpeed: 500});
		
		//animacion descripcion
		$(".info").click(function() {
			$("#slider").slideToggle();
		});
		

		$("#triggers a[rel]").overlay();
		$(".triggers [rel]").overlay();
		
		$('#backstretch').cycle({ 
		    fx:     'turnDown', 
		    speed:  'fast', 
		    timeout: 0, 
		    pager:  '.items'
		});
								
});
	
$(function() {
		 		 
	$(".items img").removeClass("active");
	$(".items img").css({'filter':'alpha(opacity=60)', '-moz-opacity':'0.6','-khtml-opacity':' 0.6','opacity':'0.6'});
	$(".items img:eq(0)").addClass("active");
	$(".items img:eq(0)").css({'filter':'alpha(opacity=100)', '-moz-opacity':'1','-khtml-opacity':' 1','opacity':'1'});
	
	//rollover	 
	$(".items img").hover(function () {
		$(this).css({'filter':'alpha(opacity=100)', '-moz-opacity':'1','-khtml-opacity':' 1','opacity':'1'});
		}, function () {
			if ($(this).attr("class")=='active') {
				$(this).css({'filter':'alpha(opacity=100)', '-moz-opacity':'1','-khtml-opacity':' 1','opacity':'1'});
			} else {
				var cssObj = {'filter':'alpha(opacity=60)', '-moz-opacity':'0.6','-khtml-opacity':'0.6','opacity':'0.6'}
			}
			
		$(this).css(cssObj);
	});
	
	//sceoll de imagenes
	
	//galeria automatica
	queDiv = 0
	queImg = 0
	autoPlayer = 0
	$(".flecha_play").hide();
	
	$('.scrollable').scrollable();
	
	$(".items img").click(function() {
		queDiv = $(".scrollable").scrollable().getIndex();
		queImg = $(this).index();
		if ( autoPlayer == 0) {
			clearInterval(ID);
		}
		// see if same thumb is being clicked
		//alert ($(this).get(0).tagName)
		if ($(this).hasClass("active")) { return; }
		// calclulate large image's URL based on the thumbnail URL
		var url = $(this).attr("src").replace("-122x81", "");
		// get handle to element that wraps the image and make it semi-transparent
		var img = new Image();
		// call this function after it's loaded
		img.onload = function() {
			var wrap = $("#backstretch").fadeOut(1000);
			$( "#backstretch" ).promise().done(function() {
				wrap.hide().fadeIn(1000);
				// change the image
				wrap.find("img").attr("src", url);
			});

		};
		img.src = url;
		// activate item
		$(".items img").removeClass("active");
		$(".items img").css({'filter':'alpha(opacity=60)', '-moz-opacity':'0.6','-khtml-opacity':' 0.6','opacity':'0.6'});
		$(this).addClass("active");
		$(this).css({'filter':'alpha(opacity=100)', '-moz-opacity':'1','-khtml-opacity':' 1','opacity':'1'});
		autoPlayer = 0
		
	// when page loads simulate a "click" on the first image
	})
		
	function doClick(queImg_f, queDiv_f, esBotonera){
		queImg = queImg + queImg_f;
		if ( queDiv == 0 ) {
			if ( queImg < 0 ) {
				queDiv = 2
				queImg = 3
				$(".scrollable").scrollable().seekTo(2);
			} else if ( queImg > 3 ) {
				queDiv = 1
				queImg = 0
				$(".scrollable").scrollable().seekTo(1);
			} 
		} else if( queDiv == 1 ){
			if ( queImg < 0 ) {
				queDiv = 0
				queImg = 3
				$(".scrollable").scrollable().seekTo(0);
			} else if ( queImg > 3 ) {
				queDiv = 2
				queImg = 0
				$(".scrollable").scrollable().seekTo(2);
			}
		} else if( queDiv == 2 ){
			if ( queImg < 0 ) {
				queDiv = 1
				queImg = 3
				$(".scrollable").scrollable().seekTo(1);
			} else if ( queImg > 3 ) {
				queDiv = 0
				queImg = 0
				$(".scrollable").scrollable().seekTo(0);
			}
		}
		autoPlayer = 1
		if ( esBotonera==0 ) {
			jQuery(".items div:eq("+queDiv+") img:eq("+queImg+")").trigger('click',  ID = setTimeout( doClick, 7000, 1,0,0) ) ;
		} else {
			jQuery(".items div:eq("+queDiv+") img:eq("+queImg+")").trigger('click') ;
		}
		
	}
	
	$(".flecha_left").click(function() {
		doClick(-1,0,1)
		$(".flecha_pausa").hide();
		$(".flecha_play").show();
		clearInterval(ID);
	})
	$(".flecha_right").click(function() {
		doClick(1,0,1)
		$(".flecha_pausa").hide();
		$(".flecha_play").show();
		clearInterval(ID);
	})
	$(".flecha_pausa").click(function() {
		$(this).hide();
		$(".flecha_play").show();
		clearInterval(ID);
	})
	$(".flecha_play").click(function() {
		$(this).hide();
		$(".flecha_pausa").show();
		ID = setTimeout( doClick, 7000, 1,0,0);
	})
	
	
	//intervalo de tiempo
	ID = setTimeout( doClick, 7000, 1,0,0);

			
});

$(function() {
    var ele   = $('#scroll');
    var speed = 25, scroll = 5, scrolling;
    
    $('#scroll-up').mouseenter(function() {
	   // Scroll the element up
	   scrolling = window.setInterval(function() {
		  ele.scrollTop( ele.scrollTop() - scroll );
	   }, speed);
    });
    
    $('#scroll-down').mouseenter(function() {
	   // Scroll the element down
	   scrolling = window.setInterval(function() {
		  ele.scrollTop( ele.scrollTop() + scroll );
	   }, speed);
    });
    
    $('#scroll-up, #scroll-down').bind({
	   click: function(e) {
		  // Prevent the default click action
		  e.preventDefault();
	   },
	   mouseleave: function() {
		  if (scrolling) {
			 window.clearInterval(scrolling);
			 scrolling = false;
		  }
	   }
    });
    
    $('#nav_down').click(
		function (e) {
			$('#scroll').animate({scrollTop: $('#scroll_int').height()}, 2000, 'easeOutQuad');
		}
	);
        // clicking the "up" button will make the page scroll to the top of the page
	$('#nav_up').click(
		function (e) {
			$('#scroll').animate({scrollTop: '0px'}, 2000, 'easeOutQuad');
		}
	);
    
    if ($('#scroll_int').height() <= $('#content').height()) {
	    $('#nav').hide();
	}
	
});

$(window).resize(function() {
	if ($('#scroll_int').height() <= $('#content').height()) {
	    $('#nav').hide();
	} else {
		$('#nav').show();
	}
});
