$(document).ready(function() { 

	$(function () {
		$.each(
		$('.loading'),
			function( intIndex, objValue ){
				var img = new Image();
				$(img).load(function () {
					$(this).hide();
					$(objValue).removeClass('loading').append(this);
					$(this).fadeIn();
				}).error(function () {
				}).attr('src', $(this).attr('load'));

				alert($(this).attr('load'));
			}
		);
	});

	// header menu
	$('.menuLiHover').hover( 
		function(e) 
		{ 
			$('.menuHover').css({display: "none"}); 
			$('#sub' + this.id).fadeIn('slow'); 
		}, 
		function(e) 
		{ 
			if ($('#sub' + this.id).is(".my-hover-class")) {
				$('.menuHover').css({display: "none"}); 
			}
		} 
   ); 

	$('.menuHover').hover( 
		function(e) 
		{ 
		//$('.menuHover').css({display: "block"}); 
		}, 
		function(e) 
		{ 
		$('.menuHover').fadeOut(); 
		} 
	); 

	$(".menuHover").hover(
		function(){$(this).addClass("my-hover-class")},
		function(){$(this).removeClass("my-hover-class")}
	);

	$(".menuHide").hover(
		function(e) 
		{ 
			$('.menuHover').fadeOut(); 
		}, 
		function(e) 
		{ 
			//...
		} 
	);

	// popup images
	$(".lightbox").fancybox();

	// popup galleries
	$(".gallery").fancybox({
		'width'				: 960,
		'height'			: 516,
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$(".shareOnFacebook").bind('click', function() {
		OpenBrWindow($(this).attr("href"), 'fb', 'resizable=1,status=no,menubar=no,scrollbars=auto,toolbar=no,titlebar=no,location=no','700','550','true');
		return false;
	});

	// comments
	$('#formFooterNombre').bind('focus', function() {
		if ($('#formFooterNombre').val() == this.defaultValue) {
			$('#formFooterNombre').val('');
		}
	});

	$('#formFooterNombre').bind('blur', function() {
		if ($('#formFooterNombre').val() == '') {
			$('#formFooterNombre').val(this.defaultValue);
		}
	});

	$('#formFooterEmail').bind('focus', function() {
		if ($('#formFooterEmail').val() == this.defaultValue) {
			$('#formFooterEmail').val('');
		}
	});

	$('#formFooterEmail').bind('blur', function() {
		if ($('#formFooterEmail').val() == '') {
			$('#formFooterEmail').val(this.defaultValue);
		}
	});

	$('#formFooterComentario').bind('focus', function() {
		if ($('#formFooterComentario').val() == this.defaultValue) {
			$('#formFooterComentario').val('');
		}
	});

	$('#formFooterComentario').bind('blur', function() {
		if ($('#formFooterComentario').val() == '') {
			$('#formFooterComentario').val(this.defaultValue);
		}
	});

	$('#formFooterNombre, #formFooterEmail').keyup(function(e) {
		if (e.keyCode == 13) {
			login();
		}
	});

	$('#formFooterSubmit').bind('click', function() {
		login();
	});

	function login() {
		$('#formFooterLoading').html('<img src="/img/loading.gif" />');

		$.ajax({
			type: "POST",
			url: '/inc/inc_footer.php',
			data: "formFooterNombre=" + $('#formFooterNombre').val() + "&formFooterEmail=" + $('#formFooterEmail').val() + "&formFooterComentario=" + $('#formFooterComentario').val(),
			success: function(data){
				if (data == 1) {
					$('#formFooterLoading').hide();
					$('#formFooterSubmit').hide();
					$('#formFooter').hide();
					$('#formFooterOk').show();
				} else {
					$('#formFooterLoading').html(data);
				}
			}
		});
	}

	// gallery
	$('.roGallery').hover( 

		function(e) 
		{ 
			$('#imageGallery div').hide().html('<a href="'+$(this).attr("href")+'"><img src="'+$(this).attr("load")+'" /></a>').fadeIn('slow'); 

			$('#imageGalleryTitle').hide().html($(this).attr("title")).fadeIn('slow'); 
			$('#imageGalleryText').hide().html($(this).attr("content")).fadeIn('slow'); 

			$('#menuGallery div').removeClass("menuGalleryHover");
			$('#menuGallery div').addClass("menuGalleryLink");
			$(this).parent().removeClass("menuGalleryLink");
			$(this).parent().addClass("menuGalleryHover");
		}, 
		function(e) 
		{ 
			//$(this).parent().removeClass("menuGalleryHover");
			//$(this).parent().addClass("menuGalleryLink");
		} 
   ); 
}); 

$(function(){
	$('#slides').slides({
		preload: true,
		preloadImage: '/img/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true,
		animationStart: function(current){
			$('.caption').animate({
				bottom:0
			},100);
			if (window.console && console.log) {
				// example return of current slide number
				// console.log('animationStart on slide: ', current);
			};
		},
		animationComplete: function(current){
			$('.caption').animate({
				bottom:0
			},200);
			if (window.console && console.log) {
				// example return of current slide number
				// console.log('animationComplete on slide: ', current);
			};
		},
		slidesLoaded: function() {
			$('.caption').animate({
				bottom:0
			},200);
		}
	});
});

/*
Open Centered Popup Window Script-(c) DHTMLShock (www.dhtmlshock.com)
To add more shock to your site, visit www.DHTMLShock.com
*/

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}
