/* javascript fiiles for HKPC site
*
* October 2008, Steve Fleischer
*
*/

/* ajax for the gallery */

function newRequestObject() {
	var xhro = false;
		if (window.XMLHttpRequest) {
			xhro = 	new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				xhro = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xhro = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					xhro = false;
				}
			}
		}
	return xhro;
}

function displayLoader(element) {
	while (element.hasChildNodes()) {
		element.removeChild(element.lastChild);
	}
	var image = document.createElement("img");
	image.setAttribute("src","images/ajax-loader.gif");
	image.setAttribute("class","noborder");
	image.setAttribute("alt","Image Loading...");
	element.appendChild(image);
}

function getFile(picfile) {
	var req = newRequestObject();
		if (req) {
			displayLoader(document.getElementById("mainimage"))
			req.onreadystatechange = function() {
				showResponse(req);
			};
		req.open("GET", 'getImg.php?picname='+picfile, true);
		req.send(null);
		}
}

function showResponse(req) {
	if (req.readyState == 4) {
		if (req.status == 200 || req.status == 304) {
			var mainpicture = document.getElementById("mainimage");
			mainpicture.innerHTML = req.responseText;
		}
	}		
}

/* determines filename and sets the correct menu item as selected */
$(function(){
   var path = location.pathname;
	var splitpath = new Array();
	splitpath = path.split("/"); 
	 thisfilename = splitpath[1]; 
   if ( thisfilename )
     $('#menu a[@href$="' + thisfilename + '"]').attr('class', 'selected');
 });

/* accordian panels */
$(document).ready(function() {
  $('div.rallypanels:eq(1)> div').hide();
  $('div.rallypanels:eq(0)> h3').click(function() {
	$(this).next().slideToggle('fast');
  });
});

/* test tabs */

$(document).ready(function(){
$('#tests div').hide(); // Hide all divs
$('#tests div:first').show(); // Show the first div
$('#tests ul li:first').addClass('active'); // Set the class for active state
$('#tests ul li a').click(function(){ // When link is clicked
$('#tests ul li').removeClass('active'); // Remove active class from links
 $(this).parent().addClass('active'); //Set parent of clicked link class to active
var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
$('#tests div').hide(); // Hide all divs
$(currentTab).show(); // Show div with id equal to variable currentTab
 return false;
});
});