function addPhotoEvents() {
	if(document.getElementsByName('rmr_vote') != undefined) {
		for(i=0; i<document.getElementsByName('rmr_vote').length; i++) {
			document.getElementsByName('rmr_vote')[i].onclick = function() { 
				document.getElementById('rmr_vote_value').value = this.value;
				submitForm(this); 
			}
		}
	}
}

////////////////////////////// Make the Top Tabs Link //////////////////////////////

// Prepate the TABS for Linking
function prepareTab() {	
	if (!document.getElementById("photos_thumbs")) return false;
	var tabs = document.getElementById("photos_thumbs").getElementsByTagName("LI");
	for (var i=0; i<tabs.length; i++) {
		// I like cheese :)
		if (tabs[i].className != "cheese") {
			tabs[i].onmousedown = function() {
				whichTab(this);
			} 
		}
	}
}

// Switch the TABS to Display Selected
function whichTab(whichtab) {
	var tabs = document.getElementById("photos_thumbs").getElementsByTagName("LI");
	for (var i=0; i<tabs.length; i++) {
		if (tabs[i].className == "on") {
			tabs[i].className = "off";
		}
		if (tabs[i].className == "off") {
			//document.getElementById(tabs[i].id+"_content").style.display = "none";
		}
	}
	
	var item = whichtab;
	item.className = "on";
	
	var element=item.id; 
	
	//document.getElementById(element+"_content").style.display = "block";
}

////////////////////////////// Integrate Previous and Next Slider //////////////////////////////

var i1 = 0;
var i2 = 0;
var item_width = 86;

// Prepare the THUMBNAILS for Linking Next
function prepareThumbsNext() {
	if (!document.getElementById("thumbs_next")) return false;

	var nav_link = document.getElementById("thumbs_next");	
	nav_link.onmousedown = function() {
		movement = setTimeout("scrollThumbsNext()", 10);
		movement;
	}
}

// Move the THUMBNAILS to Scroll Next
function scrollThumbsNext() {
	if (!document.getElementById("photos_thumbs")) return false;
	var nav_images = document.getElementById("photos_thumbs"); //images container
	var list_items = nav_images.getElementsByTagName("li").length; //images
	var total_distance = ((list_items - 7) * (item_width + 1)) * -1; //total distance for the images.  this does not include the original two images and should be a negative number for moving the pictures left
	
	var current_left = parseInt (nav_images.style.left); //get the current position of the images
	if (current_left <= total_distance) { //if the images are further than the total distance, exit
		i1 = 0;
		return true;
	} else {
		if (i1 < -2) { //call this function 3 times recursively to emulate a scrolling effect.
			i1 = 0;
			nav_images.style.left = (parseInt(nav_images.style.left) - 1) + "px"; //move the image
			return true;
		} else {		
			for (var j1 = 0; j1 < (item_width / 3); j1++) {
				current_left = current_left - 1;
				nav_images.style.left = current_left + "px"; //move the image
			}
		
			move = setTimeout("scrollThumbsNext()", 10);
			i1--;
		}
	}
}

// Prepare the THUMBNAILS for Linking Back
function prepareThumbsBack() {
	if (!document.getElementById("thumbs_back")) return false;

	var nav_link = document.getElementById("thumbs_back");	
	nav_link.onmousedown = function() {
		movement = setTimeout("scrollThumbsBack()", 10);
		movement;
	}
}

// Move the THUMBNAILS to Scroll Back
function scrollThumbsBack() {
	if (!document.getElementById("photos_thumbs")) return false;
	var nav_images = document.getElementById("photos_thumbs"); //images container
	var list_items = document.getElementById("photos_thumbs").getElementsByTagName("li").length; //images
	var total_distance = ((list_items - 7) * (item_width + 1)) * -1; //total distance for the images.  this does not include the original two images and should be a negative number for moving the pictures left
	
	var current_left = parseInt (nav_images.style.left); //current location of the image
	if (current_left >= 0) { //if the images are further than the total distance, exit
		i2 = 0;
		return true;
	} else {
		if (i2 > 2) { //call this function 3 times recursively to emulate a scrolling effect.
			i2 = 0;
			nav_images.style.left = (parseInt(nav_images.style.left) + 1) + "px"; //move the image
			return true;
		} else {
			for (var j2 = 0; j2 < (item_width / 3); j2++) {
				current_left = current_left + 1;
				nav_images.style.left = current_left + "px";
			}
		
			move = setTimeout("scrollThumbsBack()", 10);
			i2++;
		}
	}
}

//disable the slider for the opera browser as it does not support the overflow:hidden style.
function disableSlider() {
	//disable the overflow: hidden style for the div and change it to overflow: auto
	document.getElementById("slide").style.overflow = "auto";
	//disable the arrow bars
	document.getElementById("scroll_left").style.display = "none";
	document.getElementById("scroll_right").style.display = "none";
	//determine the size required for the overflow div
	var olsize = document.getElementById("photos_thumbs").getElementsByName("li").length * (82);
	//reduce the size of the overflow OL for the scroll bar.
	document.getElementById("photos_thumbs").style.width = olsize;
	//document.getElementById("photos_thumbs").style.height = 135;
}

////////////////////////////// Make the Photos Thumbnails Clickable //////////////////////////////

// Display the Appropriate PHOTO for Display
function showPic(whichpic) {
	var source_title = whichpic.getAttribute("title");
	var source = whichpic.getAttribute("source");
	var source_link = whichpic.getAttribute("source_link");
	var image_div = document.getElementById('image');

	image_div.innerHTML = '<a href="' + source_link + '" rel="lightbox[photoset]" id="" title="' + source_title + '"><img src="' + source + '" id="photos_placeholder" alt="" title="" width="478" height="359" /></a>';
	var objImage = document.getElementById('photos_placeholder');
	//objImage.setAttribute("href",source_link);
	objImage.setAttribute("title",source_title);
	return false;
}

// Prepare the PHOTO GALLERY for Linking
function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("photos_thumbs")) return false;
  var gallery = document.getElementById("photos_thumbs");
  var links = gallery.getElementsByTagName("img");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
    links[i].onkeypress = links[i].onclick;
  }
}

////////////////////////////// Execute the Necessary Functions //////////////////////////////
addLoadEvent(prepareTab);
addLoadEvent(prepareGallery);
if (navigator.appName == "Opera") {
	addLoadEvent(disableSlider);
} else {
	addLoadEvent(prepareThumbsNext);
	addLoadEvent(prepareThumbsBack);
}
addLoadEvent(addPhotoEvents);