var ns4 = (document.layers)? true:false;
var nn6 = (!document.all && document.getElementById)? true:false;
var ie4 = (document.all)? true:false;

function posTop()
{
    return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function getPageSize(){
	
	var arrayPageSize = new Array();
	var xScroll, yScroll;
	var pageWidth = 0;
      var pageHeight = 0;
	
	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;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}





function doResize()
{
    var arrayPageSize = new Array();
    arrayPageSize = getPageSize();
    if (ns4)
    {
        document.layers['disablePage'].width = '100%';
        document.layers['disablePage'].height = '100%';
        document.layers['disablePage'].height = (arrayPageSize[1] + arrayPageSize[3]);
    }
    if (nn6)
    {
        document.getElementById('disablePage').style.width = '100%';
        document.getElementById('disablePage').style.height = '100%';
        document.getElementById('disablePage').style.height = (arrayPageSize[1]) + 'px';
    }
    if (ie4)
    {
        document.getElementById('disablePage').style.width = '100%';
        document.getElementById('disablePage').style.height = '100%';
        document.getElementById('disablePage').style.height = (arrayPageSize[1]);
    }
}

window.onresize = function()
{
    doResize();
};

function enable_menues_for_ie()
{
    if (document.all)
    {
        uls = document.getElementsByTagName('UL');

        for(i = 0; i < uls.length; i++)
        {
            if (uls[i].className == 'dropdown')
            {
                var lis = uls[i].getElementsByTagName('li');

                for (j = 0; j < lis.length; j++)
                {
                    if(lis[j].lastChild.tagName == 'UL')
                    {
                        lis[j].onmouseover = function() { this.lastChild.style.display = 'block'; }
                        lis[j].onmouseout = function() { this.lastChild.style.display = 'none'; }
                        lis[j].onclick = function() { this.lastChild.style.display = 'none'; }
                    }
                }
            }
        }
    }
}


window.onload = enable_menues_for_ie;

function dialogImgLoad()
{
    var im = document.images['dialogImg'];
    var dl = document.getElementById('dialogLoading');
    var dc = document.getElementById('dialogContent');
    var dbg = document.getElementById('dialogBackground');
    var body = document.body;
    var top = 0;

    dl.style.display='none';
    dc.style.display='block';

    dbg.style.height=im.height + 6;

    if (ns4)
    {
        if((window.innerHeight / 2 - (im.height / 2)) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - (im.height / 2));
        document.layers['dialogBox'].top = top;

        document.layers['dialogBox'].left = (body.offsetWidth / 2 - (im.width / 2));
        document.layers['dialogPanel'].width = (im.width + 6);
        document.layers['dialogBackground'].width = (im.width + 6);
        document.layers['dialogBackground'].height = (im.height + 6);
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - (im.height / 2)) <=0) top = 0;
        else top = (window.innerHeight / 2 - (im.height / 2));
        document.getElementById('dialogBox').style.top = (top + posTop()) + 'px';

        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (im.width / 2)) + 'px';
        document.getElementById('dialogPanel').style.width = (im.width + 6) + 'px';
        document.getElementById('dialogBackground').style.width = (im.width + 6) + 'px';
        document.getElementById('dialogBackground').style.height = (im.height + 6) + 'px';
    }
    if (ie4)
    {
        if((document.body.offsetHeight/2 - (im.height / 2)) <= 0) top = 0;
        else top = (document.body.offsetHeight/2 - (im.height / 2));
        document.getElementById('dialogBox').style.top = top + posTop();

        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (im.width / 2));
        document.getElementById('dialogPanel').style.width = (im.width + 6);
        document.getElementById('dialogBackground').style.width = (im.width + 6);
        document.getElementById('dialogBackground').style.height = (im.height + 6);
    }
    doResize();
}


function dialogShow(imge)
{
    var d = document.getElementById('dialogBox');
    var dl = document.getElementById('dialogLoading');
    var dc = document.getElementById('dialogContent');
    var im = document.images['dialogImg'];
    var body = document.body;

    var top = 0;

    if (ns4)
    {
        if((window.innerHeight / 2 - 300) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.layers['dialogBox'].top = top;
        document.layers['dialogBox'].left = (body.offsetWidth / 2 - (400));
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - 300) <=0) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.getElementById('dialogBox').style.top = (top + posTop()) + 'px';
        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (400)) + 'px';
    }
    if (ie4)
    {
        if((document.body.offsetHeight/2 - 300) <= 0) top = 0;
        else top = (document.body.offsetHeight/2 - 300);
        document.getElementById('dialogBox').style.top = top + posTop();
        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (400));
    }

    d.style.display='block';
    dl.style.display='block';
    dc.style.display='none';
    document.getElementById('disablePage').style.display='block';

    im.src=''+uri+'images/'+imge;

    doResize();
}

function dialogAbort()
{
    var d = document.getElementById('dialogBox');
    var im = document.images['dialogImg'];
    d.style.display='none';
    document.getElementById('disablePage').style.display='none';
    im.src=''+uri+'images/loading2.gif';

    if (ns4)
    {
        document.layers['dialogPanel'].width = 806;
        document.layers['dialogBackground'].width = 806;
        document.layers['dialogBackground'].height = 606;
    }
    if (nn6)
    {
        document.getElementById('dialogPanel').style.width = (800 + 6) + 'px';
        document.getElementById('dialogBackground').style.width = (800 + 6) + 'px';
        document.getElementById('dialogBackground').style.height = (600 + 6) + 'px';
    }
    if (ie4)
    {
        document.getElementById('dialogPanel').style.width = (800 + 6);
        document.getElementById('dialogBackground').style.width = (800 + 6);
        document.getElementById('dialogBackground').style.height = (600 + 6);
    }
}

/********************************************************************************************************************/


function dialogLoading()
{
    var d = document.getElementById('dialogBox');
    var dl = document.getElementById('dialogLoading');
    var dc = document.getElementById('dialogContent');
    var im = document.images['dialogImg'];
    var body = document.body;

    var top = 0;

    if (ns4)
    {
        if((window.innerHeight / 2 - 300) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.layers['dialogBox'].top = top;
        document.layers['dialogBox'].left = (body.offsetWidth / 2 - (400));
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - 300) <=0) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.getElementById('dialogBox').style.top = (top + posTop()) + 'px';
        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (400)) + 'px';
    }
    if (ie4)
    {
        if((document.body.offsetHeight/2 - 300) <= 0) top = 0;
        else top = (document.body.offsetHeight/2 - 300);
        document.getElementById('dialogBox').style.top = top + posTop();
        document.getElementById('dialogBox').style.left = (body.offsetWidth / 2 - (400));
    }

    d.style.display='block';
    dl.style.display='block';
    dc.style.display='none';
    document.getElementById('disablePage').style.display='block';

    doResize();
}


/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/
/*******************************************************************************************************************/



function dialogImgLoadPortfolio()
{
    var im = document.images['dialogImgPortfolio'];
    var dl = document.getElementById('dialogLoadingPortfolio');
    var dc = document.getElementById('dialogContentPortfolio');
    var dbg = document.getElementById('dialogBackgroundPortfolio');
    var body = document.body;
    var top = 0;
    
    var arrayPageSize = new Array();
    arrayPageSize = getPageSize();

    dl.style.display='none';
    dc.style.display='block';

    dbg.style.height=im.height + 6;

    if (ns4)
    {
        if((window.innerHeight / 2 - (im.height / 2)) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - (im.height / 2));
        document.layers['dialogBoxPortfolio'].top = top;

        document.layers['dialogBoxPortfolio'].left = (body.offsetWidth / 2 - (im.width / 2));
        document.layers['dialogPanelPortfolio'].width = (im.width + 6);
        document.layers['dialogBackgroundPortfolio'].width = (im.width + 6);
        document.layers['dialogBackgroundPortfolio'].height = (im.height + 6);
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - (im.height / 2)) <=0) top = 0;
        else top = (window.innerHeight / 2 - (im.height / 2));
        document.getElementById('dialogBoxPortfolio').style.top = (top + posTop()) + 'px';

        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (im.width / 2)) + 'px';
        document.getElementById('dialogPanelPortfolio').style.width = (im.width + 6) + 'px';
        document.getElementById('dialogBackgroundPortfolio').style.width = (im.width + 6) + 'px';
        document.getElementById('dialogBackgroundPortfolio').style.height = (im.height + 6) + 'px';
    }
    if (ie4)
    {
//        if((document.body.offsetHeight/2 - (im.height / 2)) <= 0) top = 0;
//        else top = (document.body.offsetHeight/2 - (im.height / 2));
        
        if((arrayPageSize[3] / 2 - (im.height / 2)) <= 0) top = 0;
        else top = (arrayPageSize[3] / 2 - (im.height / 2));
        
        document.getElementById('dialogBoxPortfolio').style.top = top + posTop();

        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (im.width / 2));
        document.getElementById('dialogPanelPortfolio').style.width = (im.width + 6);
        document.getElementById('dialogBackgroundPortfolio').style.width = (im.width + 6);
        document.getElementById('dialogBackgroundPortfolio').style.height = (im.height + 6);
    }
    doResize();
}


function dialogShowPortfolio(imge,offset,limit,lp)
{
    var d = document.getElementById('dialogBoxPortfolio');
    var dl = document.getElementById('dialogLoadingPortfolio');
    var dc = document.getElementById('dialogContentPortfolio');
    var im = document.images['dialogImgPortfolio'];
    var body = document.body;
    
    
    var arrayPageSize = new Array();
    arrayPageSize = getPageSize();

    var top = 0;

    if (ns4)
    {
        if((window.innerHeight / 2 - 300) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.layers['dialogBoxPortfolio'].top = top;
        document.layers['dialogBoxPortfolio'].left = (body.offsetWidth / 2 - (400));
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - 300) <=0) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.getElementById('dialogBoxPortfolio').style.top = (top + posTop()) + 'px';
        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (400)) + 'px';
    }
    if (ie4)
    {
//        if((document.body.offsetHeight / 2 - 300) <= 0) top = 0;
//        else top = (document.body.offsetHeight / 2 - 300);
        if((arrayPageSize[3] / 2 - 300) <= 0) top = 0;
        else top = (arrayPageSize[3] / 2 - 300);
//        top = (arrayPageSize[3] /2) - 300;
        document.getElementById('dialogBoxPortfolio').style.top = top + posTop();   // top +
        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (400));
    }

    d.style.display='block';
    dl.style.display='block';
    dc.style.display='none';
    document.getElementById('disablePage').style.display='block';

//    im.src=''+uri+'images/'+imge;

    doResize();
    xajax_portfolio(offset,limit,lp);
}

function dialogAbortPortfolio()
{
    var d = document.getElementById('dialogBoxPortfolio');
    var im = document.images['dialogImgPortfolio'];
    d.style.display='none';
    document.getElementById('disablePage').style.display='none';
    im.src=''+uri+'images/loading2.gif';

    if (ns4)
    {
        document.layers['dialogPanelPortfolio'].width = 806;
        document.layers['dialogBackgroundPortfolio'].width = 806;
        document.layers['dialogBackgroundPortfolio'].height = 606;
    }
    if (nn6)
    {
        document.getElementById('dialogPanelPortfolio').style.width = (800 + 6) + 'px';
        document.getElementById('dialogBackgroundPortfolio').style.width = (800 + 6) + 'px';
        document.getElementById('dialogBackgroundPortfolio').style.height = (600 + 6) + 'px';
    }
    if (ie4)
    {
        document.getElementById('dialogPanelPortfolio').style.width = (800 + 6);
        document.getElementById('dialogBackgroundPortfolio').style.width = (800 + 6);
        document.getElementById('dialogBackgroundPortfolio').style.height = (600 + 6);
    }
}

/********************************************************************************************************************/


function dialogLoadingPortfolio()
{
    var d = document.getElementById('dialogBoxPortfolio');
    var dl = document.getElementById('dialogLoadingPortfolio');
    var dc = document.getElementById('dialogContentPortfolio');
    var im = document.images['dialogImgPortfolio'];
    var body = document.body;

    var top = 0;

    if (ns4)
    {
        if((window.innerHeight / 2 - 300) <=0 ) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.layers['dialogBoxPortfolio'].top = top;
        document.layers['dialogBoxPortfolio'].left = (body.offsetWidth / 2 - (400));
    }
    if (nn6)
    {
        if((window.innerHeight / 2 - 300) <=0) top = 0;
        else top = (window.innerHeight / 2 - 300);
        document.getElementById('dialogBoxPortfolio').style.top = (top + posTop()) + 'px';
        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (400)) + 'px';
    }
    if (ie4)
    {
        if((document.body.offsetHeight/2 - 300) <= 0) top = 0;
        else top = (document.body.offsetHeight/2 - 300);
        document.getElementById('dialogBoxPortfolio').style.top = top + posTop();
        document.getElementById('dialogBoxPortfolio').style.left = (body.offsetWidth / 2 - (400));
    }

    d.style.display='block';
    dl.style.display='block';
    dc.style.display='none';
    document.getElementById('disablePage').style.display='block';

    doResize();
}

function portfolioJs(offset,limit,lp)
{
    var dl = document.getElementById('dialogLoadingPortfolio');
    var dc = document.getElementById('dialogContentPortfolio');
    dl.style.display='block';
    dc.style.display='none';
    
    xajax_portfolio(offset,limit,lp);
}


/***************************************************************************************************************/

function getFlash(flash,w,h)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'" id="menu_nawigacja_glowna_krakow" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="'+flash+'" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="bgcolor" value="#ffffff" />');
    document.write('<param name="wmode" value="transparent">');
    document.write('<param name="scale" value="scale" />');
    document.write('<param name="menu" value="false" />');
    document.write('<embed src="'+flash+'" menu="false" scale="scale" wmode="transparent" quality="high" width="'+w+'" height="'+h+'" name="menu_nawigacja_glowna_krakow" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}
