var headerimages = [];
$(document).ready(function(){
    if($("#front-image img").length > 1){
        window.setTimeout('switchImage(0)', 4000);
    }
    $("#house-image a, .highlighted a").hover(function(){
        $(this).find("span").css({backgroundColor:"#999999"});
    },
    function(){
        $(this).find("span").css({backgroundColor:"transparent"});
    });
    $("a.review").each(function(ix, el){
        el.target = '_blank';
    });
    $("form").submit(function(){
        $("#id_lkjhgf").val("fghjkl");
        $("#id_asdfgh").val("hgfdsa");
        var a = $(this)[0].action.split("/");
        $(this)[0].action = window.location.href + "/" + a[a.length-1];
        return true;
    });
    $("<div></div>")
        .attr("id", "thumbnail-viewer")
        .css({
            position:"absolute",
            top:"-300px",
            left:"-300px"
        })
        .appendTo("body");
    $(".press a").mouseenter(function(e){
        $("#thumbnail-viewer").find("img").detach();
        $("<img />")
            .attr("src", $(this).attr("rel"))
            .appendTo("#thumbnail-viewer");
        $("#thumbnail-viewer").css({
            top:e.pageY,
            left:e.pageX
        });
    });
    $(".press").mouseleave(function(){
        $("#thumbnail-viewer").css({
            top:-400,
            left:-400
        });
    });
    var press = $(".press");
    var h = 0;
    for(var i = 0; i < press.length; i++){
        if(i % 4 == 0 && i > 0){
           for(var j = i - 4; j < i; j++){
               $(press[j]).height(h);
           }
           h = 0;
        }
        if($(press[i]).height() > h){
            h = $(press[i]).height();
        }
    }
    for(var j = i - i % 4; j < i; j++){
        $(press[j]).height(h);
    }
});
function switchImage(ix) {
    var imgs = $("#front-image img");
    var current = ix;
    if(++ix >= imgs.length) { ix = 0; }
    $("#front-image-" + current).fadeOut("slow");
    $("#front-image-" + ix).fadeIn("slow");
    window.setTimeout('switchImage(' + ix + ')', 4000);
}

