if (window.addEventListener) window.addEventListener("load", init, false);
else if (window.attachEvent) window.attachEvent("onload", init);

var current_index = 0;

function Picture(n, k) {
	this.name = n;
	this.key = k;
}

var pictures = new Array();

function init() {
	if (pictures.length > 0) {
		showPicture(0);
	}
}

function move(dir) {
	current_index += dir;
	if (current_index < 0) current_index = pictures.length - 1;
	else if (current_index >= pictures.length) current_index = 0;
	return showPicture(current_index);
}


function showPicture(idx) {
	if (idx >= pictures.length) return false;
	var el = document.getElementById("current_photo");
	if (el) {
		el.style.backgroundImage = "url(/public-servlet/com.ceiva.servlets.ViewContent?size=full&email_key=" + pictures[idx].key + ")";
	}
	el = document.getElementById("prev");
	if (el) {
		var p = idx - 1;
		if (p < 0) p = pictures.length - 1;
		setPicture(el, "full", pictures[p].key);
	}
	el = document.getElementById("next");
	if (el) {
		var n = idx + 1;
		if (n >= pictures.length) n = 0;
		setPicture(el, "full", pictures[n].key);
	}
	for (var i = 0; i < pictures.length; i++) {
		el = document.getElementById("skip_" + i);
		if (i == idx) {
			el.style.background = "#077aab";
			el.style.color = "#fff";
			el.style.padding = "4px";
			el.style.textDecoration = "none";
		} else {
			el.style.background = "#FFF";
			el.style.padding = "4px";
			el.style.fontWeight= "bold";
			el.style.textDecoration = "none";
			el.style.color = "#001040";
		}
	}
	return false;
}

var selPics = new Array();
function selct(pic, noOfPics) { // alert(document.getElementById(pic).style.backgroundColor);
	if(document.getElementById(pic).style.backgroundColor=="")
		document.getElementById(pic).style.backgroundColor = "rgb(255, 255, 255)";

	if(document.getElementById(pic).style.backgroundColor == "rgb(255, 255, 255)")
		 document.getElementById(pic).style.backgroundColor="rgb(139, 185, 223)";
	else document.getElementById(pic).style.backgroundColor="rgb(255, 255, 255)";

	selPics = new Array();
	if(pictures.length>0) {
		for(i=0; i<pictures.length; i++) { 
			if(document.getElementById(pictures[i].key).style.backgroundColor == "rgb(139, 185, 223)" ) 
				selPics[selPics.length] = pictures[i].key;
		}
	}
}

function selctAll() { //	alert("select all"+ selPics.length);
	
	if(pictures.length>0) {
		for(i=0; i<pictures.length; i++) {
			document.getElementById(pictures[i].key).style.backgroundColor = "rgb(139, 185, 223)";
		}
	}	
}

function selctNone() { // alert("select none.");
	
	if(pictures.length>0) {
		for(i=0; i<pictures.length>0; i++) 
			document.getElementById(pictures[i].key).style.backgroundColor = "rgb(255, 255, 255)";
	}
	
}

function setPicture(el, size, key) {
	el.style.backgroundImage = "url(/public-servlet/com.ceiva.servlets.ViewContent?size=" + size + "&email_key=" + key + ")";
}


