( function( $ )
{
	$( document ).ready( function()
	{
		setupHeroSpot();
		setupNewsTicker();
		setupSectionNav();
		setupMenuHoverFallback();
		setupSocialPopout();
		setupPrintButtons();
		setupSharingService();
		setupModals();
		setupForms();
		setupBioExpandos();
		setupFAQExpandos();
	});

	var setupHeroSpot = function()
	{
		var heroSpot = $( ".hero-spots" ).scrollable( {
			continuous: true,
			transition: "crossfade",
			autoCycle: { seconds: 10, holdOnClick: true, holdResumeSeconds: 15 }
		});

		$( ".home-template .hero-spot .controls .prev" ).click( function()
		{
			heroSpot.incrementPage( -1 );
			return false;
		});

		$( ".home-template .hero-spot .controls .next" ).click( function()
		{
			heroSpot.incrementPage( 1 );
			return false;
		});
	};

	var setupNewsTicker = function()
	{
		var newsTicker = $( ".news-ticker" ).scrollable( {
			continuous: true,
			randomAccessNav: false,
			sequentialAccessNav: true,
			scrollSpeed: 400
		});
	};

	var setupSectionNav = function()
	{
		var navToggle = $( ".simple-section-nav" ).navToggle();
	};

	var setupMenuHoverFallback = function()
	{
		if( $.browser.msie )
		{
			$( "ul.menu li" ).hover(
				function() { $( this ).addClass( "hover" ); },
				function() { $( this ).removeClass( "hover" ); }
			);
		}
	};

	var setupSocialPopout = function()
	{
		var socialPopout = $( ".social" ).socialPopout( {
			twitterAccount: "daegis",
			youTubePlaylistID: "C763F912A90A8EA5",
			youTubeChannel: "DaegisEDiscovery",
			wordPressFeedURL: "http://blog.daegis.com/feed/"
		});
	};

	var setupPrintButtons = function()
	{
		// Allow print button to function
		$( ".tools .print" ).click( function()
		{
			window.print();
			return false;
		});
	};

	var setupSharingService = function()
	{
		var a2a_config = a2a_config || {};
		a2a_config.linkname = "Daegis";
		a2a_config.linkurl = "http://www.daegis.com/";
		a2a_config.num_services = 4;
		a2a_config.prioritize = [ "linkedin", "twitter", "facebook" ];
		a2a_config.templates = {
			twitter: "Reading: ${title} ${link} by @daegis"
		};
	};

	var setupModals = function()
	{
		// Setup lead generation links
		$( "a[href*=-lgf-]" ).attr( "rel", "#autoiframe" );

		// Bind #autoiframe modals
		settings = {};
		settings.effect = "autoiframe";

		if( $.browser.msie && parseInt( $.browser.msie.version ) == 8 )
		{
			settings.mask = { color: null, opacity: 0.0 };
		}
		else
		{
			settings.mask = { color: "#000", opacity: 0.8 };
		}

		$( "a[rel=#autoiframe]" ).overlay( settings );
	};

	var setupForms = function()
	{
		$( ".widget_leadgenform form, .widget_contactform form" ).validator(
		{
			position: "bottom left"
		});
	};

	var setupBioExpandos = function()
	{
		$( ".widget_bio" ).widgetExpando(
		{
			expandedClassName: "bio-expanded",
			containerSelector: ".expando-content",
			clickSelector: ".expando-top"
		});
	};

	var setupFAQExpandos = function()
	{
		$( ".faqs .post-container" ).widgetExpando(
		{
			expandedClassName: "faq-expanded",
			containerSelector: ".post-content",
			clickSelector: ".post-title"
		});
	};

})( jQuery );