var ref = '';

function ajax_request(url,data,target,cb_func){
   clearTimeout(ref);
   new Ajax.Request(url, {
      method: 'get',
      parameters: data,
      onSuccess: function(transport) {
         if(transport.responseText.match(/Redirecting you, please wait.../)){
            res = transport.responseText;
            res = res.stripTags();
            res = res.replace(/Redirecting you, please wait.../,"");
            window.location = res;
         }
         if(target){
            $(target).innerHTML = transport.responseText;
         }
         if(cb_func){
            ref = setTimeout(cb_func,2000);
         }
      }
   }
);
}

function saveQuickInquire(){
   ajax_request('/ajax/quick_inquire.php', Form.serialize('quickInquireForm'),'quickInquire','');
}

function showQuickInquire(){
//   alert($('quickInquire').style.display);
   if($('quickInquire').style.display == 'none'){
      Effect.BlindDown('quickInquire', {duration: .2});
   }else{
      Effect.BlindUp('quickInquire', {duration: .2});   
   }
}

function rebuildQuickInquire(id){
   ajax_request('/ajax/quick_inquire.php', 'rebuild=true&art_id='+id,'quickInquire','');
}

function getItem(id){

   $('itemDetail').innerHTML = "<img src='/visions/gfx/loading.gif' border='0'><br><br>Loading Item Details / Additional Images";

			new Ajax.Request('./ajax/ajax.php', {
			  method: 'get',
			  parameters: 'id='+id,
			  onSuccess: function(transport) {
			     $('itemDetail').update(transport.responseText);
			  }
			});

}

function browsePrev(){

   if(currentThumb - 1 >= 0){
      currentThumb--;
      scrollX += browseImg[currentThumb] + 5;
      moveScroller();
   }
   
}

function browseNext(){
   
   if(currentThumb + 1 < browseImg.length){
      scrollX -= browseImg[currentThumb] + 5;      
      currentThumb++;
      moveScroller();
   }

}

function moveScroller(){

//   alert(browseImg[0]);
   
   if(currentThumb <= 0){
      $('bPrev').disabled = true;
   }else{
      $('bPrev').disabled = false;
   }

   if(currentThumb >= browseImg.length - 1){
      newWidth = browseImg[currentThumb] + 5;
      $('bNext').disabled = true;
   }else{
      currentThumb2 = currentThumb + 1;
      currentThumb3 = currentThumb2 + 1;
      newWidth = browseImg[currentThumb] + browseImg[currentThumb2] + browseImg[currentThumb3] + 10;
      $('bNext').disabled = false;
   }

   new Effect.Morph('browseFilesBox', {
      style: 'width: '+newWidth+'px',
      duration: 0.8
   });
   
   new Effect.Morph('browseScroller', {
      style: 'left: '+scrollX+'px',
      duration: 0.8
   });
   
}

