var productinfo_selected=0;
var productinfo_rotate_delay=2899;
var productinfo_timerRunning=false;
var productinfo_timerID=false;


function productinfo_change(num){
  with (document){
    if (num>=0 && num<productinfo_photo.length){
      productinfo_selected=num;
      if (productinfo_photo.length>1){
        getElementById("productinfo_slideshowstate").innerHTML = JS_PRODUCT_INFO_PREFIX +(productinfo_selected+1)+ JS_PRODUCT_INFO_MIDFIX +productinfo_photo.length+JS_PRODUCT_INFO_SUFFIX;
      }
      
      getElementById("productinfo_linkpic").src = productinfo_photo[num].src;
      if (num==0 && document.getElementById("productinfo_slideshow").value==JS_PRODUCT_INFO_SLIDESHOW_STOP) {
      	first_loop=false;
      	productinfo_ap();
      }
    } else {
      //alert('old index'+productinfo_selected+'\nnew index'+num+'\n');
    }
  }
}

function productinfo_change_file_cursor(evt) {
	cancelBubble(evt);
	var obj=evt.srcElement || evt.target;
	var reg=new RegExp(obj.alt, "gi");
	for (var i=0; i<productinfo_photo.length; i++) {
		if (productinfo_photo[i].src.search(reg)!=-1) {
			obj.style.cursor='pointer';
			break;
		}
	}
}

function productinfo_change_file(evt) {
	cancelBubble(evt);
	var obj=evt.srcElement || evt.target;
	var reg=new RegExp(obj.alt, "gi");
	for (var i=0; i<productinfo_photo.length; i++) {

		if (productinfo_photo[i].src.search(reg)!=-1) {
			if (productinfo_timerRunning) {
				productinfo_ap();
				productinfo_change(i);
			} else {
				productinfo_change(i);
			}
			break;
		}
	}
}

function productinfo_next() {
  productinfo_change((productinfo_selected+1)%productinfo_photo.length);
}

function productinfo_previous() {
  if (productinfo_selected-1 >= 0) {
    productinfo_change(productinfo_selected-1);
  } else {
    productinfo_last();
  }
}

function productinfo_first() {
  productinfo_change(0);
}

function productinfo_last() {
  productinfo_change(productinfo_photo.length-1);
}

function productinfo_ap() {
  if (productinfo_photo.length>1){
    with (document.getElementById("productinfo_slideshow")){
      if (value==JS_PRODUCT_INFO_SLIDESHOW_START){
        value=JS_PRODUCT_INFO_SLIDESHOW_STOP;
        if (productinfo_timerRunning){
          window.clearInterval(productinfo_timerID);
        }
        productinfo_timerID=window.setInterval("productinfo_rotate()", productinfo_rotate_delay);
        productinfo_timerRunning=true;
      } else {
        value=JS_PRODUCT_INFO_SLIDESHOW_START;
        window.clearInterval(productinfo_timerID);
        productinfo_timerRunning=false;
      }
    }
  }
}

function productinfo_rotate() {
  productinfo_next();
}
