$(window).ready( function(){
	$('body').fadeIn();
	$("#items_galeria" ).hide();
	//$("#imagen" ).hide();
	$('.scrollable').scrollable({disabledClass:"disabled"});
	$('#contenido').hide();
	$('#contacto_form').hide();
	$('#contacto').hide();
	$('#backs').hide();
	$('#comentario').val('Message');
	$.ajax({
	  url: 'images/imagen.jpg',
	  context: document.body,
	  success: function(){
		$('#imagen').fadeIn();
	  }
	});
	$('.valida').focus(function(){
		$(this).val('');
	}).blur(function(){
		if($(this).val()==''){
			$(this).val('Debes ingresar tu '+$(this).attr('id'));
		}
	}
	)
	$('#reset').click(function(){
		$('#nombre').val('Name');
		$('#email').val('Email');
		$('#comentario').val('Message');
	})
	$('a').css({underline:'none'});
	$('a[rel=external]').attr('target', '_blank');
	$(".video a[rel]").overlay({
		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			$('<iframe src="" width="550" height="316" frameborder="0"></iframe>').appendTo(wrap);
			// load the page specified in the trigger
			var wrap2=wrap.find('iframe')
			wrap2.attr('src',(this.getTrigger().attr("href")));
		},onClose:function(){
			var wrap = this.getOverlay().find(".contentWrap");
			wrap.empty();
		}

	});
	$('form').submit(function() {
	$.ajax({
	type: 'POST',
	url: 'mail.php',
	data: $(this).serialize(),
	success: function(data) {
		$('#contacto_form').html(data).fadeIn();
	}
	})
	return false;
	});
	$(".menu_home").click(
		function () {
			var valor=($("p", this).html().length)*7+'px';
			$('.cover img').animate({width:'0px'},100);
			$(this).find('.cover img').animate({width:valor},100);
			var seccion=$(this).attr("id");
			if (seccion=='menu_galerias'){
				$( "#items_galeria" ).fadeIn();
				$(this).removeClass("tachado");
				} else if(seccion=='menu_backs') {
				if ($('#items_galeria').is(':visible')) $('#items_galeria').fadeOut();
				mostrar('backs');
			}else{
				if ($('#items_galeria').is(':visible')) $('#items_galeria').fadeOut();
				mostrar('contacto');
				}
		});
	$(".galeria").click(
		function () {
			var valor=($("p", this).html().length)*7+'px';
			$('.cover img', '.galeria').animate({width:'0px'},100);
			$(this).find('.cover img').animate({width:valor},100);
			var numero=$(this).attr('id').match("[^#/]+$");
			if(numero=='news_galeria'){
				numero='61';
			}
			muestaGaleria(numero);
		});
	$("#news").click(
		function () {
			$('.cover img').animate({width:'0px'},100);
			$('#menu_galerias').find('.cover img').animate({width:'42px'},100);
			$( "#items_galeria" ).fadeIn();
			$('.cover img','.galeria').animate({width:'0px'},100);
			$('.cover img','#news_galeria').animate({width:'40px'},100);
			muestaGaleria(61);
		});
		$('h1').click(function(){
				location.href = "./" 
			}
		)
	}
);
function mostrar(seccion){
		if ($('#contenido').is(':visible')) $('#contenido').fadeOut(200,function(){$('#'+seccion).fadeIn(200)});
		if ($('#home').is(':visible')) $('#home').fadeOut(200,function(){$('#'+seccion).fadeIn(200)});
		if ($('#contacto').is(':visible')) $('#contacto').fadeOut(200,function(){$('#'+seccion).fadeIn(200)});
		if ($('#backs').is(':visible')) $('#backs').fadeOut(200,function(){$('#'+seccion).fadeIn(200)});
		return false;
}
