$(function() {

	//Content Slider
	var SLIDER_TIMEOUT = 10000;
	var SLIDER_PAUSE = 20000;
	var SLIDER_SPEED = 'slow';
	var sliderTimeout = false;
	var firstScreen = $('a.slider:first');
	firstScreen.addClass('active');
	$('div#slide-panel').css({
		'width' : $('div.screen').width() * $('div.screen').length
	});
	$('div#slide-panel > div.screen').each(function(i,el) {
		var thisScreen = $(this);
		thisScreen.attr('rel',thisScreen.width()*i);
	});
	$('a.slider').click(function(e) {
		clearInterval(sliderTimeout);
		var thisAnchor = $(this);
		var theScreen = $('div#slide-panel > div.'+thisAnchor.attr('href'));
		$('div#slide-panel').animate({
			'marginLeft' : '-'+theScreen.attr('rel')+'px'
		},SLIDER_SPEED,function() {
			$('a.slider').each(function(i,el) {
				var thisElement = $(el);
				if(thisElement.attr('href')==thisAnchor.attr('href')) { thisElement.addClass('active'); }
				else { thisElement.removeClass('active'); }
			});
		});
		e.preventDefault();
	});
	var sliderTimeout = setInterval(function() { doSlide(); },SLIDER_TIMEOUT);
	function doSlide() {
		var activeAnchor = $('div#menu > a.active');
		var firstScreen = $('div#slide-panel > div.screen:first');
		var lastScreen = $('div#slide-panel > div.screen:last');
		var nextScreen = $('div#slide-panel > div.'+activeAnchor.attr('href')).next();
		var newScreen = (!nextScreen.length) ? firstScreen : nextScreen;
		$('div#slide-panel').animate({
			'marginLeft' : '-'+newScreen.attr('rel')+'px'
		},SLIDER_SPEED,function() {
			$('a.slider').each(function(i,el) {
				var thisElement = $(el);
				var classArray = newScreen.attr('class').split(" ");
				//alert(thisElement.attr('href') + ' = ' + classArray[0]);
				if($.inArray(thisElement.attr('href'),classArray)>-1) { thisElement.addClass('active'); }
				else { thisElement.removeClass('active'); }
			}
			);
		});
	}

	// Begin Gallery
	$('div#gallery-prev').hovering({
		'cursor' : 'pointer',
		'background-image' : 'url(images/gallery-prev-over.jpg)'
	}).photostream("prev");
	$('div#gallery-next').hovering({
		'cursor' : 'pointer',
		'background-image' : 'url(images/gallery-next-over.jpg)'
	}).photostream("next");
	$('div#gallery-slide').photostream("display",{
		api_key : '75b9ef5497ac5a826e840d01fcb0abc5',
		photoset_id : '72157624210752711',
		width : '923',
		height : '90',
		show : 10,
		lightbox : 'facebox'
	});
	//End Gallery
	$('input[type=text], textarea').defaultText();
	$('input[type=submit]').hovering({
		'cursor' : 'pointer'
	});
	$('div#notification').click(function() {
		$(this).slideUp("slow");
	}).hovering({
		'cursor' : 'pointer'
	});
	$('a[rel*=facebox]').facebox();

});