$(document).ready(
	function(){
		$("a.ext").attr({ target: "_blank" });
		$("a.lightbox").lightBox();
		$("#showrooms").hide();
		$(".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");
				if (iconName.indexOf("rol") != -1) {
					var ext = iconName.substring(iconName.lastIndexOf(".") + 1);
					iconName = iconName.substring(0, iconName.length - (ext.length + 4)) + "." + ext;
					$(this).attr({src: iconName});
				}
			}
		);
		$("#colli").hoverIntent(
			function(){
				$(this).find("ul").show("slide", { direction: "left" }, 400);
			},
			function(){
				$(this).find("ul").hide("slide", { direction: "left" }, 1000);
			}
		);
	    $("#ho").click(
	    	function(){
	    		$("#showrooms").hide();
	    		$("#address").show();
				$("#ho").addClass("selected");
				$("#show").removeClass("selected");
				return false;
	    	}
	    );
	    $("#show").click(
	    	function(){
	    		$("#address").hide();
	    		$("#showrooms").show();
				$("#show").addClass("selected");
				$("#ho").removeClass("selected");
				return false;
	    	}
	    );

		var teller = 1;
		var teller2 = 2;
		var paused = false;
		var start = 'images/back';
		var ext = '.jpg';
		var upper = 3;
		var lower = 1;
	    function doImg(isNext) {
	    	paused = true;
			var iconName = start + teller + ext;
	    	var iconName2 = start + teller2 + ext;
	    	$("#background1").hide("fade", null, 1500,
	    		function(){
	    			$("#background1").attr({src: iconName}).load(
		    			function(){
		    				$("#background1").show();
		    				paused = false;
		    				$("#background1").unbind("load");
							$("#background2").hide(0,
								function(){
									$("#background2").attr({src: iconName2}).load(
										function(){
											$("#background2").show();
											paused = false;
											$("#background2").unbind("load");
										}
									);
								}
							);
		    			}
	    			);
	    		}
	    	);
	    }
		function doTimeOut() {
			setTimeout( function() {
				teller++;
				if (teller > upper) {
					teller = lower;	
				}
				teller2++;
				if (teller2 > upper) {
					teller2 = lower;	
				}
				doImg(true);
				doTimeOut()
			},
			4000);
		}
		if(cycle != "undefined") {
			if(cycle) {
				doTimeOut();
			}
		}
	}
);
