/* GoingOn.com Global Javascript */
function font_replacement() {
	// Everything
	Cufon.replace('h1, h2, h3, #copyright span, #top_banner_navigation, .top_banner_content-inner p'); // Enter All Elements that are to be rasterized in Gill Sans

	// block_3w h3
	Cufon.replace('.block_3w h3, .block_3w_content', {
		textShadow: '#fff 1px 1px'
	});

	Cufon.replace('#top_banner_header', {
		textShadow: '#000 1px 1px'
	});

}

function fixSelects() {
$('option', 'select').each(function(){
	var name  = $(this).parent().attr('name');
	var value = $(this).attr('value');
	var text  = $(this).text();


	$(this).parent().after('<input type="checkbox" name="'+ name +'" value="'+ value +'">'+ text +'<br/>');
	$(this).remove();

});

$('select').remove(); // get rid of selects
}

function modal() {

	// Preferences Button Functionality
	// $('#top_banner_content a').click(function(event) {
	// 		event.preventDefault();
	// 		var link = $(this).attr('href');
	//
	// 		$('.modal-content').load((link + ' #mid'));
	// 		$('.modal-full').fadeIn(450, 'easeInOutCubic');
	// 	});

	// "Get Going" Contact Link
	$('#get-going-link').click(function(event) {
		event.preventDefault();

		$('.modal-content').load(('contact_us.php #mid'), null, function() {
			fixSelects();
			$('.modal-full').fadeIn(450, 'easeInOutCubic');
		});

	});

		// Modal Close Button
		$('.modal-close').click(function(event) {
			event.preventDefault();

			$('.modal-full').fadeOut(325, 'easeInOutCubic');
		});
}



function top_banner_nav_tabs() {
	$('#top_banner_navigation').tabs({
		fx: {opacity:'toggle', duration:500},
		select: function(event, ui) { // For the Get Going tab that we probably want to navigate to a new page
        var url = $.data(ui.tab, 'load.tabs');
	        if( url ) {
	        	// Changes window location instead of ajax loading into .tabs()
	            // location.href = url;
	            return false;
	        }
	        return true;
	    }

	});

	// Prepend Sprited Hover span
	$('#top_banner_navigation li a').prepend('<span class="hover"></span>');

	// Append Sprited Active span
	$('#top_banner_navigation li a').append('<span class="active"></span>');

	// On Navigation Hover
	$('#top_banner_navigation li a').hover(function(){

		// Find Opacity of Current Element
		var activeOpacity = $(this).css("opacity");

		// If Active <span> is opaque
		if (activeOpacity == 1 ) {
			// Make transparent
			$('.active').animate({
				opacity:0
			}, 200);
		}

		// Hover Over Any defined element make opaque
		$('.hover', this).stop().animate({
			opacity:1
		}, 700, 'easeOutSine');

		// Hover-out of definted element make transparent
		}, function(){
			$('.hover', this).stop().animate({
				opacity:0
			}, 700, 'easeOutExpo');
		});


		// On Click, Make Active span opaque
		$('#top_banner_navigation li a').click(function(){
			$('.active', this).animate({
				opacity:1
			}, 700, 'easeOutSine');
		});

	} // End top_banner_nav_tabs


function offer_animations() {

	// Offer 1
	$('#offer1').hover(function(){
		$('#offer1_image', this).stop().animate({
			top:'-16px'
		}, 500, 'easeInOutCubic');
		$('#offer1_image_shadow', this).stop().animate({
			opacity:.25,
			top:'15px',
			right:'8px'
		}, 500, 'easeInOutCubic');
	}, function(){
		$('#offer1_image', this).stop().animate({
			top:'16px'
		}, 600, 'easeOutBounce');
		$('#offer1_image_shadow', this).stop().animate({
			opacity:1,
			top:'8px',
			right:'0'
		}, 600, 'easeOutBounce');
	});

	// Offer 2
	$('#offer2').hover(function(){
		$('#offer2_image', this).stop().animate({
			top:'-5px',
			right:'-10px'
		}, 500, 'easeInOutCubic');
		$('#offer2_image_shadow', this).stop().animate({
			opacity:.6,
			top:'1px',
			right:'-8px'
		}, 500, 'easeInOutCubic');
	}, function(){
		$('#offer2_image', this).stop().animate({
			top:'3px',
			right:'-7px'
		}, 1200, 'easeInOutCubic');
		$('#offer2_image_shadow', this).stop().animate({
			opacity:1,
			top:'1px',
			right:'-10px'
		}, 1200, 'easeInOutCubic');
	});


	// Offer 3
	$('#offer3').hover(function(){

		$('#offer3_image', this).stop().animate({
			top:'-3px',
			right:'-33px'
		}, 900, 'easeOutElastic');
		$('#offer3_image_shadow', this).stop().animate({
			opacity:.4,
			top:'2px',
			right:'-28px'
		}, 902, 'easeOutElastic');
	}, function(){
		$('#offer3_image', this).stop().animate({
			top:'0',
			right:'-35px'
		}, 1500, 'easeOutElastic');
		$('#offer3_image_shadow', this).stop().animate({
			opacity:1,
			top:'0',
			right:'-38px'
		}, 1502, 'easeOutElastic');
	});



	// $('#offer1').click(function(event) {
	// 		event.preventDefault();
	// 		var link = $(this).attr('href');
	//
	// 		console.log(link);
	//
	// 		// $('.modal-content').load(link, ' #mid');
	// 		// 		$('.modal-full').fadeIn(450, 'easeInOutCubic');
	//
	// 	});



} // End offer_animations()

function customer_slideshow() {
	$('.cycle').cycle({
		delay:  2000,
		speed:  1000
	});
}

function top_banner_animations() {
	$('#top_banner_navigation li a').click(function(e){
		e.preventDefault();

		//console.log('clicked');

		//var curve1 = $('.curve1');
		//var curve2 = $('.curve2');

		// Show, Hide Helpers For Curve and Banner Header

		function showTopBannerHeader() {
			$('#top_banner_header').animate({
				'opacity':'1'
			}, 500);
		}
		function hideTopBannerHeader() {
			$('#top_banner_header').animate({
				'opacity':'0'
			}, 500);
		}

		// Opportunity (link 1) (Exception to ODD LINKS conditions)
		/*

		if ($(this).attr('href') == '#the-opportunity') {
			//console.log('The Opportunity');

			if ($('#top_banner_header').css('opacity') == 0) {
				showTopBannerHeader();
			}

			if ($('.curve1').css('opacity') == 1) {
				hideCurve($('.curve1'));
			}

			if ($('.curve2').css('opacity') == 1) {
				hideCurve($('.curve2'));
			}
		}
		*/

		if ($(this).attr('href') == '#the-opportunity') {

		}

		// EVEN LINKS - Building Community (link 2), Deployment (link 4)
		if ($(this).attr('href') == '#building-community'
				|| $(this).attr('href') == '#deployment'
				|| $(this).attr('href') == '#the-opportunity' ) {
			//console.log('Building Community OR Deployment');

			if ($('#top_banner_header').css('opacity') == 1) {
				hideTopBannerHeader();
			}


		}

		// ODD LINKS (with exception to first link) - Community Platform (link 3), Get Going (link 5)
		else if ($(this).attr('href') == '#community-platform'
				) {
			//console.log('Community Platform OR Get Going');

			if ($('#top_banner_header').css('opacity') == 1) {
				hideTopBannerHeader();
			}


		}
	});
} // End top_banner_animations


// When DOM is Ready to be manipulated
$(document).ready(function() {

	$.ajaxSetup ({
		// Disable caching of AJAX responses */
		cache: false
	});


	// Prevent Flicker

	$('#starter, #the-opportunity, #building-community, #community-platform, #deployment').css({
		'opacity':'1'
	});


	// Fading :hover/:active states on tabs
	font_replacement();

	// All Logic for the Top Banner Display Information
	top_banner_animations();

	// Fading :hover/:active states on tabs
	top_banner_nav_tabs();

	// BiggerLink takes inner <a> and turns parent elements into handler for itself
	$('#offer1, #offer2, #offer3, .news_item').biggerlink();

	// Customer Logo Slideshow
	customer_slideshow();

	// Offer Hover Animations
	offer_animations();

	// Modal Window
	modal();

	//Input Focus
	$("input, textarea").focus(function () {
    	$(this).css({
        	'background-color':'#FFF6DF'
		});
    });
    $("input, textarea").blur(function () {
        $(this).css({
        	'background-color':'#FFFFFF'
        });
    });

	// Fix  Select Boxes
	fixSelects();

$('#WebToLeadForm').validate({

});


});