
var xmlhttp,alerted

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.

	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")

	} catch (e) {

		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

		} catch (E) {
			alert("You must have Microsofts XML parsers available")

		}

	}

@else
 alert("You must have JScript version 5 or above.")
 xmlhttp=false
 alerted=true
@end @*/

if (!xmlhttp && !alerted) {
 // Non ECMAScript Ed. 3 will error here (IE<5 ok), nothing I can
 // realistically do about it, blame the w3c or ECMA for not
 // having a working versioning capability in  <SCRIPT> or
 // ECMAScript.

	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		 alert("You need a browser which supports an XMLHttpRequest Object.")
	}
}



var load_msg_gallery = "<div id=\"popup_load_msg\">Loading Gallery<br />Please Wait</div>";

function gallery_thumb_load_message() {
	form_body = document.getElementById('popup_thumbs_items');
	
	form_body.innerHTML = load_msg_gallery;

}


function gallery_teaser_over(elm) {
	elm_child = elm.childNodes[0];
	
	i=1;
	
	while ((elm_child.className != "gallery_teaser_over") && (i < 10) ) {
		elm_child = elm.childNodes[i];
	
		i=i+1;
	
	}
	
	elm_child.style.display = "block";
	
}

function gallery_teaser_out(elm) {
	elm_child = elm.childNodes[0];
	
	i=1;
	
	while ((elm_child.className != "gallery_teaser_over") && (i < 10) ) {
		elm_child = elm.childNodes[i];
	
		i=i+1;
	
	}
	
	elm_child.style.display = "none";

}

function gallery_open_listen() {
	if (xmlhttp.readyState==4) {
		var listener_response = xmlhttp.responseText;

		thumbs_items = document.getElementById('popup_thumbs_items');
		thumbs_items.innerHTML = listener_response;

		first_thumb = thumbs_items.childNodes[0];
		
		if (first_thumb != null) {
			photo = document.getElementById('popup_main_photo');
			caption = document.getElementById('popup_main_caption');

			thumb_caption_id = first_thumb.id + "_caption";

			thumb_caption = document.getElementById(thumb_caption_id);

			if (photo != null) {

				photo.src = first_thumb.src;

				if (photo.style.display=="none") {
					photo.style.display = "block";
				}
				
			}

			if (caption != null) {
				caption.innerHTML = thumb_caption.innerHTML;
			}

		
		}
		
		thumb_viewport = document.getElementById('popup_thumbs_viewport');
		thumb_items = document.getElementById('popup_thumbs_items');
		
		if (thumb_viewport != null) {
			if (thumb_items != null) {
				if (thumb_items.offsetHeight > thumb_viewport.offsetHeight) {
					bt_down = document.getElementById('popup_thumbs_button_down');
					
					if (bt_down != null) {	
						bt_down.style.display = "block";
					}
		
				}
		
			}
		}

	}

}

function gallery_open(content_id) {
	gallery_thumb_load_message();

	popup_div = document.getElementById('popup-gallery');
	fade_div = document.getElementById('popup-page_fade');
	
	photo = document.getElementById('popup_main_photo');

	if (photo != null) {
		photo.src = null;
		photo.style.display = "none";
	}
	
	var view1 = new Viewport();
	
	if (popup_div != null) {
		popup_div.style.top = (((view1.windowY - 489) / 2) + view1.scrollY) + "px";
		popup_div.style.left = ((view1.windowX - 836) / 2) + "px";

		popup_div.style.display = "block";
	}

	if (fade_div != null) {
		fade_div.style.height = view1.pageY + "px";
		fade_div.style.width = view1.pageX + "px";
		fade_div.style.display = "block";
	}
	
	url_var = "content_id=" + content_id;
	
	if (xmlhttp) {
		xmlhttp.open("POST", "listener_gallery.php", true);
		xmlhttp.onreadystatechange=gallery_open_listen;
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(url_var);
	}

}





function gallery_close() {
	popup_div = document.getElementById('popup-gallery');
	fade_div = document.getElementById('popup-page_fade');
	
	photo = document.getElementById('popup_main_photo');
	caption = document.getElementById('popup_main_caption');
	
	items_div = document.getElementById('popup_thumbs_items');

	if (photo != null) {
		photo.src = null;
		photo.style.display = "none";
	}
	
	if (caption != null) {
		caption.innerHTML = null;
	}
	
	if (items_div != null) {
		items_div.style.top = "0px";
		items_div.innerHTML = null;
	}

	if (popup_div != null) {
		popup_div.style.display = "none";
	}

	if (fade_div != null) {
		fade_div.style.display = "none";
	}
}


function gallery_thumb_click(thumb) {
	photo = document.getElementById('popup_main_photo');
	caption = document.getElementById('popup_main_caption');
	
	thumb_caption_id = thumb.id + "_caption";
	
	thumb_caption = document.getElementById(thumb_caption_id);
	
	if (photo != null) {

		photo.src = thumb.src;
		
		if (photo.style.display=="none") {
			photo.style.display = "block";
		}
	}
	
	if (caption != null) {
		caption.innerHTML = thumb_caption.innerHTML;
	}

}

/*
function gallery_thumbs_scroll_up() {
	items_div = document.getElementById('popup_thumbs_items');

	if (items_div.offsetTop < 0) {	
		move_px = (items_div.offsetTop + 447);

		items_div.style.top = move_px + "px";
	}
	
	calc_height = ( (items_div.offsetTop * -1) + 447)

	//alert(calc_height + " : " + items_div.offsetHeight);

	if (items_div.offsetTop == 0) {
		scroll_up = document.getElementById('popup_thumbs_button_up');

		if (scroll_up != null) {	
			scroll_up.style.display = "none";
		}

	}

	if ( calc_height < items_div.offsetHeight) {
		scroll_down = document.getElementById('popup_thumbs_button_down');
		
		if (scroll_down != null) {
			scroll_down.style.display = "block";		
		}
	}	

}

function gallery_thumbs_scroll_down() {
	items_div = document.getElementById('popup_thumbs_items');
		
	calc_height = ( (items_div.offsetTop * -1) + 447)
	
	if ( calc_height < items_div.offsetHeight) {
		move_px = (items_div.offsetTop - 447);

		items_div.style.top = move_px + "px";
	}
	
	if (items_div.offsetTop < 0) {
		scroll_up = document.getElementById('popup_thumbs_button_up');

		if (scroll_up != null) {	
			scroll_up.style.display = "block";
		}

	}
	
	calc_height = ( (items_div.offsetTop * -1) + 447)

	if ( calc_height > items_div.offsetHeight) {
		scroll_down = document.getElementById('popup_thumbs_button_down');
		
		if (scroll_down != null) {
			scroll_down.style.display = "none";		
		}
	}

}
*/

function gallery_scroll_at_top() {
	bt_up = document.getElementById('popup_thumbs_button_up');
	
	bt_up.style.display = "none";
}

function gallery_scroll_at_middle() {
	bt_up = document.getElementById('popup_thumbs_button_up');
	bt_down = document.getElementById('popup_thumbs_button_down');

	bt_up.style.display = "block";
	bt_down.style.display = "block";
}

function gallery_scroll_at_bottom() {
	bt_down = document.getElementById('popup_thumbs_button_down');

	bt_down.style.display = "none";
}