
	jQuery.fn.extend({
    scrollBottom: function(speed) {
        return this.each(function() {
            var targetOffset = $(this).offset().top + $(this).height();
			var toplevel = {
				left:400,
				top:$(this).offset().top-118,
				width:200,
				height:1
				}
			var bottomlevel = {
				left:400,
				top:targetOffset,
				width:200,
				height:1
			}
			var container = {
				left: $(window).scrollLeft(),
				top: $(window).scrollTop(),
				width: $(window).width(),
				height: $(window).height()
				};
			if($.browser.safari) bodyelem = $("body")
			else bodyelem = $("html,body")

            if ($.isOnScreen(toplevel, container) && $.isOnScreen(bottomlevel, container)) { true; }
			else if ($.isOnScreen(toplevel, container) && $.isOnScreen(bottomlevel, container) !== true){ 
				if ($(this).height() < $(window).height()) {
					$(bodyelem).animate(
							{ scrollTop: targetOffset-$(window).height() } ,speed); 
				}
				else {
					$(bodyelem).animate({scrollTop: $(this).offset().top-118},speed);
				}
			}
			else { $(bodyelem).animate({scrollTop: $(this).offset().top-118},speed); } 
            });
        }
    });
	
	
	  $(document).ready(function() {
		$(".plate-link").click(function () {
			if ($("#plate-"+$(this).attr('id')).is(":hidden")) {
				$(this).children("img").attr("src", $(this).children("img").attr("src").replace(".png", "_opened.png"));
				$("#plate-"+$(this).attr('id')).slideDown("slow", function() { 	$(this).scrollBottom(1000); });
				
			} else {
				$(this).children("img").attr("src", $(this).children("img").attr("src").replace("_opened.png", ".png"));
				$("#plate-"+$(this).attr('id')).slideUp("slow");
			}
		});
		
	  });
	  
	  function plateclick(id) {
			if ($("#plate-"+id).is(":hidden")) {
				$("#"+id).children("img").attr("src", $("#"+id).children("img").attr("src").replace(".png", "_opened.png"));
				$("#plate-"+id).slideDown("slow", function() { 	$(this).scrollBottom(1000); });
				
			} else {
				$("#plate-"+id).scrollBottom(1000);
			} 
			return false;
	  }
	  
	  $(document).ready(function() {
		$(".vista-link").hover(function () {
			$('#vista-image').attr('src', 'img/vista/' + $(this).attr('id') + '.jpg');		
		});
		
	  });

