var old_onload = window.onload;

var picRoll = function(images) {
	var img = images;
	function setCookie(c_name,value,expiredays,path) {
		var exdate=new Date();

		if (path == undefined || path == null) {
			path = "/";
		}

		params = new Array();
		i=0
		params[i++] = c_name + "=" + escape(value);

		if (!(expiredays == null || expiredays == undefined)) {
			exdate.setDate(exdate.getDate()+expiredays);
			params[i++] = "expires=" + exdate.toGMTString()
		}

		params[i++] = "path=" + path;

		document.cookie = params.join(";");
	}
	
	function getCookie(c_name) {
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		    }
		}
		return "";
	}
	
	var cur = parseInt("0" + getCookie("picRoll_lastImage")) || 0;
	try {
		if (img.length && img[cur]) {
			var e = document.getElementById("hdr_banner");
			if (e) {
				e.innerHTML = "<img src='"+img[cur]+"' alt='' />";
				
				cur++;
				if (cur >= img.length) {
					cur = 0;
				}
				
				setCookie("picRoll_lastImage", cur, 7);
			}
		} else {
			cur = 0;
			var e = document.getElementById("hdr_banner");
			if (e) {
				e.innerHTML = "<img src='"+img[cur]+"' alt='' />";
			}
			setCookie("picRoll_lastImage", cur, 7);
		}
	} catch(e) {
	}
};



function picRoll_init() {
	if (picRoll_images && typeof picRoll_images == "object") {
		new picRoll(picRoll_images);
	}
};

if (typeof window.onload == "function") {
	window.onload = function(){
		old_onload();
		picRoll_init();
	}
} else {
	window.onload = function(){
		picRoll_init();
	}
}