﻿/*
  Mindefele ficsor, JS-el menon, web 2.0 project
*/
var ajax = new XSAJAX();
function checksite(url, id) {
  var check = new XSAJAX();
  check.ContentID = 'check'+id;
  check.Get('GET', url+id+'/?ajax=on');  
}
function mkaInit() {
  var bad = document.getElementsByTagName("body").item(0);
  var over = document.createElement("div");
  over.setAttribute("id","overlay");
  over.style.display = "none";
  var arrayPageSize = getPageSize();
  over.style.height = arrayPageSize[1]+"px";
  bad.appendChild(over);
  
  var content = document.createElement("div");
  content.setAttribute("id", "v2");
  content.style.visibility = "hidden";
  bad.appendChild(content);
  mkaToCenter($("v2"));
  
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function mkaResize(Height, Success) {
  if (Success == true) {
    $('v2').innerHTML = ajax.xmlhttp.responseText;
    return true;
  }
  var duration = 0.8;
  var originalHeight = $("v2").offsetHeight;
  var s = originalHeight;
  var i = 0;
  while (s <= Height) {
    setTimeout("$('v2').style.height = '"+(s+2)+"px'; mkaToCenter($('v2'));", i*2);
    i = i+1;
    s = s+2;
  }
  setTimeout("mkaResize('', true)", (i+18)*2);
}
function mkaToCenter(id) {
  var arrayPageSize = getPageSize();
  var szeles = document.body.clientWidth;
  var vastag = arrayPageSize[3];
  szeles  -= id.offsetWidth;
  szeles /= 2;
  vastag -= id.offsetHeight+100;
  vastag = vastag / 2;
  var scrollx = getScrollXY();
  vastag = vastag + scrollx[1];
  id.style.top = vastag+"px";
  id.style.left = szeles+"px";
}
function mkaLoad(site) {
  mkaToCenter($("v2"));
  $("v2").style.visibility = "visible";
  new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
  ajax.ContentID = 'v2';
  ajax.LoadingMSG = '<h2><!-- title --></h2><div id="v2content" style="text-align: center;">Pillanat, dolgozom.. <img src="/img/ajax-loader.gif" alt="Betöltés." /></div><div id="end"><!-- end --></div>';
  ajax.onSuccess = "setTimeout(\"$('v2').innerHTML = '<h2><!-- title --></h2><div id=v2content><!-- content --></div><div id=end><!-- end --></div>'; mkaResize(300);\", 500)";
  ajax.Get('GET', site+'?ajax=on');
}
function mkaClose() {
  $("v2").style.visibility = "hidden";
  new Effect.Fade('overlay', { duration: 0.2, from: 0.8, to: 0.0 });
  $("v2").style.height = "20px";
  $("v2").style.width = "620px";
  mkaToCenter($("v2"));
}
// thanks to Lightbox javascriptscript
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;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
// initalize the MKAvatar jscript
window.onload = mkaInit;