function find(id)
{
	if (document.getElementById)
	{
	  	return(document.getElementById(id));
	}
	else if (document.all)
	{
		return(document.all[id]);
	}
	else if (document.layers)
	{
		return(document.layers[id]);
	}
	return(null);	
}
var SEL_MENU = 0;
var CODICE = null;
function sub_menu(i){
	
	if(CODICE == 'home'){ return; }
	//alert($('.sub_box').size())
	if(SEL_MENU){	
		
		$('#box_'+SEL_MENU).animate({
			height: '4px'
			},200,function() { 
				$(this).css('background','#FFFFFF');
				//$('#sub_box_'+SEL_MENU+' .sub_titolo').css({"border-bottom": "1px solid #FFFFFF"});
				}  
			) 			
		//return	
		$('#sub_box_'+SEL_MENU).animate({
			marginTop: '0px'
			},200);

		$('#sub_box_'+SEL_MENU).css("background", "");

		if(SEL_MENU == i){ 
			SEL_MENU = ''; 
			return; 
		}	
	}
		SEL_MENU = i;		
		$('#box_'+i).animate({
			height: '131px'
			},200).css('background','none');
		//return	
		$('#sub_box_'+SEL_MENU).css({"background": "#f0ece8"});
		//$('#sub_box_'+SEL_MENU+' .sub_titolo').css({"border-bottom": "0"});
		
		$('#sub_box_'+i).animate({
			marginTop: '-140px'
			},200);
	
}
function init_scroll(id_scroll){
	//scroller di pagina
	var PANNELLO = $(id_scroll); //alert(PANNELLO.size())
	
	//if(PANNELLO.size()){
		PANNELLO.jScrollPane({
			showArrows:true,
			scrollbarWidth: 9,
			arrowSize: 10
		});
	//}
}
/* collezioni */
var widthDivContainer = -1;
var widthDivExt = -1;
var widthDivCentral = 609;
var root = null;
var ADivImage = null;

function init2()
{
    setParameterDiv();

    if(ADivImage!=null) {
        //crea lista circolare di foto
        root = new createDivImg(0,ADivImage[0][1]);
        var html = root.draw();
        for(var i=1;i<ADivImage.length;++i) {
            var nodo = new createDivImg(i,ADivImage[i][1]);
            root.right = nodo;
            nodo.left = root;
            root = nodo;
            html += nodo.draw();
        }

        find("div_container_variable").innerHTML = html;
        var nodo = root;
        while(root.left!=null)
            root = root.left;

        nodo.right = root;
        root.left = nodo;
        //lista circolare creata con successo

        //posizionamento dei nodi
        root.div = find("img0").style;
        root.div.left = widthDivExt+"px";
        nodo = root.left;
        var x = widthDivExt - widthDivCentral;
        var i=ADivImage.length-1;
        while(nodo != root)
        {
            nodo.div= find("img"+i).style;
            nodo.div.left = x+"px";
            x -= widthDivCentral;
            nodo = nodo.left;
            --i;
        }

        x = (widthDivExt + widthDivCentral);
        root.right.div.left = x+"px";
    }
}

function setParameterDiv()
{
    var obj = find("div_container");
    if(obj)
    {
        widthDivContainer = getBodyWidth();
        widthDivExt = (widthDivContainer - widthDivCentral)/2;
        find("div_container_variable").style.width = widthDivContainer+"px";
        obj.style.width = widthDivContainer+"px";
        find("div_left").style.width = widthDivExt+"px";
        obj =  find("div_right").style;
        obj.width = widthDivExt+"px";
        obj.left =  (widthDivExt + widthDivCentral)+"px";

        if(root != null)
        {
            root.div.left = widthDivExt+"px";
            root.left.div.left = (widthDivExt - widthDivCentral)+"px";
            root.right.div.left = (widthDivExt + widthDivCentral)+"px";
        }
    }
}

function getBodyWidth()
{
	if(parseInt(navigator.appVersion)>3)
	{
		if(navigator.appName == "Netscape")
		{
			return(window.innerWidth);
		}

		if(navigator.appName.indexOf("Microsoft")!=-1)
		{
            return(document.body.offsetWidth);
		}
	}
}


function createDivImg(idx,srcimg) { 
    this.div = null;
    this.left = null;
    this.right = null;
    this.id = idx;

    this.draw = function()
    {
        var hdiv  = "<div id='img"+idx+"' ";
		hdiv += "style='position:absolute; left:0px; top:0px; width:"+widthDivCentral+"px; height:385px; '>";
        hdiv += "<a id='tumb_"+idx+"' ";
		hdiv += " href='../../collezioni/swf/abito" + (idx+1) + ".swf' ";
		hdiv += " onclick='showLightbox(this,"+idx+");return false;'>"
		hdiv += "<img src='"+srcimg+"' border='0' width='609' height='385' /></a>";
        hdiv += "</div>";
        return hdiv;
    }


    return(this);
}
function res_lightbox(){
	
	var objLightbox = document.getElementById('lightbox');
	if(objLightbox){
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();		
		//var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 482) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - 971) / 2);
		//objLightbox.style.background = '#FFFFFF';  
		
		//posiziona il layer centrale		
		//objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px"; 
		objLightbox.style.top = "115px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";	
		//objLightbox.style.width = 971 + 'px';
	}
}
