jQuery(document).ready(function () {
    resize();
});

jQuery(window).resize(function () {
    resize();
});

//var orimfw = 440;
//var orimfw = 600;
var contenutoIstituzionale=700;
var contenutoProdotti=650;
var contenutoScheda=360;
var orisfw = 180;
var pdcf = 30; //padding 20 top/10 bottom canvas, footer
var pdlm = 80; //padding left/right lateral, main
var ah = 154; //arrow height

function resize() {
    var wtouse;
    var wh = jQuery(window).height();   //altezza schermo
    var ww = (jQuery(window).width()); //larghezza schermo
	var lw = 0
    var cw = jQuery('#content').width() + pdlm; //valido solo nella home per posiizonare il div con lo slideshow a lato del menu*/
	//var cw=215+pdlm;
    wtouse = ww - (lw + cw) + pdlm;
    
    var ratio;
    if (jQuery('#main').length == 0) {
        ratio = 1.4; //foto home page
    }
	
	if (jQuery('#main.ist').length != 0) {
		wtouse = ww - cw - contenutoIstituzionale + 215;
        ratio = 0.75;
    }
	
	if (jQuery('#main.prodotti').length != 0) {
		wtouse = ww - cw - contenutoProdotti + 215;
        ratio = 0.86;
    }
	
	if (jQuery('#main.scheda').length != 0) {
		wtouse = ww - cw - contenutoScheda + 215;
        ratio = 1.2;
    }

    var imgw = wh * ratio;
    var fh;
    var fw;
    if (imgw <= wtouse) {
        fh = wtouse / ratio;
        fw = wtouse;
    } else {
        fh = wh;
        fw = imgw;
    }
        
    //hold imgs in center
    if (fw >= wtouse) { jQuery('#slideshow').css('left', -(fw - wtouse) / 2) } //certer vertically
    jQuery('#slideshow').css('top', -(fh - wh) / 2) //certer horizontally

    jQuery('#slideshow img').height(fh).width(fw);

    jQuery('#cycleNav').not('.single').css('top', (wh - ah) / 2).width(wtouse);
 
    //resize main full div 
    if (wtouse <= 0) {
		jQuery('#main.ist').width(ww - (lw + pdlm))
		jQuery('#main.prodotti').width(ww - (lw + pdlm))
		jQuery('#main.scheda').width(ww - (lw + pdlm))
    } else {
		jQuery('#main.ist').width(contenutoIstituzionale)
		jQuery('#main.prodotti').width(contenutoProdotti)
		jQuery('#main.scheda').width(contenutoScheda)
    }
    jQuery('#main').css('min-height', wh - (pdcf*2))

}
