function g(id){
	return document.getElementById(id);
}

function updateSize(){
	height = document.getElementById("main-content").offsetHeight;
	alongerHeight = document.getElementById("main-center").offsetHeight;
	if(height >= alongerHeight){
		height = ((height-13) - ((height-13)%224))+224+12;
		document.getElementById("main-center").style.height = height+"px";
		document.getElementById("main-left-spacer").style.display = "block";
		document.getElementById("main-right-spacer").style.display = "block";
		document.getElementById("main-left-spacer").style.height = (height-909)+"px";
		document.getElementById("main-right-spacer").style.height = (height-909)+"px";
	}
}

function bodyOnLoad(){
	updateSize();
}

var guestReplyButton = false;
var guestMessageBackup = "";
var guestReplyButtonColor = false;
function replyTo(button, id, username){
	if(guestReplyButton == button){
		button.style.backgroundColor = guestReplyButtonColor;
		g("guestMessage").innerHTML = guestMessageBackup;
		guestReplyButton = false;
		g("guestParent").value = 0;
		return;
	}
	
	if(guestMessageBackup == false)
		guestMessageBackup = g("guestMessage").innerHTML;

	g("guestMessage").innerHTML = "Odpověď na zprávu od uživatele <b>"+username+"</b>";
	g("guestParent").value = id;

	if(guestReplyButton!=false)
		guestReplyButton.style.backgroundColor=button.style.backgroundColor;
	
	guestReplyButtonColor = button.style.backgroundColor;
	guestReplyButton = button;
	button.style.backgroundColor = "red";
}

function ImageMap(div, map, img) {
   //Contructor
   this.div = g(div);
   this.map = g(map);
   this.img = new Image();
   this.img.src = img;
   
   this.areas = new Array();
   this.areasCount = 0;

   this.map.innerHTML="";
   
   function ImageMapItem(image){
      this.image = image;
      this.dir = 0;
      this.timer = 0;
      this.opacity = 0;
   }
   
   this.addArea = function (shape, coords, href){
      var element = document.createElement( "AREA" );
      element.shape = shape;
      element.coords = coords[0]+","+coords[1]+" "+coords[2]+","+coords[3];
      element.href= href;
      var count = this.areasCount;
      element.onmouseover = function() { eval( "menuMap.mouseOver("+count+", true)" ); };
      element.onmouseout = function() { eval( "menuMap.mouseOver("+count+", false)" ); };
      this.map.appendChild( element );
      
      var link = document.createElement( "A" );
      link.href=href;
      var image = document.createElement( "IMG" );
      image.src = this.img.src;
      image.className = "menuImage";
      image.style.opacity = 0;
      image.style.filter = "alpha(opacity=0)";
      image.style.display="none";
      image.style.clip="rect("+coords[1]+"px "+coords[2]+"px "+coords[3]+"px "+coords[0]+"px)";
      image.onmouseout = function() { eval( "menuMap.mouseOver("+count+", false)" ); };
      image.onmouseover = function() { eval( "menuMap.mouseOver("+count+", true)" ); };
      link.appendChild( image );
      this.div.appendChild( link );
      this.areas.push(new ImageMapItem(image));
      this.areasCount++;
   }
   
   this.mouseOver = function(id, dir){
      this.areas[id].dir = (dir)?1:-1;
      this.areas[id].image.style.display="block";
      if(this.areas[id].timer == 0)
         this.areas[id].timer = setInterval( "menuMap.timerFunction("+id+")", 50);
   }
   
   this.timerFunction = function(id){
      //this.areas[id].image.style.display=((dir)?"block":"none");
      this.areas[id].opacity += parseFloat(this.areas[id].dir * 0.2);
      this.areas[id].image.style.opacity = this.areas[id].opacity;
      this.areas[id].image.style.filter = "alpha(opacity="+Math.round(this.areas[id].opacity*100)+")";
      //;filter:alpha(opacity=40)
      if(this.areas[id].opacity <=0 ){
         this.areas[id].image.style.display="none";
         clearInterval(this.areas[id].timer);
         this.areas[id].timer = 0;
         this.areas[id].opacity = 0;
      }
      
      if(this.areas[id].opacity >= 1 ){
         clearInterval(this.areas[id].timer);
         this.areas[id].timer = 0;
         this.areas[id].opacity = 1;
      }
   }
   
}

function checkGuestForm(f){
	f.odeslat.disabled = true;
	var errors = new Array();

	if(f.name && f.text.value=="")
		errors.push("text");
	if(f.name && f.name.value=="")
		errors.push("jmeno");

	if(!errors.length){
		f.submit();
		return true;
	}
	else{
		window.alert("Musite vyplnit: "+errors.join());
		f.odeslat.disabled = false;
		return false;
	}
}