addLoadListener(loadMusicTop);
addLoadListener(loadNowPlaying);


function openWindow(URL, title, features){
  window.open(URL, title, features);
}

function none(){
}


function addLoadListener(fn)
{
  if(typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if(typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if(typeof window.attachEvent != 'undefined')    
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if(typeof window.onload != 'function')
	{
	  window.onload = fn;
	}
    else
	{
      window.onload = function(){oldfn();fn();}
    }
  }
} 



function loadNowPlaying()
{
  document.getElementById('mostJatsszukContent').innerHTML = '<img src="images/ajax-loader.gif" style="margin-left: 100px; margin-top: 5px;" />';
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/ajax/most_jatsszuk.php', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('mostJatsszukContent').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  setTimeout("loadNowPlaying()", 60000);
  return true; 
}


function loadMusicTop(topListType)
{
  if (document.getElementById('musicTopContent') != null)
  {
    topListType = String(topListType);
    if (topListType == "" || topListType == null || topListType == '[object Event]' || topListType == '[object]') topListType = 'top20';
    document.getElementById('musicTopContent').innerHTML = '<img src="images/ajax-loader2.gif" style="margin-left: 70px; margin-top: 60px;" />';
    var xhr;
    try 
    {
	  xhr = new XMLHttpRequest();
    } catch (error)
    {
	  try
	  {
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	  } catch (error)
	  {
		  xhr = null;
	  }
    }

    if (xhr != null)
    {
	  xhr.open('GET', 'includes/ajax/music_top.php?type=' + topListType, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('musicTopContent').innerHTML = xhr.responseText;
				  top20Image = (topListType == 'top20') ? 'images/musictop_top20_white.gif' : 'images/musictop_top20_grey.gif';
				  trambulinImage = (topListType == 'trambulin') ? 'images/musictop_trambulin_white.gif' : 'images/musictop_trambulin_grey.gif';
				  document.getElementById('musicTopTop20').src = top20Image;
				  document.getElementById('musicTopTrambulin').src = trambulinImage;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
    }
    return true; 
  }
}


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;
	
  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;
  }
	
  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){	
  	pageWidth = xScroll;		
  } else {
	pageWidth = windowWidth;
  }

  return [pageWidth,pageHeight];
}


function getScrollPosition()
{
  var ScrollTop = document.body.scrollTop;
  if (ScrollTop == 0)
  {
    if (window.pageYOffset)
      ScrollTop = window.pageYOffset;
    else
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
  }
  return ScrollTop;
}


function setOpacity(object, opacity) 
{
	if(object){
		object.style.opacity = (opacity == 1 ? 0.99 : opacity);
		object.style.MozOpacity = (opacity == 1 ? 0.99 : opacity);
		object.style.KhtmlOpacity = opacity;
		if (object.style.setAttribute) {
			if(opacity==1){
				object.style.setAttribute("filter","");
			}else{
				object.style.setAttribute("filter",  "progid:DXImageTransform.Microsoft.Alpha(opacity=" + (opacity * 100) + ")");
			}
		}
	}
}




	
function getOpacity(object)
{
	if(object){
		if(object.style.display == 'none')
			return 0;
		if(object.style.opacity)
			return parseFloat(object.style.opacity);
		if(object.style.MozOpacity)
			return parseFloat(object.style.MozOpacity);
		if(object.style.KhtmlOpacity)
			return parseFloat(object.style.KhtmlOpacity);
		if(object.style.filter){
			var opacity = object.style.filter.match(/alpha\(opacity=(.*)\)/i);
			if(opacity[1]) return parseFloat(opacity[1]) / 100;
		}
	}
	return 1.0;
}


function fadeOut(obj, opacity){
	var object = document.getElementById(obj);
	if (opacity > -0.1)
	{
		setOpacity(object, opacity);
		var fString = "fadeOut('" + obj + "', " + (opacity - 0.05) + ")";
		setTimeout(fString, 20);
	}else
	{
		setOpacity(object, 0);
		object.style.display = 'none';
	}
}

function fadeOutTimed(obj, opacity, time){
	var object = document.getElementById(obj);
	if (opacity > -0.1)
	{
		setOpacity(object, opacity);
		var fString = "fadeOut('" + obj + "', " + (opacity - 0.5) + ", " + time + ")";
		setTimeout(fString, time);
	}else
	{
		setOpacity(object, 0);
		object.style.display = 'none';
	}
}


function fadeIn(obj, opacity){
	var object = document.getElementById(obj);
	if (opacity < 1.1)
	{
		setOpacity(object, opacity);
		var fString = "fadeIn('" + obj + "', " + (opacity + 0.05) + ")";
		setTimeout(fString, 20);
	}else
	{
		setOpacity(object, 1);
	}
}


function fadeInScreen(obj, opacity, time){
	var object = document.getElementById(obj);
	if (opacity < 0.6)
	{
		setOpacity(object, opacity);
		var fString = "fadeInScreen('" + obj + "', " + (opacity + 0.1) + ", " + time + ")";
		setTimeout(fString, time);
	}else
	{
		setOpacity(object, 0.55);
		document.getElementById('dimImage').style.display = 'block';
		//fadeInTimed('mainNewsImage', 0, 0);
	}
}


function fadeInTimed(obj, opacity, time){
	var object = document.getElementById(obj);
	if (opacity < 1.1)
	{
		setOpacity(object, opacity);
		var fString = "fadeIn('" + obj + "', " + (opacity + 0.2) + ", " + time + ")";
		setTimeout(fString, time);
	}else
	{
		setOpacity(object, 1);
	}
}


function dimScreen()
{
	pageSize = getPageSize();
	document.getElementById('dimScreen').style.width = pageSize[0] + 'px';
	document.getElementById('dimScreen').style.height = '1600px';
	document.getElementById('dimScreen').style.display = 'block';
	document.getElementById('dimImage').style.left = ((pageSize[0] / 2) - 285) + 'px';
	document.getElementById('dimImage').style.top = (getScrollPosition() + 30) + 'px';
	//setOpacity(document.getElementById('mainNewsImage'), 0);
	//document.getElementById('mainNewsImage').style.display = 'block';
	fadeInScreen('dimScreen', 0, 0);
	//fadeInTimed('dimImage', 0, 0);
	//setOpacity(document.getElementById('dimScreen'), 1);
}

function unDimScreen()
{
	//document.getElementById('dimScreen').style.display = 'none';
	document.getElementById('dimImage').style.display = 'none';
	//document.getElementById('mainNewsImage').style.display = 'none';
	fadeOutTimed('dimScreen', 0.55, 0);
}


function showRecipe(id)
{
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/ajax/show_recipe.php?recipe_id=' + id, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('dimText').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  dimScreen();
  return true; 
}


function showPRAngyalImage(text, image)
{
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/ajax/show_prangyal_kep.php?text=' + text + '&image=' + image, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('dimText').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  dimScreen();
  return true; 
}