$(document).ready(function(){

	//globals ************************************************
	// - declare IE6, or not. (declared in /js/ie6.js)
	IE6 = (typeof IE6 == 'undefined') ? false : true;

	//email nospam ************************
	$('a.email').nospam({replaceText: true, filterLevel: 'low'});

	//modals ************************
	$('a.modal, button.modal').click(function() {

		//trigger- button or link, or else?
		switch(true) {
			case this.type == 'button' : var target = $('#'+this.name); break;	//buttons use name tag without hash symbol
			default : var target = $(this.hash);								//links use hashed href
		}

		//create modal-mask
		$('body').append("<div id='modal-mask'></div>");

		//Set height and width to mask to fill entire screen, fade in, attach close event
		$('#modal-mask')
		.css({'width' : $(window).width(), 'height' : $(document).height()})
		.fadeTo(120,0.7)
		.live('click', function() {
			$(target).hide();
			$(this).remove();
			return false;
		});

		//scroll content window to top (incase the user has scrolled down when previously used)
		$('.modal-window-scroll', target).animate({scrollTop:0}, 'fast');

		//attach close event to any close buttons in the target popup
		$('.modal-window-footer button', target).live('click', function() {
			$(target).hide();
			$('#modal-mask').remove();
			return false;
		});

		//Set the popup window to center, then show it.
		$(target)
		.css({'top' : parseInt($(window).height()/2-$(target).height()/2,10), 'left' : parseInt($(window).width()/2-$(target).width()/2,10)})
		.show();

		//ie6 requires some help
		if(IE6) {
			$(target).bgiframe();
		}

		//close on escape key
		$(document).keyup(function(e) {
		  	if (e.keyCode == 27) { //escape key
				$('#modal-mask').click();
				$(document).unbind('keyup');
			} 
		});

		return false;
	});

});


/* Functions
-------------------------------------------------------------- */

/* Plugins
-------------------------------------------------------------- */
// http://www.leftrightdesigns.com/library/jquery/nospam/ - nospam plugin
jQuery.fn.nospam=function(settings){settings=jQuery.extend({replaceText:false,filterLevel:'normal'},settings);return this.each(function(){e=null;if(settings.filterLevel=='low'){if($(this).is('a[rel]')){e=$(this).attr('rel').replace('//','@').replace(/\//g,'.');}else{e=$(this).text().replace('//','@').replace(/\//g,'.');}}else{if($(this).is('a[rel]')){e=$(this).attr('rel').split('').reverse().join('').replace('//','@').replace(/\//g,'.');}else{e=$(this).text().split('').reverse().join('').replace('//','@').replace(/\//g,'.');}} if(e){if($(this).is('a[rel]')){$(this).attr('href','mailto:'+e);if(settings.replaceText){$(this).text(e);}}else{$(this).text(e);}}});};

/* Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net) Licensed under the MIT License (LICENSE.txt).
 * bgiframe Plugin fixes z-index issues when an absolute positioned element is over a select box.
 * Version 2.1.2
 */
(function(a){a.fn.bgiframe=(a.browser.msie&&/msie 6\.0/i.test(navigator.userAgent)?function(d){d=a.extend({top:"auto",left:"auto",width:"auto",height:"auto",opacity:true,src:"javascript:false;"},d);var c='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+d.src+'"style="display:block;position:absolute;z-index:-1;'+(d.opacity!==false?"filter:Alpha(Opacity='0');":"")+"top:"+(d.top=="auto"?"expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+'px')":b(d.top))+";left:"+(d.left=="auto"?"expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+'px')":b(d.left))+";width:"+(d.width=="auto"?"expression(this.parentNode.offsetWidth+'px')":b(d.width))+";height:"+(d.height=="auto"?"expression(this.parentNode.offsetHeight+'px')":b(d.height))+';"/>';return this.each(function(){if(a(this).children("iframe.bgiframe").length===0){this.insertBefore(document.createElement(c),this.firstChild)}})}:function(){return this});a.fn.bgIframe=a.fn.bgiframe;function b(c){return c&&c.constructor===Number?c+"px":c}})(jQuery);

