/*
	START PHOTO ALBUMS
*/
var _current_loaded_gallery,_current_loaded_photo;
function load_album(int,photo) {

	if(photo==null) {
		photo=0;
	}
	
	if(gallery_thumbnails[int]) {	
		var div=document.getElementById("gallery_list_div");
		var imgs=div.getElementsByTagName("img");

		for(var x=0;x<imgs.length;x++) {		
			imgs[x].src=gallery_thumbnails[x].inactive.src;		
			imgs[x].className="";
		}

		imgs[int].src=gallery_thumbnails[int].active.src;
		imgs[int].className="gallery_selected";
		
		
		var div=document.getElementById("photo_list_div");
		div.innerHTML='';
		var str='';
		for(var x=0;x<gallery_thumbnails[int].photos.length;x++) {
			if(x==0) {
				var src=gallery_thumbnails[int].photos[x].active;
				var id_str='id="photo_selected"';
			} else {
				var src=gallery_thumbnails[int].photos[x].inactive;
				var id_str='';
			}
			str+='<a href="javascript:load_photo('+x+');"><img src="'+src+'" alt="" '+id_str+'/></a>';
		}
		div.innerHTML=str;				
		document.getElementById("gal_name").innerHTML=gallery_thumbnails[int].name;
		document.getElementById("gal_desc").innerHTML=gallery_thumbnails[int].description;
		if(gallery_thumbnails[int].description=="") {
			document.getElementById("gal_desc").style.display="none";
		} else {
			document.getElementById("gal_desc").style.display="";
		}
		
		_current_loaded_gallery=int;
		load_photo(photo,1);
		update_gal_arrows();
		display_gallery_thumbs();
	}
}

function load_photo(int,firstload) {
	var div=document.getElementById("photo_list_div");
	var imgs=div.getElementsByTagName("img");
	var max_to_display=6;
	
	for(var x=0;x<gallery_thumbnails[_current_loaded_gallery].photos.length;x++) {		
			imgs[x].src=gallery_thumbnails[_current_loaded_gallery].photos[x].inactive;
			imgs[x].id="";
			if(firstload==1) {
				imgs[x].style.display=((x<max_to_display)?'block':'none');
			}
	}
	
	imgs[int].src=gallery_thumbnails[_current_loaded_gallery].photos[int].active;
	imgs[int].id="photo_selected";
	document.getElementById("photo_galery_loaded").src=gallery_thumbnails[_current_loaded_gallery].photos[int].loaded;
	
	document.getElementById("photo_desc").innerHTML=gallery_thumbnails[_current_loaded_gallery].photos[int].description;
	if(gallery_thumbnails[_current_loaded_gallery].photos[int].description=="") {
		document.getElementById("photo_desc").style.display="none";
	} else {
		document.getElementById("photo_desc").style.display="";
	}
	
	_current_loaded_photo=int;
	update_photo_arrows();
	display_photo_thumbs();
}

function change_gallery(int){
	var i=parseInt(_current_loaded_gallery+int);	
	
	if(gallery_thumbnails[i]) {
		load_album(i);
	}	
}

function change_photo(int){
	var i=parseInt(_current_loaded_photo+int);	
	
	if(gallery_thumbnails[_current_loaded_gallery].photos[i]) {
		load_photo(i);
	}	
}

function update_gal_arrows() {
	if(gallery_thumbnails[(_current_loaded_gallery+1)]) {
		document.getElementById("next_gal_image").src="/images/arrow_large_right.gif";
	} else {
		document.getElementById("next_gal_image").src="/images/arrow_large_right_gray.gif";
	}

	if(gallery_thumbnails[(_current_loaded_gallery-1)]) {
		document.getElementById("prev_gal_image").src="/images/arrow_large_left.gif";
	} else {
		document.getElementById("prev_gal_image").src="/images/arrow_large_left_gray.gif";
	}
}

function update_photo_arrows() {
	if(gallery_thumbnails[_current_loaded_gallery].photos[_current_loaded_photo+1]) {
		document.getElementById("next_photo_image").src="/images/arrow_small_right.gif";
	} else {
		document.getElementById("next_photo_image").src="/images/arrow_small_right_gray.gif";
	}

	if(gallery_thumbnails[_current_loaded_gallery].photos[_current_loaded_photo-1]) {
		document.getElementById("prev_photo_image").src="/images/arrow_small_left.gif";
	} else {
		document.getElementById("prev_photo_image").src="/images/arrow_small_left_gray.gif";
	}
}

function display_gallery_thumbs() {

	var max_to_display=8;
	var current_displayed_min=0;

	var div=document.getElementById("gallery_list_div");
	var img=div.getElementsByTagName("img");

	var loaded_is_displayed=false;
	var current_displayed_min=0;

	var found_displayed=false;
	for(var x=0;x<img.length;x++) {
		if(x==_current_loaded_gallery) {
			if(img[x].style.display=="block") {
				loaded_is_displayed=true;
				break;
			}
		}

		if(img[x].style.display=="block") {
			if(found_displayed==false) {
				current_displayed_min=x;
			}
			found_displayed=true;
		}
	}
	
	if(loaded_is_displayed==false) {
		if(_current_loaded_gallery>=max_to_display) {
			var offset=(_current_loaded_gallery+1)-max_to_display;
		} else {
			var offset=_current_loaded_gallery;
		}
		// the desired gallery is not in view, change views to accomodate
		for(var x=0;x<img.length;x++) {
			if(x>=offset && x<(offset+max_to_display)) {
				img[x].style.display="block";
			} else {
				img[x].style.display="none";
			}
		}
	}
}

function display_photo_thumbs() {

	var max_to_display=6;
	var current_displayed_min=0;

	var div=document.getElementById("photo_list_div");
	var img=div.getElementsByTagName("img");

	var loaded_is_displayed=false;
	var current_displayed_min=0;

	var found_displayed=false;
	for(var x=0;x<img.length;x++) {
		if(x==_current_loaded_photo) {
			if(img[x].style.display=="block") {
				loaded_is_displayed=true;				
				break;
			}
		}

		if(img[x].style.display=="block") {
			if(found_displayed==false) {
				current_displayed_min=x;
			}
			found_displayed=true;
		}
	}
	
	
	if(loaded_is_displayed==false) {
		if(_current_loaded_photo>=max_to_display) {
			var offset=(_current_loaded_photo+1)-max_to_display;
		} else {
			var offset=_current_loaded_photo;
		}
		// the desired gallery is not in view, change views to accomodate
		for(var x=0;x<img.length;x++) {
			if(x>=offset && x<(offset+max_to_display)) {
				img[x].style.display="block";
			} else {
				img[x].style.display="none";
			}
		}
	}
}

/*
	END PHOTO ALBUMS
*/

function load_video(int) {	
	if(video_gallery[int]) {		
		var h2=document.getElementById("video_details");		
		h2.innerHTML=video_gallery[int].name+" - "+parseInt(video_gallery[int].minutes)+":"+((parseInt(video_gallery[int].seconds.length)==1)?"0":"")+parseInt(video_gallery[int].seconds);
		document.getElementById("playerFrame").src="/qtplayer.php?w=500&h=419&movie=/library/media/"+video_gallery[int].video;
	}
}

// add the .click() method to html elements
try{
	HTMLElement.prototype.click = function()
	{
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}catch(e){;}

function getAjaxObj(func)
{
	var xmlhttp=false;
	if(window.XMLHttpRequest)
	{
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			// 4 = "loaded"
			if (xmlhttp.status==200)
			{
				// 200 = OK					
				if(xmlhttp.responseText!="")
				{	
					if(func==null)
						eval(xmlhttp.responseText)
					else
						func(xmlhttp.responseText)
				}
			}
			else
			{
				alert("Problem retrieving XML data");
			}
		}
	};
	return xmlhttp;
}