function isDOMcompliant()
{return document.getElementById && document.getElementsByTagName;}

function next_page(_type){
//	alert (select_id + ' ' + prj_count);
	if (select_id < prj_count) {tmp=select_id; tmp++; load_project(_type, tmp, tmp);}
}

function prev_page(_type){
	if (1 < select_id) {tmp=select_id; tmp--; load_project(_type, tmp, tmp);}
}

function load_img(_imgId,_img){
   if (! isDOMcompliant()) return;
   if (null != _imgId) {
	   if ('' != page_select_id) document.getElementById(page_select_id).className="buttons";
	   document.getElementById(_imgId).className="buttons_sel";
	   page_select_id = _imgId;
   }

   if (picts_idx == picts.length){picts_idx %= picts.length}
   if (null == _img) {_img = picts[picts_idx++]}
   if (null != document.getElementById('main_img')) {document.getElementById('main_img').src=_img}
}

function load_project(_type, _id, _imgId) {
	if (! isDOMcompliant()) return;	
	urj = window.location.protocol + '//' +window.location.hostname + '/get_project.php?page=' + _type + '&id=' + _id;
	ajaxLoad('content',urj, _type, _id, _imgId);
}

function updateObj(obj, _type, _id, _imgId, data){
   page_select_id = "sub_1";
   
   if (select_id >=0) document.getElementById(select_id).className="buttons";
   document.getElementById(_imgId).className="buttons_sel";
   select_id = _imgId;
   
   if (1 < select_id)         {document.getElementById('prev_img').className="nav_img";} else {document.getElementById('prev_img').className="nav_img_last";}
   if (select_id < prj_count) {document.getElementById('next_img').className="nav_img"; } else {document.getElementById('next_img').className="nav_img_last";}
   tmp=select_id;tmp++;
   document.getElementById('prev_img').src='/portfolio/'+ _type + '/t/' + (select_id-1);
   document.getElementById('next_img').src='/portfolio/'+ _type + '/t/' + tmp;
   
   document.getElementById(obj).innerHTML= data; 
} 

function ajaxLoad(obj, url, _type, _id, _imgId){
	  var ajaxObj;
      try { 
    	  ajaxObj = new ActiveXObject("Msxml2.XMLHTTP");
      }  catch (e) { 
    	  try { 
    		  ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
    	  } catch (E) {
    		  ajaxObj = false;
	      }
	  }
	  
      if (!ajaxObj && typeof XMLHttpRequest!='undefined') {
	  	ajaxObj = new XMLHttpRequest();
      }
      
      if (!ajaxObj) return;
      ajaxObj.open ('GET', url);
	  ajaxObj.onreadystatechange = ajaxCallBack(obj,ajaxObj, _type, _id, _imgId);
	  ajaxObj.send('GET'); 
	  return false;
} 

function ajaxCallBack(obj, ajaxObj, _type, _id, _imgId){
	return function(){
    if( (ajaxObj.readyState == 4) && (ajaxObj.status==200) ) { 
				updateObj(obj, _type, _id, _imgId, ajaxObj.responseText)
		}
	}
}

