function fixH(one,two) {
  if (document.getElementById(one)) {
    var lh=document.getElementById(one).offsetHeight;
    var rh=document.getElementById(two).offsetHeight;
    var nh = Math.max(lh, rh);
    document.getElementById(one).style.height=nh+"px";
    document.getElementById(two).style.height=nh+"px";
  }
}

function fixGroupH(group) {
  var elements = $$(group)
  var maxH = elements[0].offsetHeight

  for (var i = 1; i < elements.length; i++) {
    if (elements[i].offsetHeight > maxH) {
      maxH = elements[i].offsetHeight
    }
  }
  for (var i = 0; i < elements.length; i++) {
    elements[i].style.height = maxH + 'px'
  }
}

function setLangSwitchPosition() {
  $$('.language_switch')[0].style.left = ($$('.wrapper_bottom')[0].offsetLeft + 950) + 'px'
  $$('.language_switch')[0].show()
}

//this does it for three
function sortNum(a,b) {
  return b-a
}

function fixH2(one,two,three) {
  if (document.getElementById(one)) {
    var obj=new Array(3);
    var option=[one,two,three];
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height="auto";
      obj[i]=document.getElementById(option[i]).offsetHeight;
      nh=obj.sort(sortNum);
    }
    nh1=nh.splice(1,2);
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height=nh+"px";
    }
  }
}

function showMobileVideo(element){
  element.addClassName('current')
  element = element.rel
  
  $$('.game_description').invoke('hide')
  $('game_description_' + element).show()  

  element = $(element);
  $$('.mobile_videos').invoke('hide')
  element.show();
}

function initGameVideos(){
  $$('.game_link').each(function(s){
    s.onclick = function(){      
      $$('#games .current')[0].removeClassName('current')
      showMobileVideo(s)
    }
  })
  
  var first = $$('.game_link')[0]
  if(first){
    showMobileVideo(first)
  }
}

document.observe("dom:loaded", function() {
	var opacity = 0.5;
	//$(".clients li span").stop().fadeTo('normal', opacity);


/*	$(".clients li").hover(function() { //On hover...

		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		//$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 1 , function() {
			//$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		$(this).find("span").stop().fadeTo('normal', opacity).show();
	});*/

	defocus();
	
	initGameVideos()
});


function defocus(){
	var a = document.getElementsByTagName('a');

	for(i=0;i<a.length;i++){
		a[i].onfocus=function(){
			if(this.blur)this.blur();
		}
	}
}

