// JavaScript Document
var photo_c = 0;  // photo total count
var photo_i = 0;  // current photo index
var photo_max = 12;

// Article onload
function articleLoad() {
	setPhotoCount();
	photoTrans();
  transToZero();
}

function setPhotoInt() {
	document.getElementById("art_photo_int").innerHTML = photo_i;
}

function transToZero() {
	if(document.getElementById("art_photo_1") != "Undefined" || document.getElementById("art_photo_1") != null) {		
		imgData = document.getElementById("art_photo_1").innerHTML;
		document.getElementById("art_photo_0").innerHTML = imgData;
		document.getElementById("art_photo_0").style.display = "block";
	}	
}

function replaceMainPhoto(innerContent) {
	document.getElementById("art_photo_0").innerHTML = innerContent;
	 setPhotoInt();
}	

function switchPhoto() {
  var id = "art_photo_" + photo_i;
	updatePhotoDiv = document.getElementById(id).innerHTML	
	replaceMainPhoto(updatePhotoDiv);		
	setPhotoInt();
}

function setPhotoCount() {
  var ele = null;
  var baseid = "art_photo_";
  var id = "";
  // scan for the 1st undefined photo id...
  for (var i=1; i<=photo_max; i++ ) {
    id = baseid + i;
    ele = document.getElementById(id);
    if (ele == "Undefined" || ele == null) {
      break;
    }
  }
  photo_c = i -1;

  if(photo_c > 0) {photo_i = 1;}
	if(photo_c > 1) {
		document.getElementById("art_photo_controls").innerHTML = '<a href="javascript:artPrevPhoto();"><img src="/images/PrevArrow.jpg" /></a><div style="display:block;"><div id="art_photo_int"></div><div id="art_photo_of">&nbsp;of&nbsp;</div><div id="art_photo_count"></div></div><a href="javascript:artNextPhoto();"><img src="/images/NextArrow.jpg" /></a>';
	} else {
		if(document.getElementById("art_photo_controls") != null && document.getElementById("art_photo_controls") != "Undefined") {
			document.getElementById("art_photo_controls").style.height = "0px";
		}
	}
	// alert(photo_c);
	document.getElementById("art_photo_count").innerHTML = photo_c;
	setPhotoInt();
}

function artNextPhoto() {
	if(photo_c == photo_i) {
		photo_i = 1;
	} else {
		photo_i++;
	}
	// photoTrans();
	switchPhoto();
}

function artPrevPhoto() {
	if(photo_i == 1) {
		photo_i = photo_c;
	} else {
		photo_i--;
	}
	// photoTrans();
	switchPhoto();
}

/* hide photos */
function photoTrans() {
  var ele = null;
  var baseid = "art_photo_";
  var id = "";
  // hide any defined photo blocks...
  for (var i=1; i<=photo_max; i++ ) {
    id = baseid + i;
    ele = document.getElementById(id);
    if (ele == "Undefined" || ele == null) {
      continue;
    }
  document.getElementById(id).style.display = "none";
  }

  id = baseid + photo_i;
  //document.getElementById("art_photo_1").style.display = "block";
	setPhotoInt();
}