$(document).ready(function() {

	// Open external links in new Window/Tab
	$("a[href^='http:']").not("[href*='" + window.location.host + "']").attr('target','_blank'); 
	
	// Custom Login injection
	if (document.getElementById('login')) {
	//	$('#backtoblog').append('<h1>You are required to login to view <br/>this section of the website.</h1>');
	//	$('#login').append('<div id="signup"><h2 class="blue">Not a member?</h2><p>Being a Greater Cleveland Safety Council member gives you access to exclusive benefits.</p><p><a href="/membership/" target="_parent" title="Get More Information" class="button"><span>Join Now</span></a></p></div>');
	}
	
	// Sliding Doors Button Fade Like a Total Baller
	$('.button').each(function () {
		$('span', this).addClass('sd');
		$(this).append('<span class="hover"></span><span class="sd2"></span>');
		var thisHover = $(".hover", this);
		$('.sd', this).clone().removeClass('sd').addClass('overlay').appendTo(thisHover);
		var $span = $('> span.hover', this).css('opacity', 0);
		var $span2 = $('> span.sd2', this).css('opacity', 0);
		$(this).hover(function () {
			$span.stop().fadeTo(200, 1);
			$span2.stop().fadeTo(200, 1);
		}, function () {
			$span.stop().fadeTo(200, 0);
			$span2.stop().fadeTo(200, 0);
		});
	});
	
	// 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');
	});
	
	// LavaLamp
	$('.lavaLampWithImage').lavaLamp({
		fx: "easeOutBack",
		speed: 700
	});
	
	// Slideshow
	$('#slideshow').innerfade({
		speed: 'slow',
		timeout: 8500,
		type: 'sequence',
		containerheight: '280px'
	});
	$('#member-slideshow1').innerfade({
		speed: 'slow',
		timeout: 4500,
		type: 'sequence',
		containerheight: '150px'
	});
	$('#member-slideshow2').innerfade({
		speed: 'slow',
		timeout: 4500,
		type: 'sequence',
		containerheight: '150px'
	});
	$('#member-slideshow3').innerfade({
		speed: 'slow',
		timeout: 4500,
		type: 'sequence',
		containerheight: '150px'
	});
	
	// Lightbox
	$(".iframe").fancybox({
		'hideOnContentClick': true,
		'titleShow': false, 
		'width': 700,
		'height': 600
	});
	
	$(".loginiframe").fancybox({
		'type': 'iframe',
		'width': 710,
		'height': 360,
		'hideOnContentClick': false
	});
	
	// 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
	$('#s').focus(function () {
		if ($('#s').val() == 'Search WP Testbed') {
			$('#s').val('');
			$('#s').css({'color' : '#124d7a', 'font-weight' : 'bold'}); //active
		}
	});
	
	$('#s').blur(function () {
		if ($('#s').val() == '') {
			$('#s').val('Search WP Testbed');
			$('#s').css({'color' : '#a2a2a2', 'font-weight' : 'normal'}); //inactive
		}
	});
	
});
