  var image_array=new Array();
  var image_index=0;
  var interval_id;
  var interval_on=false;
  var http = createRequestObject();
  var site=window.location.href.substring(0,window.location.href.indexOf("/",8)); //site url address
  var interval_on=false;
  var image_index=0;
  var Editor ='bs';
  var new_window;
  var slide_time=5000;
function createRequestObject(){
 try{
  var request; //declare the variable to hold the object.
  var browser = navigator.appName; //find the browser name

  if(browser == "Microsoft Internet Explorer"){
    /* Create the object using MSIE's method */
    request = new ActiveXObject("Microsoft.XMLHTTP");
  }
   else{
    /* Create the object using other browser's method */
    request = new XMLHttpRequest();
  }
  return request; //return the object
}
 catch(error){alert('createRequestObject error')}
}

function getAlbums(){
  try{
  http.open('get',site+'/javascript/ajax/blog/blog_post_thumbs.php?action=imagelist&album='+
		document.form_choose_album.select_albums.value);
  http.onreadystatechange = handleAlbums; 
  http.send(null);
  }
 catch(error){alert('getAlbums error')}
}

function getImage(){
  try{

		document.form_choose_image.select_images.value=="nothing";
   http.open('get',site+'/javascript/ajax/blog/blog_post_thumbs.php?action=fetchimage&index='+
              document.form_choose_image.select_images.value +'&album='+
    document.form_choose_album.select_albums.value);
   http.onreadystatechange = handleImages; 
   http.send(null);
   }
 catch(error){alert('getImage error')}
}
function handleAlbums(){
  try{
  if(http.readyState == 4){ //Finished loading the response
    var response = http.responseText;
    document.getElementById("showimage").innerHTML = response;
  }
  }
 catch(error){alert('handleAlbums error')}
}
function handleImages(){
  try{
  if(http.readyState == 4){ //Finished loading the response
    var response = http.responseText;
	if(!(response==null || response=="")){	
    	document.getElementById("showthumb").innerHTML = response;
	if(interval_on){
	document.getElementById("btn_slide").src=site+"/media/themes/default/btn_pause.jpg";
	document.getElementById("btn_slide").alt="Pause";
	}
//fix the auto-switch to slide show problem
	}
  }
  }
 catch(error){alert('handleImages error')}
}
function time_sets(){
  try{
    slide_time=document.getElementById("speed").value;
    if(interval_on){
    clearTimeout(interval_id);  //clear the setInterval('next_image()',slide_time);
    interval_id=setInterval('next_image()',slide_time);
    }
  }
    catch(error){alert('time set error')}  
}
function slide_show(){
  try{

    if(!interval_on){
    interval_on=true;
    interval_id=setInterval('next_image()',slide_time);
    document.getElementById("btn_slide").src=site+"/media/themes/default/btn_pause.jpg";
    document.getElementById("btn_slide").alt="Pause";
    }
    else{
    clearTimeout(interval_id);
    interval_on=false;
  
    document.getElementById("btn_slide").src=site+"/media/themes/default/btn_play.jpg";
    document.getElementById("btn_slide").alt="Play";
    }
    }
    catch(error){alert('slide_show error')}
}
function stop_image(){
  try{
  
    if(!interval_on){
      var image=document.getElementById("select_images");
      image[0].selected=true;	
      getImage();
    }
    else{
      clearTimeout(interval_id);
      var image=document.getElementById("select_images");
      image[0].selected=true;	
      getImage();
      interval_on=false;
      document.getElementById("btn_slide").src=site+"/media/themes/default/btn_play.jpg";
      document.getElementById("btn_slide").alt="Play";
    }
    }
    catch(error){alert('slide_show error')}
}
function next_image(){
  try{
  var image=document.getElementById("select_images");
  for(var i=0;i<image.length;i++){
          if(image[i].value==image.value){
                  image_index=i;
                  i=image.length;//exit the loop
          }
  }		
  image_index++;

  if(image_index==image.length){
          image_index=0;
  }
  image[image_index].selected=true;	
  getImage();
  }
  //document.images["image_holder"].src=image_array[image_index];
  catch(error){alert('next_image error')}
}
function back_image(){
  try{
  var image=document.getElementById("select_images");
  for(var i=0;i<image.length;i++){
          if(image[i].value==image.value){
                  image_index=i;
                  i=image.length;//exit the loop
          }
  }
  image_index--;
  if(image_index<0){
          image_index=image.length-1;
  }
  image[image_index].selected=true;
  getImage();
  }
  catch(error){alert('back_image error')}
  //document.images["image_holder"].src=image_array[image_index];
	
}
function open_image(image_id,image_width,image_height,title_name){
  try{
    var image=site+"/images/show_image.php?id="+image_id;
    if(window_available()){
      new_window.close();
    }

    var window_dimensions="width="+image_width+",height="+image_height+",resizable,scrollbars=yes";
    new_window=window.open("","",window_dimensions);
//alert(window.document.documentElement.clientWidth);
    new_window.moveTo(window.document.documentElement.clientWidth-image_width,1);//move new window to right upper corner
    new_window.document.writeln('<html>');
    new_window.document.writeln('<head>');
    new_window.document.writeln('<title>');
    new_window.document.writeln('<\/title>');
    new_window.document.writeln('<\/head>');
    new_window.document.writeln('<body leftmargin="0" topmargin="0" ,marginwidth="0", marginheight="0">');
    new_window.document.writeln('<img src="'+image+'">');
    new_window.document.writeln('<\/body>');
    new_window.document.writeln('<\/html>');
    new_window.document.close();
    new_window.document.title=title_name;
  }
catch(error){alert("open_image error");}
}
function window_available(){
	if(!new_window){
	return false
	}
	else if(new_window.closed){
		return false
	}
	else{
		return true;
	}

}
function FCKeditor_OnComplete( editorInstance )
{
   Editor = editorInstance;
   
   //alert( editorInstance.Name ) ;
}

function insert_image(){

  // var imagev = document.getElementById("insert_image_value").value;
   var id=document.getElementById("image").src.substring(document.getElementById("image").src.indexOf('?')+4);
   var image_link=site+"/albums/album_image.php?image="+id;
   var image_src=document.getElementById("image").src;
   var img = Editor.CreateElement('img');
       img.setAttribute("src", image_src);
   var a = Editor.CreateElement('a');
       a.setAttribute("href", image_link);
       a.appendChild(img);

// a.innerHTML= = "<img src=\"http://beta.neigo.com/images/show_thumb.php?id="+imagev+"/>";

}
