$().ready(function(){

	// animations

	// forms

	//$(function(){ 
	// find all the input elements with title attributes
	//	$('input[title!=""], textarea[title!=""]').hint();
	//});

	// email

	$(function(){
		$('a.email').nospam({
			replaceText: true
		});
	});

	// templates

	$('.section-row:even').prepend('<div class="section-row-shadow-top"></div>');
	$('.section-row:odd').addClass('section-row-odd');
	$('#lightbox ul li').append('<div class="action-btn open-btn">Zoom</div>');

	// navigation

	$('#nav li a').css({
		backgroundPosition: '0 -32px'
	}).hover(
		function () {
			$(this).animate({
				backgroundPosition: '(0 0)'
			}, 200
			)
		}, 
		function () {
			if ( $(this).parent().hasClass('current') )
			{
				$(this).css({backgroundPosition: '0 0'});
			}
			else {
				$(this).animate({
					backgroundPosition: '(0 -32px)'
				},
				{
					duration:250,
					complete:function(){
						$(this).css({backgroundPosition: '0 -32px'});
					}
				})
			}
		}
	);

	// flash overlay

	$('a.show').overlay({
	// clever use of this- variable and link argument
		speed: 100,
		onLoad: function(content, link) {
			content.find('#screen').load(link.attr('href'));
			this.expose({
				speed: 100,
				zIndex: 2,
				color: '#000',
				opacity: .75
			});
		},
		onClose: function(content) { 
			$.unexpose();
			$('#screen object').remove();
		}
	});

	// lightbox

	$('#lightbox').jCarouselLite({
		visible: 6,
	    btnNext: '#lightbox-next-btn',
	    btnPrev: '#lightbox-prev-btn'
	});

	$('#lightbox a').lightBox({
		overlayBgColor: '#000',
		imageLoading: 'wp-content/themes/default/img/loading.gif',
		imageBtnClose: 'wp-content/themes/default/img/blank.gif',
		imageBtnPrev: 'wp-content/themes/default/img/prev-large-btn.png',
		imageBtnNext: 'wp-content/themes/default/img/next-large-btn.png',
		imageBlank: 'wp-content/themes/default/img/blank.gif',
		containerResizeSpeed: 250
	});

	// tables

	$('tr:even').addClass('even');

	// blog

	$('#news .xxw2:last').addClass('last');
	$('#archives .xxw2:nth-child(3)').addClass('last');

	// open new window

		function externalLinks() {
			if (!document.getElementsByTagName) return;
			var anchors = document.getElementsByTagName('a');
			for (var i=0; i<anchors.length; i++) {
				var anchor = anchors[i];
				if (anchor.getAttribute('href') &&
					anchor.getAttribute('rel') == 'external')
					anchor.target = '_blank';
			}
		}

		window.onload = externalLinks;

});