var small_width = 120;  	//thumbnail image width
var small_height = 120; 	//thumbnail image height
var g_width_length =4; 		//rows in image table
var g_height_length = 3;	//columns in image table

var Curr_idx = new Array();
for(var i=0; i<b_photo_list.length; i++)
   Curr_idx[i]=i; 

var Curr_img=parseInt('+Curr_page+');
function keep_idx(Curr_page)   {
	var Curr_page;
	Curr_img = parseInt(Curr_page);
}

var which;
function move_img(which)  {
var m_img;
    
	if(which == 'prev')   {
	    if(Curr_img > 0)   {
		   Curr_img--;
		   document.getElementById("Curr_pg").innerHTML = Curr_img+1;
		   document.getElementById("Tot_pg").innerHTML = b_photo_list.length;
		}
		else if(Curr_img == 0) {
				Curr_img=b_photo_list.length-1;
				document.getElementById("Curr_pg").innerHTML = b_photo_list.length;
		        document.getElementById("Tot_pg").innerHTML = b_photo_list.length;
		      }
			 else window.status="no photo"; 
		title.innerHTML=b_title[Curr_img];
		m_img = b_photo_list[Curr_img].substring(0,13)+".jpg";
		document.images.en_image.src=m_img;
	}
	else if(which == 'next')   {
	       if(Curr_img<b_photo_list.length-1)   {
		      Curr_img++;
			  document.getElementById("Curr_pg").innerHTML=Curr_img+1;
			  document.getElementById("Tot_pg").innerHTML=b_photo_list.length;
		   }
		   else if(Curr_img == b_photo_list.length-1)  {
				   Curr_img=0;
				   document.getElementById("Curr_pg").innerHTML = Curr_img+1;
		           document.getElementById("Tot_pg").innerHTML = b_photo_list.length;
				}
			 else window.status="no photo"; 
		 title.innerHTML=b_title[Curr_img];
		 m_img = b_photo_list[Curr_img].substring(0,13)+".jpg";
		 document.images.en_image.src=m_img;
	     }
	else window.status='no photo';
}

function move_page(porn) {
    var Tot_table=Math.ceil(b_photo_list.length/(g_width_length*g_height_length));
	
    if(porn == 'prev') {
	    page_table--;
        if(page_status == 0) {
		
            window.status="The first page";
            thumb_img(page_add_no[page_add_no.length-1]);
			page_table=Tot_table;
			document.getElementById("Curr_pg_tb").innerHTML = Tot_table;
	 	    document.getElementById("Tot_pg_tb").innerHTML = Tot_table;
        } else {
            thumb_img(page_status-(g_width_length*g_height_length));
			
			document.getElementById("Curr_pg_tb").innerHTML = page_table;
	 	    document.getElementById("Tot_pg_tb").innerHTML = Tot_table;
        }
		
    } else
    if(porn == 'next') {
	    page_table++;
        if(page_status == page_add_no[page_add_no.length-1]) {
            window.status="The last page"; 
            thumb_img(0);
			page_table=1;
			document.getElementById("Curr_pg_tb").innerHTML=page_table;
	 	    document.getElementById("Tot_pg_tb").innerHTML=Math.ceil(b_photo_list.length/(g_width_length*g_height_length));
        } else {
            thumb_img(page_status+(g_width_length*g_height_length));
			
			document.getElementById("Curr_pg_tb").innerHTML=page_table;
	 	    document.getElementById("Tot_pg_tb").innerHTML=Tot_table;
        }
		
    }
}

var page_add_no = new Array();
for(i=0; i<b_photo_list.length/(g_width_length*g_height_length); i++) {
    page_add_no[i] = i*(g_width_length*g_height_length);
}

function enlarge_img(image_url,Curr_a_title,page) {
	
	var e_i = image_url.substring(0,13)+".jpg";
	var page;
	
	document.getElementById("gallery_table").style.display="none";
	document.getElementById("move_page").style.display="none";
	document.getElementById("zoominphoto").style.display="block";
	document.getElementById("move_image").style.display="block";
  //  	document.en_image.width="500";
	//document.en_image.height="500";	
	document.en_image.src=e_i;
	title.innerHTML=Curr_a_title;
	document.getElementById("Curr_pg").innerHTML =eval(page)+1;
	document.getElementById("Tot_pg").innerHTML = b_photo_list.length;
}

function error_debug(error_no) {
    p_t[error_no].innerHTML = '<div class="g_font">กก</div>';
}
var page_status = '';
function thumb_img(page_no) {
    var elemTb = document.getElementsByName("p_t"); 
    page_status = page_no;
	document.getElementById("zoominphoto").style.display="none";
	document.getElementById("move_image").style.display="none";
	document.getElementById("gallery_table").style.display="block";
	document.getElementById("move_page").style.display="block";
	
	if(page_no == 0) page_table=1;
	
    for(i=0; i<g_width_length*g_height_length; i++) {
        if(b_photo_list[i+page_no] != undefined) {
	
            elemTb.item(i).innerHTML = '<a href="#" onclick=" enlarge_img(\''+b_photo_list[i+page_no]+
		               '\',\''+b_title[i+page_no]+'\',\''+eval(i+page_no)+'\');keep_idx(\''+Curr_idx[i+page_no]+'\');">'+
                               '<img  src="'+b_photo_list[i+page_no]+'" width="'+small_width+
			       '" height="'+small_height+
		               '" onerror="error_debug('+i+');" border="0" class="g_image_border_hide" ></a>';
	    document.getElementById("Curr_pg_tb").innerHTML=page_table;
	    document.getElementById("Tot_pg_tb").innerHTML=Math.ceil(b_photo_list.length/(g_width_length*g_height_length));
        } else {
            elemTb.item(i).innerHTML = ' ';
        }
    }
	
}
