﻿window.onresize = function () {
    resizeBackground();
    setContainer();
}

function changeText(id,testo) {
    if ($('#' + id).attr('value') == "") { $('#' + id).attr('value', testo); }
    else {
        if ($('#' + id).attr('value') == testo) { $('#' + id).attr('value', ''); }
    }
}

function setContainer() {
    var dim = clientSize();
    var a = dim.toString().split(",");
    var x = (a[1]- 240);
    $('#project_grid_container').css('width', x + 'px');
}

function label_project(what) {
    var dim = clientSize();
    var a = dim.toString().split(",");
    var x = (a[1]/2)+40;
    if (what == 'previous') {
        $('#label_previous').css('right', x + 'px');
        $('#label_previous').fadeIn();
    }
    if (what == 'next') {
        $('#label_next').css('left', x + 'px');
        $('#label_next').fadeIn();
    }
    if (what == 'details') {
        $('#label_details').css('left', x - 40 - 75 + 'px');
        $('#label_details').fadeIn();
    }
}

function swapBullet(no) {
    $('#img_buttons img').attr('src', '../../media/ui/img_pager.png');
    $('#img_button_' + no).attr('src', '../../media/ui/img_pager_on.png');
}

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 resizeBackground() {
    $('#_background img').cjObjectScaler({
        method: "fill",
        destElem: $('#_background')
//        ,
//        fade: 1500
    });
}

function resizeProjectGrid() {
    $('.project_grid_image').cjObjectScaler({
        method: "fill",
        destElem: $('.project_grid'),
        fade: 1000
    });
}

function highlightProjectGrid(id) {
    var a = id.toString().split("_");
    var el = '#image_' + a[1]
    $(el).fadeTo('slow',1);
    //$(el).attr('class', 'project_grid project_grid_highlight');
    el = '#list_' + a[1]
    $(el).attr('class', 'project_list_item_highlight');
}

function turnoffProjectGrid(id) {
    var a = id.toString().split("_");
    var el = '#image_' + a[1]
    $(el).fadeTo('fast',0);
    //$(el).attr('class', 'project_grid');
    el = '#list_' + a[1]
    $(el).attr('class', '');
}

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 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");
}
