
function getXCoordinates(el_id){
    pos_x = document.getElementById(el_id).offsetLeft;
    return(pos_x);
}


function getYCoordinates(el_id){
    pos_y = document.getElementById(el_id).offsetTop;
    return(pos_y);
}


function getWindowWidth(){
    w = -1;
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            w = window.innerWidth;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            w = document.body.offsetWidth;
        }
    }
    return(w);
}


function getWindowHeight(){
    h = -1;
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            h = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            h = document.body.offsetHeight;
        }
    }
    return(h);
}


function setSubmenuLeftPosition(menu_el) {
    // sposta il submenu in base alla posizione del menu attivo: setSubmenuLeftPosition('{{ menu.nome }}')
    var d = getXCoordinates(menu_el);
    var w = getWindowWidth();
    if (w >= 770) {
        var x = d - Math.abs(parseInt((w - 770) / 2));
    } else {
        var x = d;
    }
    document.getElementById('submenu').style.padding = '0 0 0 ' + x + 'px';
}


function submenuOnMouseOver(submenu_link, is_ie6) {
    if (is_ie6) {
        var ext = 'gif';
    } else {
        var ext = 'png'; 
    }
    document.getElementById('subnav_left_border_' + submenu_link).style.background='url(/s3k_media/images/nav_l_border_hover.' + ext + ') center left no-repeat';
    document.getElementById('subnav_right_border_' + submenu_link).style.background='url(/s3k_media/images/nav_r_border_hover.' + ext + ') center right no-repeat';
    document.getElementById('subnav_text_' + submenu_link).style.background='#c5e7e7';
}


function submenuOnMouseOut(submenu_link) {
    document.getElementById('subnav_left_border_' + submenu_link).style.background='none';
    document.getElementById('subnav_right_border_' + submenu_link).style.background='none';
    document.getElementById('subnav_text_' + submenu_link).style.background='none';
}


function callTranslator(field, translator_command) {
    var t = document.getElementById('id_' + field + '_it').value;
    t = escape(t);
    if (t.length > 2000) {
        var i = 0;
        while (t.length - i * 2000 > 2000) {
            var s = t.substr(i * 2000, 2000);
            if (i == 0) { window.open('/translate_it/firstpart/yahoo?txt=' + s, '_blank'); }
            else { window.open('/translate_it/part/yahoo?txt=' + s, '_blank'); }
            i++;
        }
        var s = t.substr(i * 2000, t.length - i * 2000);
        window.open('/translate_it/lastpart/' + translator_command + '?txt=' + s, '_blank');
    }
    else { window.open('/translate_it/full/' + translator_command + '?txt=' + t, '_blank'); }
}


/* jquery */

$(document).ready(function() {
    /* http://www.thefutureoftheweb.com/blog/detect-ie6-in-javascript */
    var is_ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
    var is_ie = /*@cc_on!@*/false;
    if (is_ie6) {
        var ext = 'gif';
    } else {
        var ext = 'png'; 
    }
    
    /* fancybox http://fancy.klade.lv/howto */
    $("a.fancybox").fancybox({ 'zoomSpeedIn': 200, 'zoomSpeedOut': 200, 'overlayShow': true, 'frameHeight': 500,'frameWidth': 770 , 'padding': 5});
    $("a.fancybox_map").fancybox({ 'zoomSpeedIn': 200, 'zoomSpeedOut': 200, 'overlayShow': true, 'frameHeight': 450,'frameWidth': 400 });
    
    /* bottone lingua */
    $("#nav_flag_it").hover(
        function() {
            $("#flag").attr('src', '/s3k_media/images/flag_it_hi.' + ext);
        },
        function() {
            $("#flag").attr('src', '/s3k_media/images/flag_it.' + ext);
    });
    $("#nav_flag_en").hover(
        function() {
            $("#flag").attr('src', '/s3k_media/images/flag_en_hi.' + ext);
        },
        function() {
            $("#flag").attr('src', '/s3k_media/images/flag_en.' + ext);
    });
    
    /* da CSS non funziona */
    /*
    document.getElementById('input_username').style.height = '12px';
    document.getElementById('input_password').style.height = '12px';
    */
});
