$(document).ready(
	function(){
		$("a.external").attr({ target: "_blank" });
		$("#previous").hide();
		var offset;
		var teller = 1;
		var paused = false;
		$(".rumble").hover(
			function(){
				offset = $(this).offset();
				$(this).effect("shake", { direction:'left', times:1000, distance:'6' }, 50);
			},
			function(){
				$(this).stop(true,true);
				$(this).offset({left:offset.left,top:offset.top});
			}
		);
	    $(".rol").hover(
			function(){
				var iconName = $(this).attr("src");
				var ext = iconName.substring(iconName.lastIndexOf(".") + 1);
				iconName = iconName.substring(0, iconName.length - (ext.length + 1)) + "rol." + ext;				
				$(this).attr({src: iconName});
				$(this).css("cursor","pointer");
			},
			function(){
				var iconName = $(this).attr("src");
				var ext = iconName.substring(iconName.lastIndexOf(".") + 1);
				iconName = iconName.substring(0, iconName.length - (ext.length + 4)) + "." + ext;
				$(this).attr({src: iconName});
			}
		);
	    $("#next").click(
	    	function(){
	    		if (!paused) {
		    		teller += 1;
		    		if (teller == upper) {
		    			$("#next").hide();
		    		} else {
		    			$("#previous").show();
		    		}
		    		doImg();
	    		}
	    	}
	    );
	    $("#previous").click(
	    	function(){
	    		if (!paused) {
	    			teller -= 1;
		    		if (teller == lower) {
		    			$("#previous").hide();
		    		} else {
		    			$("#next").show();
		    		}
		    		doImg();
	    		}
	    	}
	    );
	    function doImg() {
	    	paused = true;
	    	var iconName = start + teller + ext;
	    	$("#image").hide("fold", {}, "slow",
	    		function(){
	    			$("#image").attr({src: iconName}).load(
		    			function(){
		    				$("#image").show("fold", {}, "slow");
		    				paused = false;
		    				$("#image").unbind("load");
		    			}
	    			);
	    		}
	    	);
	    }
	}
);
