
onload = initMenu;
onresize = initMenu;

loadEventBinding( window, function() {
	initMenu;
	if ( !is.ie ) {
		document.getElementById( 'pg-text' ).style.height = getWindowDimension().height - 145 + 'px';
	}
	if( is.ie7 ) {
		var h = getPageSize()[3] - 40;
		var winheight = getPageSize()[3];
		var textheight = document.getElementById( 'pg-text' ).offsetHeight;

		if(textheight < winheight) {
			if ( document.getElementById( 'main-body' ) ) {
				document.getElementById( 'pg-text' ).style.height = h + 131 + 'px';
			}
			else {
				document.getElementById( 'pg-text' ).style.height = h + 'px';
			}
		}
		else {
			if ( document.getElementById( 'main-body' ) ) {
				document.getElementById( 'pg-text' ).style.height = textheight + 131 + 'px';
			}
		}
	}
} );

resizeEventBinding( true, function() {
	initMenu
	if ( !is.ie ) {
		document.getElementById( 'pg-text' ).style.height = getWindowDimension().height - 145 + 'px';
	}
	if( is.ie7 ) {
		var h = getPageSize()[3] - 40;
		var winheight = getPageSize()[3];
		var textheight = document.getElementById( 'pg-text' ).offsetHeight;
		if(textheight < winheight)
			document.getElementById( 'pg-text' ).style.height = h + 'px';
	}
	
	
});

function initMenu() {
	if ( is.opera ) {
		getViewport();
		mainWidth = document.getElementById('pg-main').offsetWidth;
		num = (window.strictInnerWidth-mainWidth) / 2;
		//alert(num);
		if ( num <= 0 ) num = 0;
		document.getElementById('pg-menu').style.left = num + "px";
	}
}

function pictureWiever( elImg ) { // elImg lehet elLink is!
	var oPending, sPath, sSrc, sTitle, winImage = null, oImage = null, bResize;
	if ( !is.min ) return false;
	if ( elImg.bPending ) // ha folyamatban van, visszadob
		return false;
	elImg.bPending = true;
	elImg.elType = ( isSpecified( elImg, 'src' ) ) ? 'image' : 'link';

	/* config */
	oPending = {                                // folyamat-felirat
		backgroundColor : 'rgb(88, 129, 181)',
		color : 'white',
		padding : '2px 20px 2px 20px',
		margin : '10px',
		fontSize : '12px',
		fontFamily : 'Arial, Helvetica, sans-serif',
		text : 'töltés... '
	}
	sPath = 'big/';                                 // a nagy képek általános könyvtára, felüldefiniálása path="" attribútummal
	sPageTitle = 'www.eastinfo.hu';                      // az megnyiló ablak címe
	sPrintIconURL = 'image/printer.gif';                    // a print icon elérése
	bResize = true;                                         // engedélyezett-e az ablak átméretezése képenyőnél nagyobb kép esetén
	function initPage( oImage ) {
		var aCSS = [], aHTMLPage = [], nLeft = 0, nTop = 0, nWidth, nHeight, nInnerWidth, nInnerHeight, sScrollbars, sResizable, sSettings, bRealResize ; 
		// CSS beállítások
		aCSS[aCSS.length] = 'BODY { margin: 0px; padding: 0px; background-color: white; color: black }';
		aCSS[aCSS.length] = 'P { font-family : "Times New Roman", Times, serif; font-size : 14px; color: #A31000;font-size : 16px; color: #A31000; font-weight : bold; }';
		aCSS[aCSS.length] = 'IMG{ border: 0px; }';
		aCSS[aCSS.length] = 'DIV#pg-title { position: ' + ( ( is.ie ) ? 'absolute' : 'fixed' ) + '; left: 10px; top: 10px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(88, 129, 181); color: white; padding: 2px 10px 2px 10px; }';
		aCSS[aCSS.length] = 'DIV#pg-print { position: ' + ( ( is.ie ) ? 'absolute' : 'fixed' ) + '; right: 10px; top: 10px; display: none }';
		// HTML beállítások
		aHTMLPage[aHTMLPage.length] = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
		aHTMLPage[aHTMLPage.length] = '<html><head><title>' + sPageTitle + '</title><style>' 
		aHTMLPage[aHTMLPage.length] = aCSS.join('\n');
		aHTMLPage[aHTMLPage.length] = '</style>';
		aHTMLPage[aHTMLPage.length] = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />';
		aHTMLPage[aHTMLPage.length] = '<link rel="up" href="menu_halas_turi.html" id="pg-menupage-link" />';
		aHTMLPage[aHTMLPage.length] = '</head>';
		aHTMLPage[aHTMLPage.length] = '<body>';                           
		if ( sTitle != '' )
			aHTMLPage[aHTMLPage.length] = '<div id="pg-title">' + sTitle + '</div>';
		aHTMLPage[aHTMLPage.length] = '<div id="pg-print"><a href="javascript:window.print()"><img src="' + sPrintIconURL + '" border="0"></a></div>';
		aHTMLPage[aHTMLPage.length] = '<a href="javascript:window.close();" hidefocus><img src="' + sSrc + '" border="0"></a>';
		aHTMLPage[aHTMLPage.length] = '</body></html>';    
		/* /config */

		bRealResize = ( bResize && ( ( window.screen.width <= oImage.width * 1.1 ) || ( window.screen.height <= oImage.height * 1.1 ) ) ) ? true : false;
		if ( is.ie5mac ) { // hibásan adja vissza minden esetben a kép méreteinek értékét (1px)
		 	oImage.width = 400;
		 	oImage.height = 400;
		};
		nLeft = ( !bRealResize ) ? Math.round( ( window.screen.width - oImage.width ) / 2 ) : 0;
		nTop = ( !bRealResize ) ? Math.round( ( window.screen.height - oImage.height ) / 3 ) : 0;
		nInnerWidth = parseInt( oImage.width );
		nInnerHeight = parseInt( oImage.height );
		sScrollbars = 'no';
		sResizable = 'no';
		if ( bRealResize ) {
			sScrollbars = 'yes';
			sResizable = 'yes';
			nInnerWidth =  Math.round( window.screen.width * 0.97 ); // 0.9
			nInnerHeight = Math.round( window.screen.height * 0.90 ); // 0.9
		};
		if ( is.ie5mac ) { 
			sScrollbars = 'yes';
			sResizable = 'yes';
		};
		nWidth = nInnerWidth; // + 12;
		nHeight = nInnerHeight; // + 30;
		sSettings = 'height=' + nHeight +',width=' + nWidth + ',innerWidth=' + nInnerWidth + ',innerHeight=' + nInnerHeight + ',top=' + nTop + ',left=' + nLeft + ',scrollbars=' + sScrollbars +  ',resizable=' + sResizable;
		winImage = window.open( '', '', sSettings);
		winImage.document.open( 'text/html' );
		winImage.document.write( aHTMLPage.join('\n') );
		winImage.document.close();
		// folyamat-felirat eltávolítása		
		elImg.bPending = false;
		if ( elImg.elType == 'image' )
			document.body.removeChild( elImg.elPending );
	}
	// adatok átvétele;
	sTitle = elImg.getAttribute('alt') || elImg.getAttribute('title') || '';
	if ( elImg.elType == 'link' )
		elImg.src = elImg.href;
	if ( isSpecified( elImg, 'resize' )  )
		bResize =  new Boolean( elImg.getAttribute('resize') );
	if ( isSpecified( elImg, 'path' ) )
		sSrc = elImg.getAttribute('path') + elImg.src.substr( elImg.src.lastIndexOf('/') + 1, elImg.src.length )
	else 
		sSrc = elImg.src.substr( 0, elImg.src.lastIndexOf('/') + 1 ) + elImg.src.substr( elImg.src.lastIndexOf('/') + 1, elImg.src.length - 8 - elImg.src.lastIndexOf('/') ) + ".jpg";
	// folyamat-felirat készítése
	if ( elImg.elType == 'image' ) {
		createFullOffset( elImg );
		elPending = document.createElement( 'div' );
		elPending.style.position = 'absolute';
		elPending.style.zIndex = '150';
		elPending.style.left = elImg.offsetX + 'px';
		elPending.style.top = elImg.offsetY + 'px';
		elPending.style.margin = oPending.margin;
		elPending.style.padding = oPending.padding;
		elPending.style.color = oPending.color;
		elPending.style.fontSize = oPending.fontSize;
		elPending.style.fontFamily = oPending.fontFamily;
		elPending.style.backgroundColor = oPending.backgroundColor;
		elPending.appendChild( document.createTextNode( oPending.text + sTitle ) );
		elImg.elPending = elPending;
		document.body.appendChild( elPending );
	}
	// kép letöltése és inicializáció indítása
	oImage = new Image();
	oImage.src = sSrc;
	if ( oImage.complete ) {
		initPage( oImage );
	}
	else {
		oImage.onload = function () {
			initPage( this )
		};
	};
	return false;
};

/**
 * @return		arrayPageSize 	az oldal szélességével, magasságával, ill. az ablak szélességével és magasságával tér vissza.
 * Core code from - quirksmode.com
 * Edit for Firefox by pHaez
 */

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

