var pos = 0;
var width;
var sliderWidth;
function moveReferenceBox(to) {
  if(to == "left") {
    if(pos < 0) {
      pos+=4;
      $(".reference-box-content>div").css("margin-left",pos)
    }
  }
  else {
    if(pos >= sliderWidth-width) {
      pos-=4;
      $(".reference-box-content>div").css("margin-left",pos)			
    }
  }
}

function langVisible(aktlang){
	$("div.lang a").each(function(){
		var $this = $(this);
		if($this.attr("id") !== aktlang) $this.css("display","inline");
	});
}
		
$(document).ready(function() {
  sliderWidth = $(".reference-box-content").width();
  width = 0;
  $(".reference-box-content img").each(function(){width += $(this).width()+1;});
  $("#menu > ul > li").each(function() {
    var name = $("a",this).attr("class");	
    var pos = $(this).offset().left;
    $("ul",this).css("left",pos+"px");
    $(this).hover(
      function() {
        $("ul",this).css("display","block");
        $("a",this).css("background-position","0px -46px");
      },
      function() {
        $("ul",this).css("display","none");
        $("a",this).css("background-position","0px 0px");
    });
  });

  var moveInterval;
  $(".reference-box-stepper .stepper").hover(
    function() {
      if($(this).attr("id") == "step-left") {
        moveInterval = setInterval("moveReferenceBox('left')",40);				
      }
      else {
        moveInterval = setInterval("moveReferenceBox('right')",40);				
      }
    },
    function(){
        clearInterval(moveInterval);
    }
  );

  //PRINT linkek kirakasa
  $("div.title-actions a.print").click(function(){
     printPage();
     return false;
  });

  //SEND linkek kirakasa
  $("div.title-actions a.send").click(function(){
     sendPage();
     return false;
  });
  
  //Kereses linkek  kirakasa
  $("div.search a").click(function(){
  	return keress($(this).prev().val());
  });
  $("div.search input").keypress(function(e){
	if(e.which == 47) return false;
  	if(e.which == 13) {
  		keress($(this).val());
  		return false;
  	}
  });
  
  //Nyelvvalaszto gombokra linkek rarakasa
  $("div.lang a").click(function(){
  	var $this = $(this);
  	var lang = $this.attr("id").substr(5,2);
  	var reg = new RegExp("^"+LANG_URL);
  	if(lang == "en") window.location = URI.replace(reg,"");
  	else window.location = URI.replace(reg,"/"+lang);
  });
})

    
	
function replaceHeaders(){
  window.print_content = $("#content").html();
	var h1 = document.getElementsByTagName("h1");
	for (var i=h1.length-1; i>=0; i--){
		var parent = h1[i].parentNode;
		var type = parent.className.split("_");
		if(type[0] == "flash"){
			var so = new SWFObject("/images/flash/headerBox_H1.swf", "headerBox_"+i, "100%", "33", "8", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("txt",h1[i].innerHTML);
			so.addVariable("type",type[1]);
			var node = document.createElement('div');
			node.setAttribute("id","flashHolder_"+i);
			node.appendChild(h1[i].cloneNode(true));
			parent.replaceChild(node,h1[i]);
			so.write("flashHolder_"+i);
		}
	}
	var h2 = document.getElementsByTagName("h2");	
	for (var j=h2.length-1; j>=0; j--){
		var parent = h2[j].parentNode;
		var type = h2[j].className.split("_");
		if(type[1] == "fl"){
			var so = new SWFObject("/images/flash/headerBox_H2.swf", "headerBox_"+j, "100%", "33", "8", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("txt",h2[j].innerHTML);
			so.addVariable("type",type[1]);
			var node = document.createElement('div');
			node.setAttribute("id","flashHolder2_"+j);
			node.appendChild(h2[j].cloneNode(true));
			parent.replaceChild(node,h2[j]);
			so.write("flashHolder2_"+j);
		}
	}
}
