
	/*
	 *  preload images
	 */
	
		var preloads = [
			"images/header.jpg",
			"images/nav_bg_hover.gif"
		];
		$.each(preloads,function(i,img){
			var x = new Image;
			x.src = img;
		});
		

/*
 * Console logger
 *  %s	String
 *  %d, %i	Integer (numeric formatting is not yet supported)
 *  %f	Floating point number (numeric formatting is not yet supported)
 *  %o	Object hyperlink
 * 
 *  only logs if globalVars.log = true
 */

	$.log = function() {
	  	if(window.console) {
			if($.browser.safari){
				// Safari console
				var args = "";
				$.each(arguments,function(i,val){
					args += " " + val;
				});
				window.console.log(args); // fix to show args, Safari doesn't like .apply
			}
			if ($.browser.mozilla) {
				// Firefox with firebug
				window.console.log.apply(this, arguments);
			}
	  	} else {
	  		// no Firebug
	    	//alert(message);
		}
	};
	
	
	
	
/* 
 *  fix IE6 link background image flicker bug
 */
//try {  document.execCommand("BackgroundImageCache", false, true); } catch(err) {} 
	
	
	
/* 
 * jQuery actions when DOM is loaded
 */ 

$(document).ready(function(){

	
	
	/*
	 *  De-obfuscate email addresses
	 * 
	 *  replaces email address @ in "mailto" links and link text
	 * 
	 */
		function deobfuscate(x){
			return x.replace("--@--","@");
		}
		$("a").each(function (i){
			var h = this.href;
			if (h.indexOf("mailto")==0) {
				var t = deobfuscate($(this).html());
				this.href = deobfuscate(h);
				$(this).html(t);
			}
		});
	
	/* Google Analytics tracker 
	 *  waits until DOM is loaded to fire tracker event
	 */
		//var pageTracker = _gat._getTracker("UA-5475261-1");
		//pageTracker._trackPageview();

	/* Google Analytics external links
	 *  tags with class="external" target="_blank"
	 *  optional Google Analytics tracking code trigger
	 */
		// (add https and don't include urls that start with site domain
		var pre = "/LINK/";				// prefix to add to URL for GA tracking code
		$('a[href^="http://"]')
			.addClass('external')			// add CSS class for styling
			.attr('target', '_blank')		// open in popup window
			.click(function(){				// GA tracking code
				var href = $(this).attr("href");
				href = href.substr(7,9999);	// trim off http://
				var i = href.indexOf("www.");	// trim off www.
				if (i===0){
					href = href.substr(4,9999);
				}
				href = encodeURI(href);		// encode URL
				$.log(pre + href);			// log href to console
				//pageTracker._trackPageview(pre + href)	// GA tracker code
				//return false;				// cancel link action
			})
		;

		
	/* fancybox image viewer */
	
		$(".thickbox").fancybox({
			'overlayOpacity'		:	0.5,
			'hideOnContentClick': true,
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500,
			'overlayColor'			: "000000"
		});

	// hide reveal content blocks
			$(".reveal-content").hide();
			// reveal trigger event
			$(".reveal-trigger").each(function(){
				// get id
				var id = $(this).attr("rel");
				$.log(id);
				$(this).click(function(){
					// show content block
					$("#"+id).slideDown('fast');
					// hide reveal trigger
					$(this).fadeOut('fast');
					// cancel anchor
					return false;
				});
			});

	/* columns (columns2, columns3, columns4, columns-golden) 
	 * 	usage:
	 *    <div class="columns2">
	 *     <div class="col">content</div>
	 *     <div class="col">content</div>
	 *    </div>
	 */
	
		// add CSS class and clearing
		$(".columns2, .columns3, .columns4, .columns-golden").each(function(){
			//, .columns3>.col:last, .columns4>.col:last, .columns-golden>.col:last")
			var kids = $(this).children();
			$(kids).eq(kids.length-1).addClass("col-last").after('<div class="clear-hidden"></div>');
		});
		
	/* make columns equal height
	 *  usage: <div class="columns-equalheight">
	 */		
		function makeEqualHeight(group) {
			tallest = 0;
			group.each(function() {
				thisHeight = $(this).height();
				if(thisHeight > tallest) {
					tallest = thisHeight;
				}
			});
			group.height(tallest);
		}
		$(".columns-equalheight").each(function(){
			makeEqualHeight($(this).children(".col"));
		});

	/* fancy tables zebra striping */
	
		$("table.results").each(function(){
			$(this).find("tr:even").addClass("even");
			$(this).find("tr:odd").addClass("odd");
			$(this).find("tr:first").removeClass("even").addClass("header");
		});

	/* add clearing elements to gallery */
	
	$("#gallery h2").before("<div class=\"clear-hidden\"></div>");
	
	/* contact form */
	/*
	$("#form-contact #form-submit").click(function(){
		$.log("contact form submitted");
		var ok = true;
		$("#form-contact .required").each(function(){
			var val = $(this).val();
			if (val == "") {
				ok = false;
			}
		});
		if (ok) {
			if(confirm("Are you sure you want to send your comment?")){
				return true;
			}else {
				return false;
			}
		}else {
			alert("Please complete the required information");
			return false;
		}
	});
	*/
	
	/*
	 *  PNG fixer for IE6
	 *  requires jquery_pngfix.js to be loaded before this script
		, use inline IMG width and height	 */
		//$("img[@src$=png]").pngFix();

	/* alernateive PNG fixer
	 * no included script required
	 */
	/*
	function fix_pngs() {
		 if (navigator.appVersion.match(/MSIE [0-6]\./)) {
			 $('.png').each(function () {
		 		if (this.currentStyle.backgroundImage != 'none') {
		 			var image = this.currentStyle.backgroundImage;
		 			image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
			 		if(image.indexOf(".png") !=-1) {
				 		$(this).css({
			 			'backgroundImage': 'none',
		 				'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
		 				});
		 			}
			 	}
		 	});
		 }
		}
	*/
	
	/*
	 *  Innerfade slideshows
	 *  docs: http://medienfreunde.com/deutsch/weblog/aus_der_praxis.html?nid=162
	 *  in CSS set the following to prevent images from showing while page loads:
	 * 	 #container img { display: none; }
	 */ 
		/*
		$(".slideshow").innerfade({
		    animationtype: 'fade',
		    speed: 1500,
		    timeout: 6000,
		    type: 'sequence',
		    containerheight: '200px'
	    });
	    */

	/* BIG BUTTONS 
	 * wraps <input type="submit"> and adds functionality
	 */

	/*
	$("input[type='submit']").each(function(index){
		$(this).wrap("<div class='buttonBig'></div>");
		var label = $(this).attr("value");
		$(this).before("<span class='spacer'>" + label + "</span>");
		// setup hover
		$(this).hover(
			function(){
				// add hover in
				$(this).addClass("active");
			},
			function (){
				// add hover out
				$(this).removeClass("active");
			}
		);
	});
	*/	

	/*
	 *  Disable form submit buttons on click
	 * 
	 *  adds class="form-submit-disabled" 
	 *  unbinds click event
	 *  appends a status message
	 * 
	 */
	 
	/*
	 var sel = "#content_main input.form-submit";
		$(sel).click(function(){
			$(this)
				.parent().append("<span id='form-submit-loading'>Please wait...</span>")
			;
			$(sel)
				.addClass("form-submit-disabled")
				.fadeTo('fast',.25)	// make button look disabled
				.unbind("click")	// prevent clicking again
				.click(function(){return false;})	// disable click event
			;
		});
	*/	 
});
