var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function scrollNews(ypos){
      document.getElementById('newsbox').scrollTop=ypos;
      //alert(document.getElementById('newsbox').scrollTop);
}

function makeInfo(sDom, sUser){
	a = sUser+"@"+sDom.replace(/%23/g,".");
	b = "mai"+"lto:"+a;
    return('<a href="'+b+'">'+a+'</a>');
} 

function mainNav() {
var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

stylep = ""; stylec = "";
document.write('<div id="navbar2">');
document.write('<ul>');
document.write('<li><a href="index.html" onFocus="this.blur()">Home</a></li>');
if (sPage == "press.html")
	stylep = "class='on'";
document.write('<li><a href="press.html" onFocus="this.blur()" '+stylep+'>Press</a></li>');
if (sPage == "contact.html")
	stylec = "class='on'";
document.write('<li><a href="contact.html" onFocus="this.blur()" '+stylec+'>Contact</a></li>');
document.write('<li><a href="javascript:popWindow(\'xmlLoad.html\',400,445)" onFocus="this.blur()">Photos</a></li>');
document.write('</ul>');
document.write('</div>');

}

/*function autoFireLightbox() {
	$(function() {
			//Check if location.hash matches a lightbox-anchor. If so, trigger popup of image.
			setTimeout(function() {
				if(document.location) {
					$('a[@rel*=lightbox]').lightBox();
				}},
				250
			);
		}
		Event.observe(window, 'load', autoFireLightbox, false);*/

function makeInfo(sDom, sUser){
	a = sUser+"@"+sDom.replace(/%23/g,".");
	b = "mai"+"lto:"+a;
    return('<a href="'+b+'">'+a+'</a>');
}

//Load everything
$(document).ready(function() {
	
  $('a#slick-show').click(function() {
		$('#slickbox').show('slow');
		return false;
  });
	
	$('a#eh-show').click(function() { $('#ehbox').show('slow');	return false; });
	$('a#hf-show').click(function() { $('#hfbox').show('slow');	return false; });
	$('a#tlone-show').click(function() { $('#tlonebox').show('slow');	return false; });
	$('a#tltwo-show').click(function() { $('#tltwobox').show('slow');	return false; });	
	
// hides the slickbox on clicking the noted link
  
	$('a#slick-hide').click(function() {
	$('#slickbox').hide('fast');
	return false;
  });
	
	$('a#eh-hide').click(function() { $('#ehbox').hide('fast');	return false; });
	$('a#hf-hide').click(function() { $('#hfbox').hide('fast');	return false; });
	$('a#tlone-hide').click(function() { $('#tlonebox').hide('fast');	return false; });
	$('a#tltwo-hide').click(function() { $('#tltwobox').hide('fast');	return false; });
	
 // toggles the slickbox on clicking the noted link

  $('#slick-toggle').click(function() {
		if (BrowserDetect.OS=="Mac")
			document.getElementById('newsbox').style.overflow = "hidden";
		if (document.getElementById('slick-toggle').value=="Show News" && BrowserDetect.browser=="Safari") {
			document.getElementById('newsbox').style.overflow = "auto";   }
		$("#slickbox").slideToggle("slow",function(){
		toggleNewsButtonLabel(); });
	return false;
  });
	
$('a#even-more-btn').click(function() {
 $("#mainframe").animate({width: 'toggle'});
  });

	$('div#eh-cover').click(function() {
	$("#ehbox").slideToggle("slow",function(){
		toggleButtonLabel("eh-toggle");
		});
	return false;
  });
	
	$('#eh-toggle').click(function() {
	$("#ehbox").slideToggle("slow",function(){
		toggleButtonLabel("eh-toggle");
		});
	return false;
  });
	
	$('div#hf-cover').click(function() {
	$("#hfbox").slideToggle("slow",function(){
	toggleButtonLabel("hf-toggle");
		});
	return false;
  });
	
	$('#hf-toggle').click(function() {
	$("#hfbox").slideToggle("slow",function(){
	toggleButtonLabel("hf-toggle");
		});
	return false;
  });
	
	$('div#tlone-cover').click(function() {
	$("#tlonebox").slideToggle("slow",function(){
		toggleButtonLabel("tlone-toggle");
		});
	return false;
  });
	
	$('#tlone-toggle').click(function() {
	$("#tlonebox").slideToggle("slow",function(){
		toggleButtonLabel("tlone-toggle");
		});
	return false;
  });

$('div#tltwo-cover').click(function() {
	$("#tltwobox").slideToggle("slow",function(){
		toggleButtonLabel("tltwo-toggle");
		});
	return false;
  });
	
	$('#tltwo-toggle').click(function() {
	$("#tltwobox").slideToggle("slow",function(){
		toggleButtonLabel("tltwo-toggle");
		});
	return false;
  });		

	$('#rw01-toggle').click(function() {
	$("#rw01box").slideToggle("slow",function(){
		toggleButtonLabel("rw01-toggle");
		});
	return false;
  });		
	$('div#rw01-cover').click(function() {
	$("#rw01box").slideToggle("slow",function(){
		toggleButtonLabel("rw01-toggle");
		});
	return false;
  });  

	$('#rw02-toggle').click(function() {
	$("#rw02box").slideToggle("slow",function(){
		toggleButtonLabel("rw02-toggle");
		});
	return false;
  });		
	$('div#rw02-cover').click(function() {
	$("#rw02box").slideToggle("slow",function(){
		toggleButtonLabel("rw02-toggle");
		});
	return false;
  });
	
	
});

function toggleNewsButtonLabel () {
  if (document.getElementById('slick-toggle').value=="Show News") {
    document.getElementById('slick-toggle').value = "Hide News";
    if (BrowserDetect.OS=="Mac")
        document.getElementById('newsbox').style.overflow = "auto";
    }
  else {
    document.getElementById('slick-toggle').value = "Show News";
  }
}

function toggleButtonLabel(btnname) {
	if (document.getElementById(btnname).value=="Show Details") {
		document.getElementById(btnname).value = "Hide Details";
    }
  else {
    document.getElementById(btnname).value = "Show Details";
  }
}

/* Load url into div!!! */
function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
			//Reload prettyPhoto for new images
			$("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 30, /* padding for each side of the picture */
				opacity: 0.65, /* Value betwee 0 and 1 */
				showTitle: false, /* true/false */
				allowresize: false, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
				hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
				modal: false, /* If set to true, only the close button will close the window */
				changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
				callback: function(){} /* Called when prettyPhoto is closed */
			});
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	ahah(name,div);
	return false;
}

function popWindow(pagename,winwidth,winheight) {
	
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	if (!window.opera) { 
		winleft = Math.round((scW-winwidth)/2); 
		wintop = Math.round((scH-winheight)/2); 
	}
	else { 
		winleft = 20; 
		wintop = 20;
	}
	
	pageinfo = 'width='+winwidth+',height='+winheight+'';
	pageinfo += ',directories=no,location=no,menubar=no,';
	pageinfo += 'scrollbars=no,status=yes,toolbar=no,resizable=no,left='+winleft+',top='+wintop;
	popWinHandle = window.open(pagename,'popWinTarget',pageinfo);
	if (!popWinHandle.opener)
		popWinHandle.opener = self;
}


