$(document).ready(function() {
	
	// Show Search Results div when searching
	$('#searchInput').keyup(function () {
		if ($(this).val() == '' || $(this).val() == 'Search') {
			$('#hidden-results').slideUp();
		} else {
			$('#hidden-results').slideDown();
		}
	});
	
	// Open PDFs in a new Window/Tab
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});
	
	// Open external links in new Window/Tab
	$("a[href^='http:']").not("[href*='" + window.location.host + "']").attr('target','_blank'); 

	
	// Home Page Promo Box Logic
	if (document.getElementById('slider')) {
		$('.slider-content').hide();
		$('.slider-content:eq(0)').show();
		$('#slider-menu li').click(function () {
			// Make clicked section active
			$('#slider-menu li').removeClass('selected');
			$(this).addClass('selected');
			$('#slider-menu li div').removeClass('selected');
			$('div', this).addClass('selected');
			
			// Fade in active section's description
			currentIndex = $('#slider-menu li').index($(this));
			$('.slider-content').fadeTo(300,0).css('display', 'none');
			$('.slider-content:eq('+currentIndex+')').fadeTo(600,1);
		});
	}
	
	// Accordion Logic (actually it's not an accordion, but doesn't that sound cooler than "toggler"?)
	$('.element').hide();
	$('.toggler').click(function () {
		$(this).parent().find('.element').slideToggle('slow','jswing');
	});
	
	
	// Home Slideshow
	$('#slideshow').innerfade({
		animationtype: 'fade',
		speed: 1500,
		timeout: 5000,
		type: 'sequence',
		containerheight: '276px'
	});
	
	// Detect Windows to address differences in Georgia font
	var BrowserDetect = {
		init: function () { 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;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		dataOS : [{ string: navigator.platform, subString: "Win", identity: "Windows"}]
	};
	BrowserDetect.init();
	window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser };
	
	if ($.client.os == "Windows") {
		$("#posts").css('width', '230px');	
		$("#address").css('width', '140px');	
	}
	
	// Flexy Buttons
	$('.button').hover(function () {
			$(this).stop().animate({'padding-right': '35px'}, 400, 'easeOutElastic');
		}, function () {
			$(this).stop().animate({'padding-right': '14px'}, 300, 'easeOutBounce');
	});
	
	// Lightbox
	$(".iframe").fancybox({
		'hideOnContentClick': false,
		'titleShow': false
	});
	
	$(".fancybox").fancybox({
		'hideOnContentClick': true,
		'titleShow': false
	});
	
	$("a[href*=.jpg]").fancybox({
		'hideOnContentClick': true,
		'titleShow': false
	});
	
	// Activate LavaLamp Menu
	$('ul#menu>li>ul>li.current_page_item').removeClass().parent().addClass('current_page_item');
	$('ul#menu>li.current_page_ancestor').removeClass().addClass('current_page_item');
	$('ul#menu>li>ul>li').removeClass().addClass('noLava');
	$('ul#menu>li>ul').parent().css('padding-right', '10px');
	$('ul#menu>li>ul').parent().prepend('<img src="/wp-content/themes/the-beck/images/menu-dropdown.png" />');
	$('ul#menu').lavaLamp({
		fx: "easeOutBack",
		speed: 700
	});
	
	// Form Validation
	if (document.getElementById('contact-form')) {
		$("#contact-form").validationEngine({
			
		});
	};
	
	// Fade
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () {
			$span.stop().fadeTo(300, 1);
		}, function () {
			$span.stop().fadeTo(300, 0);
		});
	});
	
	// Input value switcher
	$('#newsletter-name').focus(function () {
		if ($('#newsletter-name').val() == 'Name') {
			$('#newsletter-name').val('');
			$('#newsletter-name').css({'color' : '#464646'}); //active
		}
	});
	
	$('#newsletter-name').blur(function () {
		if ($('#newsletter-name').val() == '') {
			$('#newsletter-name').val('Name');
			$('#newsletter-name').css({'color' : '#b0b0b0'}); //inactive
		}
	});
	
	$('#newsletter-email').focus(function () {
		if ($('#newsletter-email').val() == 'Email Address') {
			$('#newsletter-email').val('');
			$('#newsletter-email').css({'color' : '#464646'}); //active
		}
	});
	
	$('#newsletter-email').blur(function () {
		if ($('#newsletter-email').val() == '') {
			$('#newsletter-email').val('Email Address');
			$('#newsletter-email').css({'color' : '#b0b0b0'}); //inactive
		}
	});
	
	$('#s').focus(function () {
		if ($('#s').val() == 'Search The Beck Center for the Arts') {
			$('#s').val('');
			$('#s').css({'color' : '#464646'}); //active
		}
	});
	
	$('#s').blur(function () {
		if ($('#s').val() == '') {
			$('#s').val('Search The Beck Center for the Arts');
			$('#s').css({'color' : '#b0b0b0'}); //inactive
		}
	});
	
});
