/*
Joe Abi Raad
This is my JS file
*/
var cat_id=2;
var page=1;
var total=5;
var hand = function(str){
	var str_a = new Array();
	var bigpic;
	var vid;
	opacity('pics', 0, 100, 500);
	str_a=str.split('|');
	str=str_a[0];
	total=str_a[1];
	bigpic=str_a[2];
	vid=str_a[3];
	window.document.getElementById('pics').innerHTML=str;
	window.document.getElementById('pagination').innerHTML="Set "+page+"/"+total;
	if(cat_id==2) window.document.getElementById('tv_portfolio').style.marginLeft='675px';
	else if(cat_id==3) window.document.getElementById('tv_portfolio').style.marginLeft='765px';
	else if(cat_id==4) window.document.getElementById('tv_portfolio').style.marginLeft='855px';
	showBigPic(bigpic,vid);
	if ( page>total ){
		page=0;
	}
}
var behind_hand = function(str){
	//alert(str);
	str_a=str.split('|');
	str=str_a[0];
	pp=str_a[1];
	window.document.getElementById('imgs').innerHTML=str;
	window.document.getElementById('pages').innerHTML="<img src='images/loading3.gif'  style='border:0px;'>";
	this.doGet('ouf.php?action=behind_pages&pp='+pp,behind_pages,'text');
}
var behind_pages = function(str){
	//alert(str);
	window.document.getElementById('pages').innerHTML=str;
}
var behind_data = function(str){
	window.document.getElementById('behind_data').innerHTML=str;
}
function get_pics(catid,t){
	cat_id = catid;
	if ( t==-1 ) page=page-1;
	if ( t==1 ) page=page+1;
	if ( t==0 ) page=1;
	if ( page < 1 ) page=1;
 	window.document.getElementById('pics').innerHTML="<br><center><img src='images/loading.gif'  style='border:0px;width:32px; height:32px;'><BR><font size=1>Loading pics</font></center>";
	opacity('pics', 0, 100, 1000);
	var ajax = new Ajax();
	this.doGet('ouf.php?action=portfolio_pics&cat_id='+catid+'&p='+page,hand,'text');
}

function get_imgs(pp){
 	window.document.getElementById('imgs').innerHTML="<br><center><img src='images/loading2.gif'  style='border:0px;width:32px; height:32px;'></center>";
	opacity('imgs', 0, 100, 1000);
	var ajax = new Ajax();
	this.doGet('ouf.php?action=behind_pics&pp='+pp,behind_hand,'text');
}
function showBigPic(pic,vid){
 	window.document.getElementById('bigpic').innerHTML="<center><img src='images/loading.gif'  style='border:0px;width:32px; height:32px;'><BR><font size=1>Loading pic</font></center>";
	opacity('bigpic', 0, 100, 1000);
 	window.document.getElementById('bigpic').innerHTML="<img src=img/big/"+pic+" onclick=openVideo('"+vid+"')>";
 	window.document.getElementById('showvid').innerHTML="<a onclick=openVideo('"+vid+"')>Download/Play</a>";
}
function enlargeBehind(pic,id){
	if ( pic=='' ) return;
 	window.document.getElementById('bigimg').innerHTML="<center><img src='images/loading.gif'  style='border:0px;width:32px; height:32px;'><BR><font size=1>Loading pic</font></center>";
	//opacity('bigimg', 0, 100, 1000);
 	window.document.getElementById('bigimg').innerHTML="<img src=img/big/"+pic+">";
	if ( id != 0 ){
	  //window.document.getElementById('behind_data').innerHTML="<img src='images/loading3.gif'  style='border:0px;'>";
	  this.doGet('ouf.php?action=behind_data&id='+id,behind_data,'text');
	}
}
function openVideo(vid){
  if ( vid=="" ){
  	alert("Sorry but it seems that the video is not ready yet !\nPlease try again later");
	return false;
  }
  var myWin = window.open("video.php?vid="+vid,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=500, height=500");
  myWin.moveTo((screen.width-500)/2,(screen.height-500)/2); 
}

