var margL;

addEvent(window, "load", Initialize);

function addEvent(obj, eType, func) {
  if (obj.addEventListener) obj.addEventListener(eType, func, false);
  else if (obj.attachEvent) obj.attachEvent('on' + eType, func);
  else obj['on' + eType] = func;
}

load = function(filename) {
	load.getScript(filename);
  load.tryReady(0);
};

load.getScript = function(filename) {
  var script = document.createElement('script');
  script.setAttribute("type","text/javascript");
  script.setAttribute("src", filename);
  if (typeof script!="undefined")
  document.getElementsByTagName("head")[0].appendChild(script);
};

load.tryReady = function(time_elapsed) {
	
  if (typeof $ == "undefined") { 
    if (time_elapsed <= 5000) { 
      setTimeout("load.tryReady(" + (time_elapsed + 200) + ")", 200);
    } else {
      alert("Timed out while loading jQuery.");
    }
  } else {
  $("body").fadeIn(2000);
  if (document.getElementById("submenu")){
  		$.getScript("jquery.effects.core.js", function(){
  		$("#goTop").hide();
  		$.getScript("jquery.scrollTo-1.4.2-min.js", function(){
  			$("#submenu li a").click(function(){
  				$("#submenu li").hide();
  				var item = '#' + $(this).attr("id") + 'p';
  				var oSet = $(item).offset();
  				$.scrollTo(item,{speed: 1000, easing:'easeOutExpo'});
  				if (oSet.top > 475) $("#submenu").css("marginTop", (oSet.top-325));
  				else $("#submenu").css("marginTop", (oSet.top-235));
					$("#submenu li:first").delay(1000).fadeIn(60, function showIt(){
						$(this).next().fadeIn(20, showIt);
					});
					$("#goTop").css("marginTop", oSet.top-205);
					$("#goTop").fadeIn(2000);
					
					$("#goTop").click(function(){
						$("#submenu li").hide();
		    		$("html, body").animate({scrollTop : 0, easing: 'easeOutExpo'}, "slow", function(){
		    			$("#goTop").hide();
		    			$("#submenu").css("marginTop", 0);
		    			$("#submenu li:first").delay(200).fadeIn(60, function showIt(){
								$(this).next().fadeIn(20, showIt);
							});
		    		});
		    	});
  			});
  		});
  	});
  	$("#submenu li:first").fadeIn(60, function showSub() {  		
  		$(this).next().fadeIn(20, showSub);
  	});
  }
  else{
  	$.getScript("jquery.effects.core.js", function(){
  		$.getScript("jquery.effects.slide.js", function(){
  				$("#menu").animate({left: margL + 270,opacity:"slide"}, 500, "easeOutCubic", function showNews(){
	  				$("li:first").fadeIn("fast").delay(5000).fadeOut("fast", function fader(){
	  			  	$(this).next().fadeIn("fast").delay(5000).fadeOut("fast", fader);
	  			  	if ($(this).attr("id") == "last") $("li:first").fadeIn("fast").delay(7000).fadeOut("fast", fader);
	  			  });
  				});
    	});
  	});
  }
  };
  };
  


function Initialize(){
  margL = (screen.width) ? (screen.width-950)/2 : (document.documentElement.offsetWidth - 950)/2;
	if (screen.width < 900) document.getElementById('content').style.width = '600px';
	if (location.href.indexOf('index.html') == -1) document.getElementById('menu').style.left = String(margL + 270) + 'px';
	load("jquery-1.7.min.js");
	document.getElementById('content').style.height = String(document.getElementById('copyright').offsetTop - 130) + "px";
	var elem = document.getElementById('leftpanel'); 
	elem.style.height = String(document.getElementById('copyright').offsetTop -50) + "px";
	elem.style.marginLeft = String(margL-30) + "px";
	var relelem = document.getElementById('topnews');
	relelem.style.marginLeft = String(margL-30) + "px";
	if (relelem.offsetLeft < elem.offsetLeft){
		// for IE7
		elem.style.marginLeft = String(margL-30-(elem.offsetLeft - relelem.offsetLeft)) + "px";
		elem.style.height = String(document.getElementById('copyright').offsetTop + 165) + "px";
		var conelem = document.getElementById('content');
		conelem.style.height = String(document.getElementById('copyright').offsetTop + 85) + "px";
		document.getElementById('header').style.marginLeft = String(margL-(140*margL/165)) + "px";
	} 
	else {
		document.getElementById('content').style.marginLeft = String(230 + margL - 30) + "px";
		document.getElementById('header').style.marginLeft = String(margL-20) + "px";
	}
	var elements = document.getElementsByTagName("a");
  for(i=0; i<= elements.length-1; i++)
  	addEvent(elements[i], 'click', OnLinkClick);
}

function OnLinkClick(e){
	theLink = '';
	if (!e)  e = event;
  if (e.target.id){
    if (e.target.id.toString().indexOf('out', 0) > 0) theLink = e.target.id;
  }
  else
    if (e.srcElement.id.toString().indexOf('out', 0) > 0) theLink = e.srcElement.id;
	switch (theLink) {
	  case 'liskaland_out' :  open('http://liskaland.hu'); break;
	  case 'modell_out'    : open('http://liskatibor.extra.hu/irodalom.htm'); break;
	  case 'irodalom_out'  : open('http://liskatibor.extra.hu/irodalom.htm'); break;
	  case 'spi_out'       : open('http://www.spi.hu'); break;
	  case 'forras_out'    : open('http://www.forras.hu'); break;
	  case 'online_out'    : open('http://www.online.hu'); break;
	  case 'stab_out'      : open('http://www.stabfilm.hu'); break;
	  case 'lib_out'       : open('http://www.lib.hu/newlib/index.php'); break;
	  case 'dircon_out'    : open('http://www.dircon.hu'); break;
	  case 'gpit_out'      : open('http://www.gpit.eu'); break;
	  case 'LLand_out'     : open('http://liskaland.hu/tamogatok/'); break;
	  case 'map_out'       : open('http://maps.google.com/maps?f=q&source=s_q&hl=hu&geocode=&q=liska+m%C5%B1vek&ie=UTF8&hq=liska+m%C5%B1vek&hnear=&ll=47.469182,19.053791&spn=0.009066,0.016544&z=16&iwloc=A'); break;  
	  default: break;
}
}



