sfHover = function() {
	var sfEls = document.getElementById("nav-page").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function set_images( obj_a ){
    //tmp_src = obj_a.getElementsByTagName('img')[0].src.replace(/thumb/,'gross');
    tmp_src = obj_a.children('img').attr('src').replace(/thumb/,'gross');
    tmp_src = tmp_src.replace(/_th/,'');
    $('.main-image').attr('src',tmp_src);
    tmpStr = obj_a.attr('href') + ' #info-projectDetail';
    $('#info-projectDetail').html('loading');
    /*var tmpHTML = $('<div></div>');
    tmpHTML.attr('id','tmp');
    $('#info-project').append(tmpHTML);
    $('#tmp').load(tmpStr, function() {
      $('#info-projectDetail').html( $('#tmp #info-projectDetail').html() );
      $('#tmp').remove()
    } );*/
    
    $('#info-projectDetail').load(tmpStr);
    $('#nav-gallery .selected').removeClass('selected');
    obj_a.parent('li').addClass('selected');
  }

function create_turnNav(){
  var tmpHTML = '';
  tmpHTML += '<ul id="turnPage">';
  tmpHTML += '<li id="turnPagePrev">previous</li>';
  tmpHTML += '<li id="turnPageNext">next</li>';
  tmpHTML += '</ul>';
  $('body.gallery #outer-page-content').prepend(tmpHTML);
  $('#turnPagePrev').click( function() {
    turnPage('prev');
  });
  $('#turnPageNext').click( function() {
    turnPage('next');
  });
}

function turnPage( direction ){
  var tmpNavLength = $('#nav-gallery ul li').length;
  
  for ( var x = 0, count = tmpNavLength; x < count; x++ ){
    var tmpTarget = '#nav-gallery ul li:nth-child('+x+')';
    if( $(tmpTarget).attr('class') == 'selected' ){
      targetNum = x;
      break;
    }
  }
  if( direction == 'next' ){
    targetNum++;
    targetNum = ( targetNum > tmpNavLength ) ? 1 : targetNum;
  }else {
    targetNum--;
    targetNum = ( targetNum < 1 ) ? (tmpNavLength-1) : targetNum;
  }
  var tmpTarget = '#nav-gallery ul li:nth-child('+targetNum+') a';
  obj_a = $(tmpTarget);
  set_images(obj_a);
}
