var img_folder = 'images_'+ pagename + '/';  //Directory where all images for this page are
var descr_folder = 'description_'+ pagename + '/';  //Direcctory where all description (.html) are

if ((thumb_format) && (thumb_format == 'jpg'))
{
var ext_thumb = '_54.jpg';   //Three variables for thumbs and main images' extentions
var ext_th_over = '_over.jpg';
}
else
{
var ext_thumb = '_54.gif';   //Three variables for thumbs and main images' extentions
var ext_th_over = '_over.gif';
}
var ext_main = '_540_1.jpg';



var N = 0;
var img_return = 0;
var flip_pos = 0;
    
function az_preload() {
 var temp = az_preload.arguments; 
 for(x=0; x < temp.length; x++) {
  img_preload[x]=new Image();
  img_preload[x].src=az_preload.arguments[x];
 }
}

function az_swap_over(N) {
  var i=0; 
  for (i=0; i < img_names.length; i++) {
   var img_name = 'th_'+ i;
   if (i == N)  document[img_name].src = img_folder + img_names[i] + ext_th_over; 
   else document[img_name].src = img_folder + img_names[i] + ext_thumb;
      }
 }
  
 function az_swap_main(N) {  
    ////    if(!document.images.main) 
    document.getElementById('photo_box').innerHTML = '<img src="' + img_folder + img_names[N] + ext_main + '" alt="' + img_alt_m[N][0] + '" name="main" width="540" height="400" id="main" />';
   if(jpg_flash_m[N][0] != 'swf') {            
       document.main.src = img_folder + img_names[N] + ext_main;         
       document.main.alt = img_alt_m[N][0];
        }        
    else {  
      y = document.getElementById('photo_box');
        do_flash = flash_displ(N,1);           
          /// alert(do_flash);    
        y.innerHTML = do_flash;              
 }            
     img_return = N; 

     if (flps ==1) {
     document.getElementById('frms').src = descr_folder + img_names[N] + "_1"  + ".html";
     fliptozero();     
        }         
     else if (flps == 2) {
		// alert ("MUDE");
       z= document.getElementById('text_box');	  
       z.innerHTML= decodeURIComponent(img_descr[N][0]); 
	   fliptozero();
             
        }           
     else if (flps == 0) {
          z= document.getElementById('text_box');	  
          z.innerHTML= img_descr[N] + '<div id="frms"></div>';
		  fliptozero();
        }  

 }
   
function make_add_array(img_num) {   
  arr_add = new Array();
  nn = img_num;
  arr_l = flip_nums[img_num];
     for(i=0; i < arr_l; i++) {
      k = i + 1;
      arr_add[i] = img_names[nn] + '_540_' + k + '.jpg';  	 	   
   }
   return arr_add;
}  
 
 function flip_through(dir){
  var k = flip_nums[img_return];  //img.return is the number of the thumb selected (should stay selected)
  var temp_arr =  make_add_array(img_return);
  if (dir == 'next') if (flip_pos < k-1) flip_pos = flip_pos + 1;
  if ((dir == 'pre') && (flip_pos > 0)) flip_pos = flip_pos - 1;
  if (flip_pos > 0) document.prevArrow.style.visibility = "visible";
  else document.prevArrow.style.visibility = "hidden";
  if (flip_pos >= k-1) document.nextArrow.style.visibility = "hidden";
  else document.nextArrow.style.visibility = "visible";
  
  if(!document.images.main) 
    document.getElementById('photo_box').innerHTML = '<img src="' + img_folder + img_names[img_return] + ext_main + '" alt="' + img_alt_m[img_return][flip_pos] + '" name="main" width="540" height="400" id="main" />';
    
  if(jpg_flash_m[img_return][flip_pos] != 'swf') { 
    document.images.main.src = img_folder + temp_arr[flip_pos];
     document.images.main.alt = img_alt_m[img_return][flip_pos];  
  }
  else {
     y = document.getElementById('photo_box');
        do_flash = flash_displ(img_return,flip_pos+1);           
              //// alert(do_flash);    
        y.innerHTML= do_flash;              
 }            
 
  if (flps == 1) { 
    flip_descr_adr = descr_folder + img_names[img_return] + "_" + (flip_pos + 1) + ".html";
    document.getElementById('frms').src = flip_descr_adr;
  }
   else if (flps == 2) {    
       z= document.getElementById('text_box');	  
       z.innerHTML= decodeURIComponent(img_descr[img_return][flip_pos]); 
	   /// fliptozero();
   }
  
  flip_txt = "Image " + (flip_pos + 1) + " of " + k;  // shows the number of flip
  flp = document.getElementById('flips');	  
  flp.innerHTML= flip_txt;   
 if (dir == 'next') X = swaparrow('nextArrow','images/arrow_next_over.gif');
 if (dir == 'pre') X = swaparrow('prevArrow','images/arrow_prev_over.gif');
}
   
   function fliptozero() {
  flip_pos = 0;
      document.prevArrow.style.visibility = "hidden";
  if (flip_nums[img_return] != 1) {
  document.nextArrow.style.visibility = "visible";
document.getElementById('flips').innerHTML = "Image 1 of " + flip_nums[img_return]; 
}
  else {
document.nextArrow.style.visibility = "hidden";
document.getElementById('flips').innerHTML = '';  
  }
}
  
 function az_restore() {
   xxx = az_swap_over(img_return);
 }
 
 function swaparrow(arrowName,source) {
  document[arrowName].src = source;
}
 
 function is_in_array(xarray,xval) {
       for(i=0; i < xarray.length; i++) {
         if (xval == xarray[i]) return 1;
         else return 0;     
      }
    }
        
function flash_displ(N,k) {   

  insert_obj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="540" height="400" title="' + img_alt_m[N][0] + '">' +
  '<param name="movie" value="' + img_folder + img_names[N] + '_540_' + k + '.swf" />' +
  '<param name="quality" value="high" />' +
  '<embed src="' + img_folder + img_names[N] + '_540_' + k + '.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="540" height="400"></embed>' +
'</object>';

return insert_obj;
}
  
var bottom = '<div class="footer"><img src="images/bottom756_' + pagename + '.gif" alt="' + pagename + '" name="' + pagename + '" id="' + pagename + '" /></div>';
