
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
function newImage(arg) {
	if (document.images) { 
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4)		return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
var preloadFlag = false;
function changeImages() {
	if (document.images && (preloadFlag == true)) {

		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (document.layers) {
				img = findElement(changeImages.arguments[i],0);
			}
			else {
				img = document.images[changeImages.arguments[i]];
			}
			if (img) {
				img.src = changeImages.arguments[i+1];
			}
		}
	}
}


function ajaxFunction(page, photo, bcp, accom_sub){
	var ajaxRequest; 
	
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your Browser does not support this function");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('page_photo');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var url = "get_photo.php?" + "p=" + page + "&f=" + photo;
	if ( bcp != "" ) 
		url = url + "&bcp=" + bcp;
	if ( accom_sub != "" )
		url = url + "&accom_sub=" + accom_sub;
		
/* 	alert( "requesting" + url); */
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}




var popUpWin = null;

function popUpWindow(URLStr, left, top, width, height)
{
	if ( popUpWin &&  !popUpWin.closed ) popUpWin.close();
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function open_window(url) {
	mywin = window.open( url, "win", 
	'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1,width=820,height=620');
}



function register_photo(myPage, largePath, photo, nextPhoto, previousPhoto, bcp_, accom_)
{
	$("#photo_nav a").not("#prev_anchor, #next_anchor").each( 
			function(i) {
				$(this).click( 
					function(e) {
						e.preventDefault();
						$("#photo a").html("<img src=\"images/loading.gif\" style=\"margin-top: 120px\" alt=\"\" />");
						$.get(
							'get_photo.php', 
							{ p: myPage, f: i + 1, bcp: bcp_ , accom_sub: accom_},
							function(data) {$("#page_photo").html(data); }
						); // end $.get
				}); // end $(this).click
			});  // end each  
						
		$("#prev_anchor").click( function(e) {
				e.preventDefault(); 
				$.get('get_photo.php', 
					{ p: myPage, f: previousPhoto, bcp: bcp_, accom_sub: accom_ } , 
					function(data) {  $("#page_photo").html(data); } 
				) 
			}
		);

		$("#photo a, #next_anchor").click( function(e) { 
				e.preventDefault();
				$.get('get_photo.php',	
					{ p: myPage, f: nextPhoto,	bcp: bcp_, accom_sub: accom_	}, 
					function(data) {  $("#page_photo").html(data); }
				)
			}
		);
				
		$("#show_large").click( 
			function(e) {
				e.preventDefault();
				open_window(largePath);
			}
		);

		$("#show_large_bc").click( 
			function(e) {
				e.preventDefault();
				open_window(largePath);
			}
		);
	
}

function handleLoading(src)
{
	$("#photo a").html("<img src=\"images/loading.gif\" style=\"margin-top: 120px\" alt=\"\" />");
	var img = new Image();
	$(img).load(function () {
		var i = $(this);
		$(this).hide();
		$("#photo a").find("img").fadeTo(100, 0.1, function() {
				$(this).remove();
				$("#photo a").append(i);});
		$(this).fadeIn();
	  }).error(function () {})
	  .css('display', 'inline')
	  .attr('src', src);
}



jQuery.extend({
	 getURLParam: function(strParamName){
		  var strReturn = "";
		  var strHref = window.location.href;
		  var bFound=false;
		  
		  var cmpstring = strParamName + "=";
		  var cmplen = cmpstring.length;

		  if ( strHref.indexOf("?") > -1 ){
		    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
		    var aQueryString = strQueryString.split("&");
		    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
		      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
		        var aParam = aQueryString[iParam].split("=");
		        strReturn = aParam[1];
		        bFound=true;
		        break;
		      }
		      
		    }
		  }
		  if (bFound==false) return null;
		  return strReturn;
		}
});



$(document).ready(function(){
	$('#content').hide(0);
	$('#content').fadeIn(1500);
	
	if ( $.getURLParam('p') == 'accom')
	{
		$("#page_text ul").find("div").hide();
		$("#page_text ul").find("a").click( 
				function(e) {
					e.preventDefault();
					$("#page_text ul").find("div").hide(150);
		 			$(this).next().toggle(400);
				 	$.get(
				 		 	'get_photo.php', 
				 		 	{
						 		p:'accom', 
						 		accom_sub: $(this).attr("id")
						 	}, 
						 	function(data) {
				 				$('#page_photo').html(data);
				 			}
				 	); 
		 		}
		);
	}
});