function switch_photo(imgObj) {
  var src = imgObj.attr('src');
  var title = imgObj.attr('title');
  var area = $("#large_photo_img");
  var newimg = new Image();
  newimg.src = src;
  var oldimg = new Image();
  oldimg.src = area.attr('src');

  var new_height = newimg.height;
  var old_height = oldimg.height;
  var diff = new_height-old_height;
  old_height = area.parent().height();
  new_height = area.parent().height()+diff;

  area.parent().append("<img id='fade_layer'/>");
  var tmp_area = $("#fade_layer");
  tmp_area.attr("src", area.attr('src'));
  tmp_area.css("position", "absolute");
  tmp_area.css("top", area.position().top);
  tmp_area.css("left", area.position().left);
  tmp_area.css("opacity", 1);

  area.attr("src", src);
  if (diff <= 0) {
    area.parent().height(old_height);
  }
  else {
    area.parent().height(new_height);
  }

  tmp_area.animate({"opacity":0}, 1000, function(){
    area.parent().height(new_height);
    tmp_area.remove();
  });			
  
  $('p#photo_caption').text(title);
  if (imgObj.parent().parent().prevAll().length>0) {
    $("li#btn_prev").attr("class", "btn_prev");
  }
  else {
    $("li#btn_prev").attr("class", "btn_prev off");
  }
  if (imgObj.parent().parent().nextAll().length>0) {
    $("li#btn_next").attr("class", "btn_next");
  }
  else {
    $("li#btn_next").attr("class", "btn_next off");
  }
}
$(function(){
    $('li.btn_next a').click(function(){
      if ($(this).parent().hasClass('off')) return false;
      var cursrc = $("#large_photo_img").attr("src");
      if ($.browser.msie && $.browser.version < 8) {
        var imgar = $("div#box_game_photos ul li a img");
        for (var i=0; i<imgar.length; i++) {
          var s = $("div#box_game_photos ul li:nth-child("+(i+1)+") a img").attr('src');
	  if (s == cursrc) {
	    switch_photo($("div#box_game_photos ul li:nth-child("+(i+1)+")").next().children().children());
	    i = imgar.length;
	  }
	}
      }
      else {
        switch_photo($("div#box_game_photos ul li a img[src='"+cursrc+"']").parent().parent().next().children().children());
      }
    });
    $('li.btn_prev a').click(function(){
      if ($(this).parent().hasClass('off')) return false;
      var cursrc = $("#large_photo_img").attr("src");
      if ($.browser.msie && $.browser.version < 8) {
        var imgar = $("div#box_game_photos ul li a img");
        for (var i=0; i<imgar.length; i++) {
          var s = $("div#box_game_photos ul li:nth-child("+(i+1)+") a img").attr('src');
	  if (s == cursrc) {
	    switch_photo($("div#box_game_photos ul li:nth-child("+(i+1)+")").prev().children().children());
	    i = imgar.length;
	  }
	}
      }
      else {
        switch_photo($("div#box_game_photos ul li a img[src='"+cursrc+"']").parent().parent().prev().children().children());
      }
    });
    $('div#box_game_photos ul li a img').click(function(){
      switch_photo($(this));
    });
    $('div#all_game_list').load('../game_list.html', set_accordion);

});
function set_accordion() {
    $('div#box_game_list').each(function(){
      $('div.box_accordion > h5', this).each(function(index){
        var $this = $(this);
	if ($this.parent().attr('id') != ('box_ac_'+box_ac)) {
	  $this.next().hide();
	}
	else {
	  $this.attr('class', 'selected');
	}
	$this.click(function(){
	  var params = {height:"toggle", opacity:"toggle"}; 
	  if($(this).hasClass('selected'))
	    $(this).attr("class","");
	  else $(this).attr("class","selected");
	  $(this).next().animate(params).parent().siblings().children("ul:visible").animate(params, function(){
	  $(this).parent().siblings().children("ul:visible").prev().attr("class", "selected");
	  $(this).prev().attr("class", "");
}); 
	  return false;
	});
      });
    });
}
