﻿window.onresize = function() {
    resizeBackground();
}

function clientSize() {
    var theWidth, theHeight, ratio;
    // Window dimensions: 
    if (window.innerWidth) {
        theWidth = window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
        theWidth = document.documentElement.clientWidth;
    }
    else if (document.body) {
        theWidth = document.body.clientWidth;
    }
    if (window.innerHeight) {
        theHeight = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        theHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        theHeight = document.body.clientHeight;
    }
    ratio = theWidth / theHeight;
    var result = ratio + "," + theWidth + "," + theHeight;
    return result;
}

function tb_remove_label(o, v) {
    if (o.value == v) { o.value = ""; }
}

function tb_add_label(o, v) {
    if (o.value == "") {o.value = v; }
}

function close_item() {
    var id = "inner_text";
    if ($('#' + id).css('display') == "none") {
        $('#' + id).slideDown("fast");
        $('#close_1').css('background-image', 'url(img/cross_big.png)')
        $('#close_1').css('background-position', '5px 5px')
    }
    else {
        $('#' + id).slideUp("fast");
        $('#close_1').css('background-image', 'url(img/button_arrow_left_big.png)')
        $('#close_1').css('background-position', 'left top')
    }
}

function resizeBackground() {
    $('#background img').cjObjectScaler({
        method: "fill",
        destElem: $('#background'),
        fade: 1500
    });
}

function resizeProjectGrid() {
    $('.foto_image_gallery img').cjObjectScaler({
        method: "fill",
        destElem: $('.foto_image_gallery'),
        fade: 1500
    });
    $('.foto_image img').cjObjectScaler({
        method: "fill",
        destElem: $('.foto_image'),
        fade: 1500
    });
}

function timerChiudi() {
    timer01 = setTimeout('chiudi()', 2000);
}

function stopTimerChiudi() {
    clearTimeout(timer01);
}

function chiudi() {
    $('.accordion_panel').slideUp("fast");
}

function slide(id) {

if ($('#' + id).css('display') == "none") {
    $('.accordion_panel').slideUp("fast");
    }

    if ($('#' + id).css('display') == "none") {
        $('#' + id).slideDown("fast");
    }
//    else {
//        $('#' + id).slideUp("fast");
//    }
}

function slide_box(id) {
    //$('.accordion_panel_2').slideUp("fast");

    if ($('#' + id).css('display') == "none") {
        $('#' + id).slideDown("fast");
    }
    else {
        $('#' + id).slideUp("fast");
    }
}

function slide_home() {
    if ($('#more_home').css('display') == "none") {
        $('#more_home').slideDown("fast");
        $('#continue_home').hide();
        $('#continue_home_2').show();
        $('#box_title').attr("style", "height:auto");
    }
    else {
        $('#more_home').slideUp("fast", function() { $('#box_title').attr("style", "height:100px") });
        $('#continue_home').show();
        $('#continue_home_2').hide();
        
    }
}

function change_text(id, text, label1, label2) {
    if (text == "continua") {
        $('#' + id).html("&raquo; " + label2 + " &laquo;");
        $("#" + id).attr("href", "javascript: slide('continua'); change_text('p_continua', 'nascondi','" + label1 + "','" + label2 + "');");
    }
    if (text == "nascondi") {
        $('#' + id).html("&raquo; " + label1 + " &laquo;");
        $("#" + id).attr("href", "javascript: slide('continua'); change_text('p_continua', 'continua','" + label1 + "','" + label2 + "');");
    }
}

function modal_message() {
    // open a welcome message as soon as the window loads
    Shadowbox.open({
    content: '<div id="modal_loader"><img src="../images/ui/loader_mini.gif" class="icon" />Operazione in corso...</div>',
        player: "html",
        height: 150,
        width: 350
    });

}
function fade_object(oggetto){
    $(oggetto).fadeOut("slow");
}
