// JavaScript Document
//função redimensiona

function getPageScroll()
{

    var yScroll;
	
    if (self.pageYOffset)
    {
        yScroll = self.pageYOffset;
    }
    else if(document.documentElement && document.documentElement.scrollTop)
    { // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    }
    else if (document.body)
    {// all other Explorers
        yScroll = document.body.scrollTop;
    }
	
    arrayPageScroll = new Array('',yScroll)
	
    return arrayPageScroll;
}
	
function getPageSize()
{
	
    var xScroll, yScroll;
	
    if (window.innerHeight && window.scrollMaxY)
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else
    { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
	
    var windowWidth, windowHeight;
	
    if (self.innerHeight)
    { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
	
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight)
    {
        pageHeight = windowHeight;
    }
    else
    {
        pageHeight = yScroll;
    }
	
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth)
    {
        pageWidth = windowWidth - 18;
    }
    else
    {
        pageWidth = xScroll;
    }
	
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}

var Window =
{
    '_centralHeight': function(div)
    {//centraliza um um tamanho para centralizar o elemento
		
        var h = $('#'+div).height();
        var pageSize = getPageSize();
        var winY = pageSize[1];
        var y = (winY - h) / 2;
        return y;
    },
	
    '_centralWidth': function(div,divW,divH)
    {		
        var pageSize = getPageSize();
		
        var winW = pageSize[0];
		
        //menos a largura da div
        var w = (winW - divW) / 2;
		
        document.getElementById(div).style.left = w + 'px';		
    },
	
    '_open': function(div,divW,divH)
    {
        $.unblockUI();
        $.blockUI();
		
        var pageSize = getPageSize();
		
        var objScroll = getPageScroll();
        //alert(objScroll[1]);
		
        var winW = pageSize[0];
        var winY = pageSize[3];
		
        //menos a largura da div
        var w = (winW - divW) / 2;
        //menos a altura da div
        var y = objScroll[1] + ((winY - divH) / 2);
		
        //var y = objScroll[1] + 20;
        //alert(w);
        //alert(pageSize[3]);
		
        document.getElementById(div).style.left = w + 'px';
        document.getElementById(div).style.top = y + 'px';
        $("#"+div).width(divW);
        $("#"+div).height(divH);
        $("#"+div).show('slow');
        document.getElementById(div).style.display = 'block';
    },
	
    '_openCarrinho': function(div)
    {
		
        var pageSize = getPageSize();
		
        var objScroll = getPageScroll();
		
        //alert(objScroll[1]);
		
        var winW = pageSize[0];
        var winY = pageSize[1];
		
		
        //menos a largura da div
        var w = (winW - 905) / 2;
        //menos a altura da div
        var y = (winY - 490) / 2;
		
		
        /*if (objScroll[1] > 167)
			arr = (objScroll[1] - 167) + 'px';
		else
			arr = '0px';*/
			
        document.getElementById(div).style.left = w + 'px';
        //document.getElementById(div).style.top = y + 'px';
        document.getElementById(div).style.top = objScroll[1] + 'px';
		
        $('#'+div).show();
        $('#'+div).focus();
    },

    '_openDetalhe': function(div)
    {
        var pageSize = getPageSize();

        var objScroll = getPageScroll();

        //alert(objScroll[1]);

        var winW = pageSize[0];
        var winY = pageSize[1];


        //menos a largura da div
        var w = (winW - 505) / 2;
        //menos a altura da div
        var y = (winY - 202) / 2;


        /*if (objScroll[1] > 167)
			arr = (objScroll[1] - 167) + 'px';
		else
			arr = '0px';*/

        document.getElementById(div).style.left = w + 'px';
        //document.getElementById(div).style.top = y + 'px';
        document.getElementById(div).style.top = objScroll[1] + 'px';

        $('#'+div).show();
        $('#'+div).focus();
    },
	
    //sombra 1=mostra, 0=sem ação
    'gerFoto': function(div,divW,divH,sombra)
    {
        if(sombra == 1)
            $.blockUI();
		
        var pageSize = getPageSize();
		
        var objScroll = getPageScroll();
        //alert(objScroll[1]);
		
        var winW = pageSize[0];
        var winY = pageSize[1];
		
        //menos a largura da div
        var w = (winW - divW) / 2;
        //menos a altura da div
        var y = (winY - divH) / 2;
		
        //var y = objScroll[1] + 20;
        //alert(w);
        //alert(y);
		
        document.getElementById(div).style.left = w + 'px';
        document.getElementById(div).style.top = (objScroll[1] + 30) + 'px';
        $("#"+div).width(divW);
        $("#"+div).height(divH);
        $("#"+div).show('slow');
    //document.getElementById(div).style.display = 'block';
    },
	
    'openWin': function(url, name, w, h, s)
    {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+s+',resizable=no';
        //	winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes';
		
        win = window.open(url, name, winprops)
        if(parseInt(navigator.appVersion) >= 4)
        {
            win.window.focus();
        }
    },
	
	
    '_close': function(div)
    {
        /*document.getElementById(div).style.display='none';*/
        $("#"+div).hide('slow');
        $("#"+div).empty();
        $.unblockUI();
    },
	
    '_closeEffect': function(div)
    {
        /*document.getElementById(div).style.display='none';*/
        $("#"+div).hide(function(){
            $("#"+div).animate({
                left: 50,
                opacity: 1
            },"slow");
        });
        $("#"+div).empty();
        $.unblockUI();
    }
}

