function link_fadeout() {
    $('#link_div').fadeTo(800,0.1,function(){
        link_fadein();
    });
}

function link_fadein() {
    $('#link_div').fadeTo(1000,0.95,function(){
        link_fadeout();
    });
}
            

function resize_images() {

    var min_width = 640;
    var min_height = 480;

    var max_width = 1134;
    var max_height = 753;

    var window_width  = $(window).width();
    var window_height = $(window).height();

    var image_width   = $("#rimage").width();
    var image_height  = $("#rimage").height();

    var width_ratio   = image_width / window_width;
    var height_ratio  = image_height / window_height;

    if (height_ratio > width_ratio) {
        var new_height = (window_height*0.9);
        $("#rimage").height(new_height);
        $("#rimage").width("auto");
        if(new_height < min_height) {
            $("#rimage").height(min_height);
            $("#rimage").width("auto");
        }

    } else {
        var new_width = (window_width*0.9);
        $("#rimage").width(new_width);
        $("#rimage").height("auto");
        if(new_width < min_width) {
            //alert("height < width");
            $("#rimage").width(min_width);
            $("#rimage").height("auto");
        }

    }

    // Maximum Image Size
    if($("#rimage").width() > max_width) {
        //alert("height < width");
        $("#rimage").width(max_width);
        $("#rimage").height("auto");
    }
    if($("#rimage").height() > max_height) {
        $("#rimage").height(max_height);
        $("#rimage").width("auto");
    }

    // Minimum Image Size
    if($("#rimage").width() < min_width) {
        //alert("height < width");
        $("#rimage").width(min_width);
        $("#rimage").height("auto");
    }
    if($("#rimage").height() < min_height) {
        $("#rimage").height(min_height);
        $("#rimage").width("auto");
    }

    var roc_left = ($(window).width() - $("#rimage").width()) / 2;
    if(roc_left < 0) roc_left = 0;

    var roc_top  = ($(window).height() - $("#rimage").height()) / 2;
    if(roc_top < 0) roc_top = 0;

    $("#rocas_main").css('left', roc_left);
    $("#rocas_main").css('top', roc_top);

    var link_left   = Math.ceil(parseFloat($("#rocas_main").css('left').replace("px", "")) + (882 * ($("#rimage").width() / max_width)));
    var link_top    = Math.ceil(parseFloat($("#rocas_main").css('top').replace("px", "")) + (336 * ($("#rimage").height() / max_height)));

    $("#link_div").css('left', link_left);
    $("#link_div").css('top', link_top);

    $("#limage").width(25 * ($("#rimage").width() / max_width));
    $("#limage").height(25 * ($("#rimage").height() / max_height));


    
    var link_left2   = Math.ceil(parseFloat($("#rocas_main").css('left').replace("px", "")) + (130 * ($("#rimage").width() / max_width)));
    var link_top2    = Math.ceil(parseFloat($("#rocas_main").css('top').replace("px", "")) + (330 * ($("#rimage").height() / max_height)));

    $("#link_agenda").css('left', link_left2);
    $("#link_agenda").css('top', link_top2);

    $("#aimage").width(160 * ($("#rimage").width() / max_width));
    $("#aimage").height(50 * ($("#rimage").height() / max_height));
    
}


