try {
 document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

String.prototype.ucfirst = function() {
    return this.charAt(0).toUpperCase() + this.substr(1);
}

$(document).ready(function() {

    /* general hovers */
    $("img.hover").each(function() {
        if ($(this).attr("src").match(/_on\.(gif|jpg|png)$/i)) {
            $(this).removeClass("hover");
        }
    });
    $("img.hover").hover(function() {
        s = $(this).attr("src").replace(/\.(gif|jpg|png)$/i, "_on.$1");
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/_on\.(gif|jpg|png)$/i, ".$1");
        $(this).attr("src", s);
    });
    
    /* remove map mouseover from sold apartments */
	$("#plan > div.apartment").each(function() {
	    id = '#area' + $(this).attr('id').ucfirst();
	    if ($(this).css('background')) {
	        $(id).remove();
	    };
	});
	/* table to imagemap hovers */
	$("tr.passive").hover(function() {
	    number     = $(this).attr("id").replace(/\D/g, "");
	    background = "url('apartments/house1_apartmentXX_hover.gif') no-repeat top left;";
	    background = background.replace(/XX/, number);
	    id         = "#apartment" + number;
	    $(id).css("background", background);
	    $(this).addClass("hovered");
	}, function() {
   	    number     = $(this).attr("id").replace(/\D/g, "");
	    $(id).css("background", '');
	    $(this).removeClass("hovered");
	});
	
	/* imagemap to table hovers */
	$("#map > area").hover(function() {
        number     = $(this).attr("id").replace(/\D/g, "");
	    background = "url('apartments/house1_apartmentXX_hover.gif') no-repeat top left;";
	    background = background.replace(/XX/, number);
	    id         = "#apartment" + number;
	    row        = "#apartment" + number + "row";
	    $(id).css("background", background);
   	    $(row).addClass("hovered");
	}, function() {
        number     = $(this).attr("id").replace(/\D/g, "");
	    id         = "#apartment" + number;
	    row        = "#apartment" + number + "row";
	    $(id).css("background", '');
   	    $(row).removeClass("hovered");
	});
	
});
