$(document).ready(function(){
	
	var lastid = $('#thumbnails').find('img').last().parent().attr('id');
	$('#next').live('click',function(){
		var a = window.location.href.split("#")[1];
		var id = $('#thumbnails').find('img[value="'+a+'"]').parent().attr('id');
		if ( typeof id !== 'undefined') {
			id++;
		} else {
			id = 1;
		}
		$('#thumbnails').find('a[id="'+id+'"]').trigger('click');

	});
	
	$('#prev').live('click',function(){
		var a = window.location.href.split("#")[1];
		var id = $('#thumbnails').find('img[value="'+a+'"]').parent().attr('id');
		id--;
		$('#thumbnails').find('a[id="'+id+'"]').trigger('click');
	});
	
	$('a[rel^=galeria]').each(function(){
	    $(this).bind('click',function(event){
	    $('.picimg').hide();
	    $('#navigallery').hide();
	    $('.cargando').show();
    	event.stopPropagation();
    	event.preventDefault();
	    var a = $('img',this).attr('src');
	    a = a.replace('thumb','normal');
	    var b = $('img',this).attr('alt');
	    $('.picimg').attr({src: a, alt:b});
	    $('.picimg').load(function(){
	        $('.cargando').hide();
	        $('.picimg').show();
	        $('#navigallery').show();
	    });
	    var c = $('img',this).attr('value');
	    window.location.hash = c;
	    });
	});
	
	$('a[rel^="gmap"]').each(function(){
	    $(this).bind('click',function(){
	    var a = $(this).attr('title');
	    $('#fromAddress').val(a);
	    $('#gmap').submit();
	    });
	});
	
	var imagen = "";
	imagen = window.location.href.split("#")[1];
	if ( typeof imagen !== "undefined") {
		$('#thumbnails').find('a img[value='+imagen+']')
			.parent()
			.trigger('click');
	}
	
	
/*	setInterval(function(){
		var an = window.location.href.split("#")[1];
		if ( typeof an == 'undefined') {
			an = 1;
		}
		var ids = $('#thumbnails').find('img[value="'+an+'"]').parent().attr('id');
		if ( typeof ids !== 'undefined' && ids < lastid) {
			ids++;
		} else {
			ids = 1;
		}
		$('#thumbnails').find('a[id="'+ids+'"]').trigger('click');
	},5000);*/
	
	var bc = $('.counter');
    var $container = $('.slideshow').cycle({
	    	fx: 'fade',
	    	speed: 250,
	    	prev: '#prinprev',
	    	next: '#prinnext'
	});

});

