/**
 * Function resizes the css widths of key elements required onload
 * and when the window is resized.
 */
var email_user_id = false; 
var email_user_email = false; 
var lb_reg_param = "";

 
function windowResize() {
	var windowWidth = $(window).width();
	$('body').css('width', windowWidth);
	var sectionCount = $('#content div.innerContent > section').length;
	$('div.innerContent').css('width', windowWidth * sectionCount);
	$('section.mySection, section.mySection .story').css('width', windowWidth);

    var current = $('#current-viewport').data('current');
    var type    = navigator.userAgent.toLowerCase().indexOf('firefox') > -1 ? 'html' : 'body';

	if(typeof current !== 'undefined' || current != null)
	{
		$(type).scrollLeft(($(current).offset().left));
	    if(current != '#homepage')
		{
			$('#what-is-hand').css('background-position', ((windowWidth-960)/2+492)+'px'  );
			$('.yourCustomers').css('background-position', ((windowWidth-960)/2+590)+'px'  );
			$('#green-hand').css('background-position', ((windowWidth-960)/2+320)+'px'  );
			$('#mobilizing-mobile .mobilizingMobile').css('background-position',   Math.round((($window_width - 960) / 2 + 233)) + 'px');
			$('#agency-hand').css('background-position', ((windowWidth-960)/2+330)+'px'  );
	    }
	}
}

//Disable tabbing to prevent skipping steps
	$(document).keydown(function(objEvent) {
        if (objEvent.keyCode == 9) {  
            if (document.activeElement.tagName != 'INPUT')
                objEvent.preventDefault();
        }
	});

/**
 *    Someones function ( update this doc plz )
 */
function random_from_to(from, to)
{
    return Math.floor(Math.random() * (to - from + to) + from);
}

function ad_double_click(cat)
{
	var axel = Math.random() + "";
	var a    = axel * 10000000000000;
	var url  = "http://ad.doubleclick.net/activity;src=3402384;type=globa661;cat="+cat+";ord=1;num='" + a
	$('#add_blocker').html('<img src="'+ url +'" width="1" height="1" alt=""/>');
}

/**
 *   +1 Script
 */
$(window).load(function()
{
	ad_double_click("gomoh173");
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	
	var id_patt = new RegExp ( "registrant_id=([0-9]+)" );
	var page_id_matches = window.location.href.match( id_patt );
	if ( page_id_matches != null ) { 
		email_user_id = page_id_matches[1] ? page_id_matches[1] : false;
	}
	id_patt = new RegExp ( "email=([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)" );
	page_id_matches = window.location.href.match( id_patt );
	if ( page_id_matches != null ) { 
		email_user_email = page_id_matches[1] ? page_id_matches[1] : false;
	}
	id_patt = new RegExp("lb_unreg");
	page_id_matches = window.location.href.match(id_patt);
	if (page_id_matches != null)
	{
		lb_reg_param = "lb&";
	}
});


/**
 *	Returns the servers base URL.
 */
function getBaseURL() {
	var url = window.location.href;
	var baseURL = url.substring(0, url.indexOf('/', 14));
	if (baseURL.indexOf('http://localhost') != -1) {
		var url = window.location.href;
		var pathname = location.pathname;
		var index1 = url.indexOf(pathname);
		var index2 = url.indexOf('/', index1 + 1);
		var baseLocalUrl = url.substr(0, index2);
		return baseLocalUrl + "/";
	} else {
		return baseURL + "/";
	}
}

// animation vars to store the functions
var homepage_landing, blue_landing, red_landing, green_landing, black_landing;
var $animation_selector = ($.browser.webkit === true) ? $('body') : $('html');

/* AddThis UI Configuration. */
var addthis_config = {
	ui_click: true,
	ui_open_windows: true,
	services_compact: 'google_plusone, facebook, twitter, digg, stumbleupon, reddit',
     services_exclude: 'print'
};

/* AddThis UI Configuration. */
var addthis_share = {
   description: 'Help support Mobilizing Mobile and spread the word! #GoMobile www.howtogomo.com/en/#spread-the-word',
   
   templates: {
          twitter: 'Help support Mobilizing Mobile and spread the word! #GoMobile www.howtogomo.com/en/#spread-the-word'
    }
};

$(window).load(function()
{
	var animateHand = function(selector, pos, callback)
	{
        var url = window.location.href;
		this.tag        = selector;
		this.pos        = pos;
		this.callback   = callback;
		this.url        = $(this.tag).css('background-image');
		this.url        = url.substring(4,(url.length-1));
		this.defaultPos = $(this.tag).css('background-position');
		this.reset = function() { $(this.tag).css('background-position', this.defaultPos); }
    }

    animateHand.prototype.run = function()
	{
        var instance = this;
        $(instance.tag).stop().animate({'background-position' : instance.pos}, 1000);
        if(typeof instance.callback == 'function') { return instance.callback() }
    }

    homepage_landing = new animateHand('.blue-section .readyGoMo','+=218', function()
	{
        $("#homepage").stop().animate({ opacity: 1 },1500, function() { $('#circle').animate({opacity:1},300); });
    });

    var ww        = $(window).width(), basis = (ww-450);
    var placement = basis - ((ww-960)/2+402);
    $('#what-is-hand').css('background-position',basis);

    blue_landing = new animateHand('.blue-section #what-is-hand','-='+placement, function()
	{
		$('#circle2').delay(1500).animate({opacity:1},300);
    });

	/**
	 *     Handling new ad_double_clicks on nav
	 **/
	$("ul#nav li a").bind("click", function ()
	{
		cat = $(this).data("cat");
		if (cat != undefined &&  cat != "")
		{
			ad_double_click($(this).data("cat"));
		}
	});

    /**
        RED
    **/
    var placement = basis - ((ww-960)/2+350);
    $('.yourCustomers').css('background-position',basis);

    red_landing = new animateHand('.yourCustomers','-='+placement, function()
	{
		$('#circle6').delay(1500).animate({opacity:1},300);
    });


    var placement = basis - ((ww-960)/2+470);
    $('#green-hand').css('background-position', (ww-600));

    green_landing = new animateHand('#green-hand','-='+placement, function() { $('#circle7').delay(1500).animate({opacity:1},300); });


  	$("#circle7").hover( function() {
		$("#circle7 p").text("-");
		$('#circle7-container').css('display','block');
	}, function() {
		$("#circle7 p").text("+");
		$('#circle7-container').hide();
	});

	/**
        YELLOW
    **/
    var placement = (ww - 700) - (Math.round((ww - 960) / 2) + 233);
	$('#mobilizing-mobile .mobilizingMobile').css('background-position', (ww-700));
    yellow_landing = new animateHand('#mobilizing-mobile .mobilizingMobile','-='+placement);

    /**
        BLACK
    **/
    var placement = basis - ((ww-960)/2+480);
    $('#agency-hand').css('background-position', (ww-600));
    black_landing = new animateHand('#agency-hand','-='+placement, function() { $('#circle8').delay(1500).animate({opacity:1},300); });

    $('li.pdf').click(function() { window.open( $(this).find('a').attr('href'), '_blank'); });

	$('#blueNavA, #blueNavB, #blueNavC, #redNavA, #greenNavA, #greenNavB, #greenNavC, #blackNavB, #yellowNavB, #yellowNavC, #yellowNavD, #yellowNavE, #yellowNavF').click(function(){
		$('#mainLogo').fadeOut();
		$('#mainLogoTurned').fadeIn();
		$('div.modal', 'div#register').hide();
		$('div.registrationLightbox').remove();
	});

	$('#GOMO, #blueNav, #redNav, #greenNav, #ylellowNav, #blackNav').click(function(){
		$('#mainLogo').fadeIn();
		$('#mainLogoTurned').fadeOut('slow');
	});

/**
 *	Homepage - Put Your Site To The Test - Animation.
 */
if(typeof Raphael !== 'undefined')
{
	var blueMobile = new Raphael(document.getElementById('blueMobile'), 58, 91);
	var mobile = blueMobile.rect(0, 0, 58, 91, 14);

	mobile.attr({
		fill: '#424243',
		stroke: 'none'
	});

	var shadingTop = blueMobile.rect(8, 4, 43, 3, 6);
	shadingTop.attr({
		fill: '#767676',
		stroke: 'none'
	});

	var darkBlue2 = blueMobile.rect(4, 17, 50, 57);
	darkBlue2.attr({
		fill: '#339db5',
		stroke: 'none'
	});

	var lightBlue2 = blueMobile.rect(8, 21, 42, 47);
	lightBlue2.attr({
		fill: '#a0d9f3',
		stroke: 'none'
	});

	var tickbox1 = blueMobile.rect(11, 25, 12, 12);
	tickbox1.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var tickbox1Center = blueMobile.rect(13, 27, 8, 8);
	tickbox1Center.attr({
		fill: '#a0d9f3',
		stroke: 'none'
	});

	var tickbox2 = blueMobile.rect(11, 39, 12, 12);
	tickbox2.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var tickbox2Center = blueMobile.rect(13, 41, 8, 8);
	tickbox2Center.attr({
		fill: '#a0d9f3',
		stroke: 'none'
	});

	var tickbox3 = blueMobile.rect(11, 53, 12, 12);
	tickbox3.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var tickbox3Center = blueMobile.rect(13, 55, 8, 8);
	tickbox3Center.attr({
		fill: '#a0d9f3',
		stroke: 'none'
	});

	var line1 = blueMobile.rect(25, 33, 23, 3);
	line1.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var line2 = blueMobile.rect(25, 46, 23, 3);
	line2.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var line3 = blueMobile.rect(25, 60, 23, 3);
	line3.attr({
		fill: '#ffffff',
		stroke: 'none'
	});

	var button1 = blueMobile.circle(11, 82.5, 2.5);
	button1.attr({
		fill: '#767676',
		stroke: 'none'
	});

	var button2 = blueMobile.circle(23, 82.5, 2.5);
	button2.attr({
		fill: '#767676',
		stroke: 'none'
	});

	var button3 = blueMobile.circle(35, 82.5, 2.5);
	button3.attr({
		fill: '#767676',
		stroke: 'none'
	});

	var button4 = blueMobile.circle(47, 82.5, 2.5);
	button4.attr({
		fill: '#767676',
		stroke: 'none'
	});

	var tick = blueMobile.path('M 15 30 l 16 0 l 0 -3 l -13 0 l 0 -3 l -3 0 z');
	tick.attr({
		fill: '#7cb037',
		stroke: 'none',
		rotation: -40,
		opacity: 0,
		scale: 1.5
	});

	var tick2 = blueMobile.path('M 15 45 l 16 0 l 0 -3 l -13 0 l 0 -3 l -3 0 z');
	tick2.attr({
		fill: '#7cb037',
		stroke: 'none',
		rotation: -40,
		opacity: 0,
		scale: 1.5
	});

	var tick3 = blueMobile.path('M 15 60 l 16 0 l 0 -3 l -13 0 l 0 -3 l -3 0 z');
	tick3.attr({
		fill: '#7cb037',
		stroke: 'none',
		rotation: -40,
		opacity: 0,
		scale: 1.5
	});

	$('#rolloverImageLink1').hover(
		function() {
			tick.animate({
				'10%': { opacity: 0 },
				'100%': { scale: 1, opacity: 1 }
			}, 500);
			tick2.animate({
				'30%': { opacity: 0 },
				'60%': { opacity: 1 },
				'100%': { scale: 1 }
			}, 1000);
			tick3.animate({
				'60%': { opacity: 0 },
				'70%': { opacity: 1 },
				'100%': { scale: 1 }
			}, 1500);
		},
		function() {
			tick3.animate({
				'40%': { scale: 1, opacity: 1 },
				'100%': { scale: 1.5, opacity: 0 }
			}, 500);
			tick2.animate({
				'30%': { scale: 1, opacity: 1 },
				'60%': { scale: 1.5 },
				'100%': { opacity: 0 }
			}, 1000);
			tick.animate({
				'60%': { scale: 1, opacity: 1 },
				'80%': { scale: 1.5 },
				'100%': { opacity: 0 }
			}, 1500);
		}
	);


//*********************************
//** Rollover link - msd Hereo ****
//*********************************

var msdHero = new Raphael(document.getElementById('msdHero'), 78, 99);

var msdCape = msdHero.path("M 0,35.5 a0.3,0.3 0 0,0 76,0");
msdCape.attr({
	fill: "#ed1e29",
	stroke: "none",
	rotation: 180
});

var msdCape2 = msdHero.circle(38, 0, 29);
msdCape2.attr({
	fill: '#ed1e29',
	stroke: "none",
	'scale': 1.3,
	'opacity': 0
});

var shoulders1 = msdHero.path("M 8.5,35.5 a0.3,0.3 0 0,0 58.5,0");
shoulders1.attr({
	fill: "#2970b8",
	stroke: "none",
	rotation: 180
});

var greyBody = msdHero.ellipse(38, 64, 18, 19);
greyBody.attr({
	fill: 'none',
	stroke: "none",
	'scale': 1.1,
	'rotation': 90
});

var msdArms = msdHero.rect(8, 65, 59, 7, 2);
msdArms.attr({
	fill:'#cea589',
	stroke: 'none'
});

var msdHeadBody = msdHero.ellipse(38, 61, 17, 19);
msdHeadBody.attr({
	fill: '#0fb5e1',
	stroke: "none",
	'scale': 1.1,
	'rotation': 90
});

var msdHead = msdHero.circle(38, 24, 18);
msdHead.attr({
	fill: '#5e2b0f',
	stroke: "none",
	'scale': 1.3
});

var msdMouth = msdHero.ellipse(38, 37, 2.5, 3);
msdMouth.attr({
	fill: '#cea589',
	stroke: "none",
	'scale': 1.3
});

var msdFace2 = msdHero.path("M 30 35 l -0.5 -3 l 0.5 -2 l 1.5 -5 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1 2 l 1 -2 l 1.5 5 l 0.5 2 l -0.5  3 l 23 0   z");
msdFace2.attr({
	fill: '#cea589',
	stroke: "none",
	'scale': 1.3
});

var msdMouthCover = msdHero.rect(33, 36.68, 10, 1.5);
msdMouthCover.attr({
	fill: '#5e2b0f',
	stroke: "none",
	'scale': 1.3
});

var msdLeftEye = msdHero.circle(28.5, 31, 1);
msdLeftEye.attr({
	fill: '#000',
	stroke: "none",
	'scale': 1.3
});

var msdRightEye = msdHero.circle(47.5, 31, 1);
msdRightEye.attr({
	fill: '#000',
	stroke: "none",
	'scale': 1.3
});

var msdNose = msdHero.circle(38, 33, 1.5);
msdNose.attr({
	fill: '#a5774f',
	stroke: "none",
	'scale': 1.3
});

var msdBodyLegs2 = msdHero.path("M 46 131 S 38 -10 67 130");
msdBodyLegs2.attr({
	fill: '#414243',
	stroke: "none"
});

var msdBodyLegs1 = msdHero.path("M 10 131 S 30 -10 30 130");
msdBodyLegs1.attr({
	fill: '#414243',
	stroke: "none"
});

var msdBodyLegs = msdHero.path("M 20.5 70 l 35 0 l -2.5 4 l -3 3 l -3 1 l -3 3 l -5 0 l -4 0 l -8 0 l -4 -6 z");
msdBodyLegs.attr({
	fill: '#414243',
	stroke: "none",
	'scale': 1.1
});


// mobile image

var msdMobile = msdHero.rect(9, 12, 58, 91, 14);
msdMobile.attr({
	fill: '#3a62a1',
	stroke: "none",
	rotation: 0,
	'scale': 0.19
});

var msdDarkRed = msdHero.rect(13, 29, 50, 57);
msdDarkRed.attr({
	fill: '#5490cb',
	stroke: "none",
	rotation: 0,
	'scale': 0.19
});

var msdBelt = msdHero.rect(19, 68, 38, 3);
msdBelt.attr({
	fill: '#296fb7',
	stroke: "none",
	rotation: 0
});

var msdText = msdHero.text(38, 55, "GO");
msdText.attr({
	fill: "#ffffff",
	stroke: "none",
	'font-size': 5,
	'font': 'helvetica'
});

var msdText2 = msdHero.text(38, 60, "MO");
msdText2.attr({
	fill: "#ffffff",
	stroke: "none",
	'font-size': 5,
	'font': 'helvetica'
});

$('#rolloverImageLink2').hover(function() {
	// open mouth
	msdMouth.animate({ cy:40, radius: 3, }, 100);
	// hide bottom cape
	msdCape.animate({ 'opacity': 0, }, 500);
	// show top cape
	msdCape2.animate({ 'opacity': 1, }, 500);
}, function(){
	// close mouth
	msdMouth.animate({ cy:38, radius: 2.5, }, 100);
	// show bottom cape
	msdCape.animate({ 'opacity': 1, }, 500);
	// hide top cape
	msdCape2.animate({ 'opacity': 0, }, 200);
});

}

	// rollover color faded animation on homepage

	$('#rolloverImageLink1').hover(function(){
		$(this).stop().animate({
			'backgroundColor' : '#ce182b',
			'color' : '#ffffff',
			'opacity' : 1
		},500);
	}, function() {
		$(this).stop().animate({
			'backgroundColor' : 'rgba(255, 255, 255, 0.6)',
			'color' : '#333'
		}, 500);
	});

	$('.blueBullet').click(function(){
		$('nav ul li a').removeClass("fillBlue fillGreen fillBlack redFocus");
		$('#blueNav').toggleClass('fillBlue');
	});

	$('#rolloverImageLink1, .redBullet').click(function(){
		$('nav ul li a').removeClass("fillBlue fillGreen fillBlack redFocus");
		$('#redNav').toggleClass('fillRed');
	});

	$('#rolloverImageLink2, .greenBullet').click(function(){
		$('nav ul li a').removeClass("fillRed fillBlue fillBlack greenFocus");
		$('#greenNav').toggleClass('fillGreen');
	});
	
	$('#rolloverImageLink2').hover(function(){
		$(this).stop().animate({
			'backgroundColor' : "#009925",
			'color' : '#ffffff',
			'opacity' : 1
		},500);
	}, function() {
		$(this).stop().animate({
			'backgroundColor' : "rgba(255, 255, 255, 0.6)",
			'color' : '#333'
		}, 500);
	});

// Main Navigation

	var mainNavLink = $('nav ul li > a');	
	var lowerNavLink = $('span.sub li a', '#nav');
	
	mainNavLink.click(function(){
		mainNavLink.removeClass('active');
		mainNavLink.next().removeClass('showNav');
		$(this).addClass('active').next('span').addClass('showNav');
		$('span.sub a', '#nav').removeClass('fill');
	});
	
	$('span.sub a', '#nav').click(function() {
		$('span.sub a', '#nav').removeClass('fill');
		$(this).addClass('fill');
				
		if( !$(this).parent().hasClass('showNav') ) {
			mainNavLink.removeClass('active');
			$(this).parent().addClass('showNav');
		}
		$(this).parent().prev().addClass('active');
	});

	// Hides sub nav on hover
	/*mainNavLink.mouseover(function() {
		$(this).addClass('active');
	});*/
	
	$('#blueNav, .blueSubNav').hover(function() { 
		$('.redSubNav, .greenSubNav, .yellowSubNav, .blackSubNav').removeClass('showNav');
 	});

	$('#redNav, .redSubNav').hover(function() { 
		$('.blueSubNav, .greenSubNav, .yellowSubNav, .blackSubNav').removeClass('showNav');
 	});

	$('#greenNav, .greenSubNav').hover(function() { 
		$('.blueSubNav, .redSubNav, .yellowSubNav, .blackSubNav').removeClass('showNav');
 	});
	
	$('#yellowNav, .yellowSubNav').hover(function() { 
		$('.blueSubNav, .redSubNav, .greenSubNav, .blackSubNav').removeClass('showNav');
 	});

	$('#blackNav, .blackSubNav').hover(function() { 
		$('.blueSubNav, .redSubNav, .yellowSubNav, .greenSubNav').removeClass('showNav');
 	});

	

    // change navigation color on scroll
	$(window).scroll(function() {

		/* Floating Menu for Vendors */

		var name = "#vendorCheck";
		var menuYloc = null;
		if(typeof $(name) != 'undefined')
		{
			menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")));

			var top = $(document).scrollTop() - 950 - menuYloc;
			offset = menuYloc+top+"px";
			$(name).animate({top:offset},{duration:500,queue:false});
		}

	}); // end scroll

    
	// hide and show circle content
  	$("#circleContainer").hide();
  	$("#circleContainer2").hide();
  	$("#circleContainer3").hide();
  	$("#mobilePractices-S1C2-container").hide();
  	$("#circleContaine5").hide();
  	$("#circleContainer6").hide();
  	$("#circleContainer7").hide();
  	$("#circleContainer8").hide();

  	$(".circles").hover( function() {
  		$(this, 'div.circles').next('.circleContainers').fadeIn("100").css('display','block');
	}, function() {
		$(this, 'div.circles').next('.circleContainers').hide();
	});
	
	
		/* Helpful Links Homepage */
		$('#blue .helpfulLinks a').click(function(){
			$('#blueNavA').addClass('blueFocus');
			$('.blueSubNav').addClass('showNav');
		});

		$('#red .helpfulLinks a').click(function(){
			$('#redNavA').addClass('redFocus');
			$('.redSubNav').addClass('showNav');
		});

		$('#green .helpfulLinks a').click(function(){
			$('#greenNavB').addClass('greenFocus');
			$('.greenSubNav').addClass('showNav');
		});

		$('#black .helpfulLinks a').click(function(){
			$('#blackNavB').addClass('blackFocus');
			$('.blackSubNav').addClass('showNav');
		});
		
	/* Main Navigation */
		
	/* Build Your Site */
	/*$('#greenNav').click(function(){
		$(this).addClass('greenFocus');
		$('.greenSubNav').addClass('showNav');
		$('#blueNavA').removeClass('blueFocus');
		$('#blueNavB').removeClass('blueFocus');
		$('#blueNavC').removeClass('blueFocus');
		$('#blueNav').removeClass('blueFocus');
		$('#redNavA').removeClass('redFocus');
		$('#redNav').removeClass('redFocus');
		$('#blackNavB').removeClass('blackFocus');
		$('#blackNav').removeClass('blackFocus');
		$('#yellowNav').removeClass('yellowFocus');
		$('#yellowNavB').removeClass('yellowFocus');
		$('#yellowNavC').removeClass('yellowFocus');
		$('#yellowNavD').removeClass('yellowFocus');
		$('#yellowNavE').removeClass('yellowFocus');
		$('#yellowNavF').removeClass('yellowFocus');
	});

	$('#greenNavB').click(function(){
		$('#greenNav').addClass('greenFocus');
		$('.greenSubNav').addClass('showNav');
		$('.redSubNav, .blueSubNav, .blackSubNav').removeClass('showNav');
		$('#greenNav').addClass('fillGreen');
	});

	$('#greenNavC').click(function(){
		$('#greenNav').addClass('greenFocus');
		$('.greenSubNav').addClass('showNav');
		$('.redSubNav, .blueSubNav, .blackSubNav').removeClass('showNav');
		$('#greenNav').addClass('fillGreen');
	});*/

	/* Test Your Site */
	/*if (document.URL.indexOf("#test-your-site") >= 0 ) {
		$('#redNav').addClass('fillRed');
		$('.redSubNav').addClass('showNav');
	}
	if (document.URL.indexOf("#gomo-meter") >= 0) {
		$('#redNav').addClass('fillRed');
		$('.redSubNav').addClass('showNav');
		$('#redNavA').addClass('redFocus');
	}

	$('#redNav').click(function(){
		$(this).addClass('redFocus');
		$('.redSubNav').addClass('showNav');
		$('#greenNavA').removeClass('greenFocus');
		$('#greenNavB').removeClass('greenFocus');
		$('#greenNavC').removeClass('greenFocus');
		$('#greenNav').removeClass('greenFocus');
		$('#blueNav').removeClass('blueFocus');
		$('#blueNavA').removeClass('blueFocus');
		$('#blueNavB').removeClass('blueFocus');
		$('#blueNavC').removeClass('blueFocus');
		$('#blackNavB').removeClass('blackFocus');
		$('#blackNav').removeClass('blackFocus');
		$('#yellowNav').removeClass('yellowFocus');
		$('#yellowNavB').removeClass('yellowFocus');
		$('#yellowNavC').removeClass('yellowFocus');
		$('#yellowNavD').removeClass('yellowFocus');
		$('#yellowNavE').removeClass('yellowFocus');
		$('#yellowNavF').removeClass('yellowFocus');
	});

	$('#redNavA').click(function(){
		$('#redNav').addClass('redFocus');
		$('.redSubNav').addClass('showNav');
	});*/
	
	/* Mobilizing Mobile */
	/*$('#yellowNav').click(function(){
		$(this).addClass('yellowFocus');
		$('.redSubNav').addClass('showNav');
		$('#greenNavA').removeClass('greenFocus');
		$('#greenNavB').removeClass('greenFocus');
		$('#greenNavC').removeClass('greenFocus');
		$('#greenNav').removeClass('greenFocus');
		$('#redNavA').removeClass('redFocus');;
		$('#redNav').removeClass('redFocus');
		$('#blueNav').removeClass('blueFocus');
		$('#blueNavA').removeClass('blueFocus');
		$('#blueNavB').removeClass('blueFocus');
		$('#blueNavC').removeClass('blueFocus');
		$('#blackNavB').removeClass('blackFocus');
		$('#blackNav').removeClass('blackFocus');
	});*/

	/* Why Go Mo */
	/*if (document.URL.indexOf("#why-go-mo") >= 0 ) {
		$('#blueNav').addClass('fillBlue');
		$('.blueSubNav').addClass('showNav');
	}
	
	if (document.URL.indexOf("#reasons-mobile-matters") >= 0) {
		$('#blueNav').addClass('fillBlue');
		$('.blueSubNav').addClass('showNav');
		$('#blueNavA').addClass('blueFocus');
	}
	
	if (document.URL.indexOf("#mobile-best-practices") >= 0) {
		$('#blueNav').addClass('fillBlue');
		$('.blueSubNav').addClass('showNav');
		$('#blueNavB').addClass('blueFocus');
	}
	
	if (document.URL.indexOf("#case-studies") >= 0) {
		$('#blueNav').addClass('fillBlue');
		$('.blueSubNav').addClass('showNav');
		$('#blueNavC').addClass('blueFocus');
	}

	$('#blueNav').click(function(){
		$('.blueSubNav').addClass('showNav');
		$('#blueNav').addClass('blueFocus');
		$('#greenNavA').removeClass('greenFocus');
		$('#greenNavB').removeClass('greenFocus');
		$('#greenNavC').removeClass('greenFocus');
		$('#greenNav').removeClass('greenFocus');
		$('#redNavA').removeClass('redFocus');
		$('#redNav').removeClass('redFocus');
		$('#yellowNav').removeClass('yellowFocus');
		$('#yellowNavB').removeClass('yellowFocus');
		$('#yellowNavC').removeClass('yellowFocus');
		$('#yellowNavD').removeClass('yellowFocus');
		$('#yellowNavE').removeClass('yellowFocus');
		$('#yellowNavF').removeClass('yellowFocus');		
		$('#blackNavB').removeClass('blackFocus');;
		$('#blackNav').removeClass('blackFocus');
	});
	
	$('#blueNavA').click(function(){
		$('.blueSubNav').addClass('showNav');
		$('#blueNav').addClass('blueFocus');
		$('.blueSubNav').addClass('showNav');
		$('.redSubNav, .greenSubNav, .blackSubNav').removeClass('showNav');
		$("#blueNav").addClass('fillBlue');
	});
	
	$('#blueNavB').click(function(){
		$('.blueSubNav').addClass('showNav');
		$('#blueNav').addClass('blueFocus');
		$('.blueSubNav').addClass('showNav');
		$('.redSubNav, .greenSubNav, .blackSubNav').removeClass('showNav');
		$("#blueNav").addClass('fillBlue');
	});
	
	$('#blueNavC').click(function(){
		$('.blueSubNav').addClass('showNav');
		$('#blueNav').addClass('blueFocus');
		$('.blueSubNav').addClass('showNav');
		$('.redSubNav, .greenSubNav, .blackSubNav').removeClass('showNav');
		$("#blueNav").addClass('fillBlue');
	});*/

	/* For Agencies */
	/*$('#blackNav').click(function(){
		$('#blueNavA').removeClass('blueFocus');
		$('#blueNavB').removeClass('blueFocus');
		$('#blueNavC').removeClass('blueFocus');
		$('#blueNav').removeClass('blueFocus');
		$('#greenNavA').removeClass('greenFocus');
		$('#greenNavB').removeClass('greenFocus');
		$('#greenNavC').removeClass('greenFocus');
		$('#greenNav').removeClass('greenFocus');
		$('#redNavA').removeClass('redFocus');
		$('#redNav').removeClass('redFocus');
		$('#yellowNav').removeClass('yellowFocus');
		$('#yellowNavB').removeClass('yellowFocus');
		$('#yellowNavC').removeClass('yellowFocus');
		$('#yellowNavD').removeClass('yellowFocus');
		$('#yellowNavE').removeClass('yellowFocus');
		$('#yellowNavF').removeClass('yellowFocus');
	});

	$('#blackNavB').click(function(){
		$('#blackNav').addClass('blackFocus');
		$('.blackSubNav').addClass('showNav');
		$(this).addClass('blackFocus');
	});*/

	//End of deeplink active states


	/* jquery for social links to animate */

	$('#socialSharing .google').hover(function(){
    	$(this).animate({
    		width: "75px"
    		}, 200);
	}, function() {
    	$(this).animate({
    		width: "5px"
    		}, 200);
	});

	$('#socialSharing .twitter').hover(function(){
    	$(this).animate({
    		width: "85px"
    		}, 200);
	}, function() {
    	$(this).animate({
    		width: "5px"
    		}, 200);
	});

	$('#socialSharing .facebook').hover(function(){
    	$(this).animate({
    		width: "95px"
    		}, 200);
	}, function() {
    	$(this).animate({
    		width: "5px"
    		}, 200);
	});
	$('#socialSharing .chat').hover(function(){
    	$(this).animate({
    		width: "85px"
    		}, 200);
	}, function() {
    	$(this).animate({
    		width: "5px"
    		}, 200);
	});
	$('#socialSharing .pdf').hover(function(){
    	$(this).animate({
    		width: "105px"
    		}, 200);
	}, function() {
    	$(this).animate({
    		width: "5px"
    		}, 200);
	});

	//	How mobile friendly is your site, section 2

    function isUrl(s) 
	{
        var regexp = /((ftp|http|https):\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return regexp.test(s);
    }

    $("#webUrl").keyup(function() {
    		    $('#websiteURL').removeClass('greyBullet');
    		    var v = $(this).val();
				
    		    if( isUrl(v) ) {
    		    	    $('#websiteURL').addClass('testYourSiteConfirm');
    		    } else {
    		    	    $('#websiteURL').removeClass('testYourSiteConfirm');
    		    }
    });

	// Black Section drop down select
	$("#employeeDropDown").click(function()
	{
   		var hidden = $(this).parents("li").children("ul").is(":hidden");
	   	if(hidden)
		{
	   		$(this).parents("li").children("ul").show();
		}
		else
		{
			$(this).parents("li").children("ul").hide();
		}
	});

	var employeeNoSelect = $('#employeeDropDown').text();

	$('#emp_drop li').click(function()
	{
		$('select#number_of_employees').val($(this).data("employees"));
		employeeNoSelect = $(this).data("employees");
		$('#employeeDropDown').text(employeeNoSelect);
		$('#employeeDropDown').next("ul").hide();
	});

    /* Animate the banner links in index banner */
	$('a', '.helpfulLinks').hover(function(){
		$(this).stop().animate({
			left : '+=15'
		  }, 100);
	}, function(){
		$(this).stop().animate({
			left : '0'
		}, 300);
	});

	/**
	 * When .infoBox is hovered the hidden span.hoverInfoBox is faded in
	 * and positioned over the box
	  */

	  // needs to be animated
	var $myHover = $('li.infoBox').find('span.hoverInfoBoxRed, span.hoverInfoBoxGreen');
	$myHover.hide();

	$('li.infoBox').hover(function() {
		$(this).find($myHover).stop(true, true).fadeIn('normal');
	}, function(){
		$(this).find($myHover).stop(true, true).fadeOut('normal');
	});

    // Before/After images

    /* Hide all before images as the after image is the default to be shown. */
	$('img.beforeImage', '#case-studies').hide();

	/**
	 *	Takes the before and after links, and shows the appropriate image,
	 *	while managing active classes on themselves.
	 */

	$('img.beforeImage').hide();

	$('ul.beforeAfter a', '#case-studies').bind('click', function(e) {
		var thisLink = $(this);
		var otherLink = thisLink.parent().siblings('li').children('a');
		var leftPanel = thisLink.parents('div.slider3left');

		thisLink.addClass('active');
		otherLink.removeClass('active');

		if (thisLink.hasClass('before')) {
			leftPanel.children('img.beforeImage').delay('500').fadeIn('200');
			leftPanel.children('img.afterImage').fadeOut('100');
		} else {
			leftPanel.children('img.afterImage').delay('500').fadeIn('200');
			leftPanel.children('img.beforeImage').fadeOut('100');
		}

		$.stop_event(e)
	});


	$('input').customInput();

    $('li.twitter').click(function(e){

        $.stop_event(e)

        var hash = window.location.hash;
        var page = hash.substr(1).replace(/-/g,' ');
        var text = 'Introducing GoMo from Google. Test your business\'s website and get custom tips on how to be more mobile-friendly. ';
        var url = 'http://twitter.com/intent/tweet?text='+text+'&url=http://goo.gl/oxe6S';
        window.open(url,'twitter-window','height=300,width=450');

    });

    $('li.facebook').bind('click', function(e) {
        var hash = window.location.hash;
        var url = 'http://www.howtogomo.com';
		var baseURL = getBaseURL();
		var imgPath = baseURL + 'media/images/gomo-fb.png';
		var summary = 'There\'s a mobile movement underway and GoMo is here to help businesses get ready. Come test your company\'s site to see if it\'s mobile-friendly and learn about mobile usage and best practices. You can even find a developer to help build your new mobile site.';
		var url = 'http://www.facebook.com/sharer.php?s=100&p[title]=GoMo: An Initiative From Google&p[url]='+url+'&p[images][0]='+imgPath+'&p[summary]='+summary;
		window.open(url,'facebook-window','height=300,width=550');

		$.stop_event(e)
    });

    var vend = vendors.list,
    imgpath = vendors.imgpath;

    var controller = $('#vendor-result-con #cn-slide-control .controller');
    $('#vendor-result-list .companyLogo').live({
        mouseover:function(){
            $(this).css('background-position','0 -124px');
        },
        mouseleave:function(){
            $(this).css('background-position','0 0');
        }
    });

    $('.companyProfile .readMore a.rm').live('click', function(e){

        $.stop_event(e)
        var t = $(this).parent('.readMore');
        var i = $(this).data('id');
        t.html( '<strong>Description: </strong>'+vend[i].description.full+'<a href="javascript:void(0)" class="rl" data-id="'+i+'"> Read less</a></li>');
        t.animate({height:t.data('height')+'px'},400,function(){
            accessScrolling('n');
        });

    });

    $('.companyProfile .readMore a.rl').live('click', function(e){

        $.stop_event(e)
        var i =$(this).data('id');
        var t = $(this).parent('.readMore');
        t.animate({height:t.data('min-height')+'px'},400, function(){
            t.html( '<strong>Description: </strong>' +vend[i].description.short+'<a href="javascript:void(0)" class="rm" data-id="'+i+'"> Read more</a></li>');
            accessScrolling('n');
        });
    });

    var len = (vend.length-1),
    $results = $('#vendor-result-list'),
    _h = $results.height(),
    $error = $('#vendor-result-list .no-results'),
    $none = $('#vendor-result-list .no-results-opt'),
    mtop = 0,
    size = 0,
    cpos=0,
    active=0;;
    $error.hide();
    $none.hide();

    var accessScrolling = function(e) {
        var e = e || 'y';
        var set='n';
        active=0;

        $results.find('.companyProfile').each(function(){
            if($(this).data('active')=='y'){
                active +=1;
            }
        });

        if(active == 0){
            $none.show();
        } else {
            $none.hide();
        }
    }


    $('.companyProfile').live('click', function() {
       _gaq.push(['_trackEvent', 'Vendors', $(this).prev('h3').text()]);
       console.log( 'Vendors clicked' );
    });

    for(i=0;i<=len;i++) {

        var imgtemp = '<span class="companyLogo"></span>';

         if(vend[i].img !='#'){
            imgtemp = '<a href="'+vend[i].url+'" class="companyLogo" class="ga-event-hit" data-category="Vendors" data-action="'+vend[i].url+'" data-name="'+vend[i].name+'" target="_blank" style="background:url('+imgpath+vend[i].img+');"></a>';
        }

        var consti = vend[i].contact.match('@') ? 'mailto:' : '';

        var template = '<div class="companyProfile clearfix" data-id="'+i+'" data-active="y" data-service-id="'+vend[i].service+'" data-duration-id="'+vend[i].duration+'" data-cost-id="'+vend[i].cost+'">' + imgtemp + '<div class="companyDescription">';
		if (vend[i].name.length > 0) {
			template += '<h3>'+vend[i].name+'</h3>';
		}
		if (vend[i].url.length > 0) {
			template += '<a href="'+vend[i].url+'" class="ga-event-hit" data-category="Vendors" data-action="'+vend[i].url+'" data-value="'+vend[i].name+'" target="_blank">'+vend[i].url+'</a>';
		}
		template += '<ul class="partnerProfile">';
		if (vend[i].contact.length > 0) {
			template += '<li><strong>Contact: </strong><a href="' + consti + vend[i].contact+'" data-name="'+vend[i].name+'" target="_blank">' + vend[i].contact + '</a></li>';
		}
		if (vend[i].phone.length > 0) {
			template += '<li><strong>Phone:</strong> ' + vend[i].phone + '</li>';
		}
		if (vend[i].areas.length > 0) {
			template += '<li><strong>Areas of expertise:</strong> ' + vend[i].areas + '</li>';
		}
		if (vend[i].description.full.length > 0) {
			template += '<li class="readMore"><strong>Description:</strong> ' + vend[i].description.full + '<a href="javascript:void(0)" class="rm" data-id="' + i + '"> Read more</a></li>';
		}
		template += '</ul></div></div>';
        $results.append(template);
        var t = $results.find('.companyProfile[data-id="'+i+'"]');

        t.data('height', t.height() );
        var _h = t.find('.readMore').height();
        t.find('.readMore').data('height',_h);
        t.find('.readMore').html( '<strong>Description:</strong> '+vend[i].description.short+'<a href="javascript:void(0)" class="rm" data-id="'+i+'"> Read more</a></li>');
        var _mh = t.find('.readMore').height();
        t.find('.readMore').data('min-height',_mh);
        t.find('.readMore').height(_mh);
    }

    var serv0 = $('.ch-service[value="service-0"]'),
        serv1 = $('.ch-service[value="service-1"]'),
        cost0 = $('.ch-cost[value="cost-0"]'),
        cost1 = $('.ch-cost[value="cost-1"]'),
        cost2 = $('.ch-cost[value="cost-2"]'),
        cost3 = $('.ch-cost[value="cost-3"]'),
        dur0 = $('.ch-dur[value="duration-0"]'),
        dur1 = $('.ch-dur[value="duration-1"]'),
        dur2 = $('.ch-dur[value="duration-2"]'),
        dur3 = $('.ch-dur[value="duration-3"]');

    accessScrolling();
    $('.optionFilter :checkbox').change(function(){
    $('#vendor-result-list .companyProfile').hide();

            var serv="n", cost="n", dur="n";


                if( serv1.is(':checked') && serv0.is(':checked') ) { serv = 'a';
                } else {

                    if( serv0.is(':checked') ) {
                        serv = '0';
                    }

                    if( serv1.is(':checked') ) {
                        serv = '1';
                    }

                }

                if( cost0.is(':checked') && cost1.is(':checked') && cost2.is(':checked') && cost3.is(':checked')) { cost = 'a' } else {

                    if( cost0.is(':checked') && cost1.is(':checked') && cost2.is(':checked') ) { cost = '0-1-2';
                    }else if( cost0.is(':checked') && cost2.is(':checked') && cost3.is(':checked') ) { cost = '0-2-3';
                    }else if( cost0.is(':checked') && cost1.is(':checked') && cost3.is(':checked') ) { cost = '0-1-3';
                    }else if( cost1.is(':checked') && cost2.is(':checked') && cost3.is(':checked') ) { cost = '1-2-3';
                    } else {

                              if( cost0.is(':checked') && cost1.is(':checked') ) { cost = '0-1';
                        }else if( cost0.is(':checked') && cost2.is(':checked') ) { cost = '0-2';
                        }else if( cost0.is(':checked') && cost3.is(':checked') ) { cost = '0-3';
                        }else if( cost1.is(':checked') && cost2.is(':checked') ) { cost = '1-2';
                        }else if( cost1.is(':checked') && cost3.is(':checked') ) { cost = '0-1';
                        }else if( cost2.is(':checked') && cost3.is(':checked') ) { cost = '2-3';
                        } else {

                            if( cost0.is(':checked') ) { cost='0' }
                            if( cost1.is(':checked') ) { cost='1' }
                            if( cost2.is(':checked') ) { cost='2' }
                            if( cost3.is(':checked') ) { cost='3' }

                    }

                }
}
                if( dur1.is(':checked') && dur2.is(':checked') && dur3.is(':checked') ) { foo = 'a' } else {

                    if( dur0.is(':checked') && dur1.is(':checked') && dur2.is(':checked') ) { dur = '0-1-2';
                    }else if( dur0.is(':checked') && dur2.is(':checked') && dur3.is(':checked') ) { dur = '0-2-3';
                    }else if( dur0.is(':checked') && dur1.is(':checked') && dur3.is(':checked') ) { dur = '0-1-3';
                    }else if( dur1.is(':checked') && dur2.is(':checked') && dur3.is(':checked') ) { dur = '1-2-3';
                    } else {

                              if( dur0.is(':checked') && dur1.is(':checked') ) { dur = '0-1';
                        }else if( dur0.is(':checked') && dur2.is(':checked') ) { dur = '0-2';
                        }else if( dur0.is(':checked') && dur3.is(':checked') ) { dur = '0-3';
                        }else if( dur1.is(':checked') && dur2.is(':checked') ) { dur = '1-2';
                        }else if( dur1.is(':checked') && dur3.is(':checked') ) { dur = '0-1';
                        }else if( dur2.is(':checked') && dur3.is(':checked') ) { dur = '2-3';
                        } else {

                            if( dur0.is(':checked') ) { dur='0' }
                            if( dur1.is(':checked') ) { dur='1' }
                            if( dur2.is(':checked') ) { dur='2' }
                            if( dur3.is(':checked') ) { dur='3' }

                        }
                    }

                }



                $('#vendor-result-list .companyProfile').each(function(){
                    $(this).data('active', 'n');
                    var service,_c,_d,
                    sid = $(this).data('service-id'),
                    cid = $(this).data('cost-id'),
                    did = $(this).data('duration-id');

                    if( serv == 'a' ) { service = sid == 0 || sid == 1 || sid == '0-1'; }
                    if( serv == '0' ) { service = sid == 0 || sid == '0-1'; }
                    if( serv == '1' ) { service = sid == 1 || sid == '0-1'; }
                    if( serv == 'n' ) { service = 1 == 1; }

                    if( cost=='a' ) { _c = cid=='a' || cid == 0 || cid == 1 || cid == 2 || cid == 3 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid == '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-1-2' ) { _c = cid=='a' || cid == 0 || cid == 1 || cid == 2 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-2-3' ) { _c = cid=='a' || cid == 0 || cid == 2 || cid == 3 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-1-3' ) { _c = cid=='a' || cid == 0 || cid == 1 || cid == 3 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-2-3' ) { _c = cid=='a' || cid == 0 || cid == 2 || cid == 3 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='1-2-3' ) { _c = cid=='a' || cid == 1 || cid == 2 || cid == 3 || cid== '1-2-3'; }
                    if( cost=='0-1' ) { _c = cid=='a' || cid == 0 || cid == 1 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '1-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-2' ) { _c = cid=='a' || cid == 0 || cid == 2 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-2' || cid== '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0-3' ) { _c = cid=='a' || cid == 0 || cid == 3 || cid== '0-1' || cid== '0-2' || cid == '0-3' || cid== '1-3' || cid== '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='1-2' ) { _c = cid=='a' || cid == 1 || cid == 2 || cid== '0-1' || cid== '0-2' || cid == '1-3' || cid== '1-2' || cid== '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='1-3' ) { _c = cid=='a' || cid == 1 || cid == 3 || cid== '0-1' || cid== '0-3' || cid == '1-3' || cid== '1-2' || cid== '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='2-3' ) { _c = cid=='a' || cid == 2 || cid == 3 || cid== '0-2' || cid== '0-3' || cid == '1-3' || cid== '1-2' || cid== '2-3' || cid=='0-1-2' || cid=='0-1-3' || cid=='0-2-3' || cid=='0-1-2' || cid== '1-2-3'; }
                    if( cost=='0' ) { _c = cid=='a' || cid == 0 || cid == '0-2' || cid == '0-3' || cid == '0-1-2' || cid == '0-1-3'; }
                    if( cost=='1' ) { _c = cid=='a' || cid == 1 || cid == '1-2' || cid == '1-3' || cid == '0-1-2' || cid == '0-1-3' || cid == '1-2-3'; }
                    if( cost=='2' ) { _c = cid=='a' || cid == 2 || cid == '1-2' || cid == '2-3' || cid == '0-1-2' || cid == '0-2-3' || cid == '1-2-3'; }
                    if( cost=='3' ) { _c = cid=='a' || cid == 3 || cid == '2-3' || cid == '1-3' || cid == '0-1-3' || cid == '0-2-3' || cid == '1-2-3'; }
                    if( cost == 'n' ) { _c = 1 == 1; }

                    if( dur=='a' ) { _d = did=='a' || did == 0 || did == 1 || did == 2 || did == 3 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did == '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-1-2' ) { _d = did=='a' || did == 0 || did == 1 || did == 2 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-2-3' ) { _d = did=='a' || did == 0 || did == 2 || did == 3 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-1-3' ) { _d = did=='a' || did == 0 || did == 1 || did == 3 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-2-3' ) { _d = did=='a' || did == 0 || did == 2 || did == 3 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='1-2-3' ) { _d = did=='a' || did == 1 || did == 2 || did == 3 || did== '1-2-3'; }
                    if( dur=='0-1' ) { _d = did=='a' || did == 0 || did == 1 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '1-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-2' ) { _d = did=='a' || did == 0 || did == 2 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-2' || did== '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0-3' ) { _d = did=='a' || did == 0 || did == 3 || did== '0-1' || did== '0-2' || did == '0-3' || did== '1-3' || did== '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='1-2' ) { _d = did=='a' || did == 1 || did == 2 || did== '0-1' || did== '0-2' || did == '1-3' || did== '1-2' || did== '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='1-3' ) { _d = did=='a' || did == 1 || did == 3 || did== '0-1' || did== '0-3' || did == '1-3' || did== '1-2' || did== '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='2-3' ) { _d = did=='a' || did == 2 || did == 3 || did== '0-2' || did== '0-3' || did == '1-3' || did== '1-2' || did== '2-3' || did=='0-1-2' || did=='0-1-3' || did=='0-2-3' || did=='0-1-2' || did== '1-2-3'; }
                    if( dur=='0' ) { _d = did=='a' || did == 0 || did == '0-2' || did == '0-3' || did == '0-1-2' || did == '0-1-3' || did == '1-2-3'; }
                    if( dur=='1' ) { _d = did=='a' || did == 1 || did == '1-2' || did == '1-3' || did == '0-1-2' || did == '0-1-3' || did == '1-2-3'; }
                    if( dur=='2' ) { _d = did=='a' || did == 2 || did == '1-2' || did == '2-3' || did == '0-1-2' || did == '0-2-3' || did == '1-2-3'; }
                    if( dur=='3' ) { _d = did=='a' || did == 3 || did == '2-3' || did == '1-3' || did == '0-1-3' || did == '0-2-3' || did == '1-2-3'; }
                    if( dur == 'n' ) { _d = 1 == 1; }

                    $none.hide();

                    console.log(serv, cost, dur);

                    if( service && _c && _d ) {
                        $(this).show().data('active','y');
                    }



                });

                $error.hide();

                if( serv == 'n' && cost == 'n' && dur == 'n' ) {
                    $('#vendor-result-list .companyProfile').show();

                    //$error.show();
                }

                accessScrolling();

            });

/**
 *
 * GA Event Tracker
 * ----------------
 *
 * Takes data attributes of SEO meta and pushes to gloabl GA tracking array
 *
 */

 $('a.ga-event-hit').live('click', function(){
    var t = $(this);
    _gaq.push(['_trackEvent', t.data('category'), t.data('action') ]);

 });
/*
* Creates Virtual Pageviews
*/
 $('#nav li a, a#GOMO, #bannerLinks li a, .subnav-fx-dwn').click(function(){

    var t = $(this);
    _gaq.push(['_trackPageview', '/'+t.attr('href') ]);
     
 });
 
	/**
	 * T&C modal and Learn More modal hide/show
	 */
	 $('div.terms-and-conditions', '#yellow').hide();
	 $('#learn-more').hide();
	 $('a.linkTermsAndConditions').click(function(e) {
		$('div.terms-and-conditions', '#yellow').fadeIn();
		e.preventDefault();
	 });
	 
	 $('a#learn-more-link').click(function(e) {
		$('#learn-more').css({ 'margin-top' : '-85px' })
		$('#learn-more').fadeIn();
		
		e.preventDefault();
	 });
	 
	 $('section.legalTerms').find('a.closeTerms').click(function(e) {
		$('div.terms-and-conditions', '#yellow').fadeOut();
		$('#learn-more').fadeOut();
		e.preventDefault();
	 });
 
 
    /**
	  * Tool tip for registration process
	  */
	$('#classInfoToolTip').hide();
	$('#hoverToolTip').hover(function(e){ 
		$('#classInfoToolTip').stop(true,true).fadeToggle(); 
		e.preventDefault();
	});
	
	/**
	 * When register mmobilization jam modal close is clicked
	 * loop through all input fields with class cssPush if 1 is 0 update
	 * anythingChecked variable to true and exit loop
	 */		
	$('#mobilization-register a.close').click(function() { 			
		var requiredInputs = $('input.cssPush', '#mobilization-jam-registration');
		var anythingChecked = false;
		
		requiredInputs.each(function(i, element){
			if( $(element).val().length > 0 ) {
				anythingChecked = true;
				return false;
			}
		});
		
		if(anythingChecked) {
			$('div.registrationLightbox').fadeIn().show();
			$('#mobilization-cancel_options li').attr( "class", "" );
			$('#mobilization-cancel').fadeIn();											   
			$('#mobilization-register.modal').fadeOut(); 
		} else {			
			$('#mobilization-register.modal').fadeOut(); 
			$('div.registrationLightbox').fadeOut().remove();
			$('#yellow form .error').removeClass('error');
			$('#mobilization-jam-registration span.requiredNotice,#yellow form label, #yellow form span.fakeLabel').css('color', '#8d8d8d');
			$('#mobilization-register hgroup span.topright_required').css('display', 'none');
		}
	});

			
	$('#mobilization-thankyou a.close').click(function() {
		$('div.registrationLightbox').fadeOut().remove();
		$('#mobilization-thankyou.modal').fadeOut(); 
	});
	
	/**
	 * Cancel Mobilization 
	 */
	 $("#mobilization-cancel_submit").click( function ( e ) {
		
		if ( $('#mobilization-cancel_options-yes').attr("class") == "active" ) {
			//If user has selected Yes
			$('div.registrationLightbox').fadeOut().remove();
			$('#mobilization-cancel').fadeOut(); 
		} else if ( $('#mobilization-cancel_options-no').attr("class") == "active" ) { 
			//If user has selected NO
			$('#mobilization-cancel').fadeOut(); 
			$('#mobilization-register.modal').fadeIn(); 
		}
		e.preventDefault();
	} );
	
	 
	 $('#mobilization-cancel_options li').click ( function ( e ) {
		$('#mobilization-cancel_options li').attr( "class", "" );
		$( this ).attr( "class", "active" );
	} );
	 
	 /**
	 * Email Mobilization 
	 */
	 $("#email-cancel_submit").click( function ( e ) {
		
		if ( $('#email-cancel_options-yes').attr("class") == "active" ) {
			//If user has selected Yes
			$('#email-cancel').fadeOut(); 
			$.ajax ( {
				url : "/en/_xhr/unregister?"+lb_reg_param+"id=" + email_user_id+"&email="+email_user_email,
				success : function ( res ) {
					email_user_id = false;
				}
			} );
		} else if ( $('#email-cancel_options-no').attr("class") == "active" ) { 
			//If user has selected NO
			$('#email-cancel').fadeOut(); 
			email_user_id = false;
		}
		e.preventDefault();
	} );
	 
	 $('#email-cancel_options li').click ( function ( e ) {
		$('#email-cancel_options li').attr( "class", "" );
		$( this ).attr( "class", "active" );
	} );

 });
/*
* Captures out bound links
*/
 function recordOutboundLink(link, category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
  }

  $('.ga-outbound').click(function(e){

  	e.preventDefault();

  	recordOutboundLink( $(this).attr('href'), 'Vendors', $(this).data('name'));

  });

/**
 *
 * GoMometer privacy
 * ----------------
 *
 * Clicking link shows extra content
 *
 */

 $('a#privacy-notice-o').click(function(e){

    e.preventDefault();

    $('.gomoLegal .extraContent').fadeIn(400);

 });

/* Case Study Links */

$('.rylandDLPDF').click(function(){
	window.open('/en/media/downloads/GoMo_RylandHomes_CaseStudy.pdf');
});

$('.ticksnowDLPDF').click(function(){
	window.open('/en/media/downloads/GoMo_TicketsNow_CaseStudy.pdf');
});


/* Disable scroll arrows when not in use for BX Slider */

$(function(){

	//MM Initial Hide
	$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
	$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
	$('.mobileMatters').find('.slider1-prev a').mouseover(function() {
		$(this).css({'cursor' : 'default'});
	});
	$('.mobileMatters').find('.slider1-next a').click(function(){
		$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
		$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
		//Reasons Mobile Matters
		var mmsection = $('.mobileMatters').find('.pager-active').text();
		if (mmsection < '6' && mmsection > '1') {
			$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
			$('.mobileMatters').find('.bx-next').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.mobileMatters').find('.slider1-next a').css({'background-position':'0 0'});
			$('.mobileMatters').find('.slider1-prev a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
			$('.mobileMatters').find('.slider1-next a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}
		if (mmsection == '6') {
			$('.mobileMatters').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.mobileMatters').find('.slider1-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
		if (mmsection == '1') {
			$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
			$('.mobileMatters').find('.slider1-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
	});
	$('.mobileMatters').find('.slider1-prev a').click(function(){
		//Reasons Mobile Matters
		var mmsection = $('.mobileMatters').find('.pager-active').text();
		if (mmsection < '6' && mmsection > '1') {
			$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
			$('.mobileMatters').find('.bx-next').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.mobileMatters').find('.slider1-next a').css({'background-position':'0 0'});
			$('.mobileMatters').find('.slider1-prev a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
			$('.mobileMatters').find('.slider1-next a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}
		if (mmsection == '6') {
			$('.mobileMatters').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.mobileMatters').find('.slider1-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
		if (mmsection == '1') {
			$('.mobileMatters').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.mobileMatters').find('.slider1-prev a').css({'background-position':'0 -46px'});
			$('.mobileMatters').find('.slider1-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}

	}); //MM Hides

	//Mobile Best Practices

	$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
	$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
	$('.bestPractices').find('.slider2-prev a').mouseover(function() {
		$(this).css({'cursor' : 'default'});
	});
	$('.bestPractices').find('.slider2-next a').click(function(){
		$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
		$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
		//Reasons Mobile Matters
		var bpsection = $('.bestPractices').find('.pager-active').text();
		if (bpsection < '11' && bpsection > '1') {
			$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
			$('.bestPractices').find('.bx-next').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.bestPractices').find('.slider2-next a').css({'background-position':'0 0'});
			$('.bestPractices').find('.slider2-prev a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
			$('.bestPractices').find('.slider2-next a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}
		if (bpsection == '11') {
			$('.bestPractices').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.bestPractices').find('.slider2-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
		if (bpsection == '1') {
			$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
			$('.bestPractices').find('.slider2-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
	});
	$('.bestPractices').find('.slider2-prev a').click(function(){
		//Reasons Mobile Matters
		var bpsection = $('.bestPractices').find('.pager-active').text();
		if (bpsection < '11' && bpsection > '1') {
			$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
			$('.bestPractices').find('.bx-next').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.bestPractices').find('.slider2-next a').css({'background-position':'0 0'});
			$('.bestPractices').find('.slider2-prev a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
			$('.bestPractices').find('.slider2-next a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}
		if (bpsection == '11') {
			$('.bestPractices').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.bestPractices').find('.slider2-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
		if (bpsection == '1') {
			$('.bestPractices').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.bestPractices').find('.slider2-prev a').css({'background-position':'0 -46px'});
			$('.bestPractices').find('.slider2-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}

	}); //BP Hides

	//CASE STUDY

	$('.caseStudies').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
	$('.caseStudies').find('.slider3-prev a').css({'background-position':'0 -46px'});
	$('.caseStudies').find('.slider3-prev a').mouseover(function() {
		$(this).css({'cursor' : 'default'});
	});
	$('.caseStudies').find('.slider3-next a').click(function(){
		$('.caseStudies').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
		$('.caseStudies').find('.slider3-prev a').css({'background-position':'0 -46px'});
		//Reasons Mobile Matters
		var cssection = $('.caseStudies').find('.pager-active').text();
		if (cssection == '2') {
			$('.caseStudies').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.caseStudies').find('.slider3-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
		if (cssection == '1') {
			$('.caseStudies').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.caseStudies').find('.slider3-prev a').css({'background-position':'0 -46px'});
			$('.caseStudies').find('.slider3-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
		}
	});
	$('.caseStudies').find('.slider3-prev a').click(function(){
		//Reasons Mobile Matters
		var cssection = $('.caseStudies').find('.pager-active').text();
		if (cssection == '2') {
			$('.caseStudies').find('.bx-next').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.caseStudies').find('.slider3-next a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
			$('.caseStudies').find('.bx-prev').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.caseStudies').find('.slider3-prev a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}
		if (cssection == '1') {
			$('.caseStudies').find('.bx-prev').css({'background':'url(../media/images/large-prev-next-grey.png)'});
			$('.caseStudies').find('.slider3-prev a').css({'background-position':'0 -46px'});
			$('.caseStudies').find('.slider3-prev a').mouseover(function() {
				$(this).css({'cursor' : 'default'});
			});
			$('.caseStudies').find('.bx-next').css({'background':'url(../media/images/large-prev-next.png)'});
			$('.caseStudies').find('.slider3-next a').mouseover(function() {
				$(this).css({'cursor' : 'pointer'});
			});
		}

	}); //CS Hides

	/**
	 *	Clicking the partner logos on the landing page of the yellow section will
	 *	trigger a click on the partners link, scroll the page down to that section.
	 */
	$('#partnerLogos').delegate('a', 'click', function(e) {
		$('#yellowNavF').trigger('click');
		e.preventDefault();
	});
	
	$('#register-free-link-landing').click(function(e) {
		$('#yellowNavC').trigger('click');
		$('#mobilization-register').before('<div class="registrationLightbox"></div>').show();
		$('#mobilization-register').show();
		e.preventDefault();
	});

	/* Initially hide all but the first days event details, and say day one to be active. */
	$('#agendaListings').find('div.programmeDetails').hide();

	/**
	 *	Clicking a heading in the agenda listings will make it act like an accordion,
	 *	folding up any active days and sliding down the chosen day's programme details.
	 */
	$('#agendaListings').delegate('h3', 'click', function(e) {
		var thisHeading = $(this);
		var parentListItem = thisHeading.parent();

		if (!parentListItem.hasClass('active')) {
			parentListItem.find('div.programmeDetails').slideDown(600).promise().then(function() {
				parentListItem.addClass('active');
			});
		} else {
			parentListItem.find('div.programmeDetails').slideUp(600).promise().then(function() {
				parentListItem.removeClass('active');
			});
		}
	});


	 /* Animate the banner links in index banner */
	$('a.callToAction', '#yellow').not('#pledgeLanding a.callToAction').hover(function(){
		
		var thisLink = $(this);
		thisLink.css('left', '0');
		
		thisLink.stop().animate({
			left : '+=15'
		  }, 100);
	}, function(){
		var thisLink = $(this);
		thisLink.stop().animate({
			left : '0'
		}, 300);
	});
	
	$('#pledgeLanding a.callToAction').hover(function(){
		$(this).stop().animate({
			right : '-=10'
		  }, 100);
	}, function(){
		$(this).stop().animate({
			right : '25'
		}, 300);
	});

	/**
	 *	Scroll down to the registration page after clicking a link
	 *	in the agenda accordion.
     */
	$('#agendaListings').delegate('a.registerEvent', 'click', function(e) {
		$('#yellowNavC').trigger('click');
		$('#mobilization-register').before('<div class="registrationLightbox"></div>').show();
		$('#mobilization-register').show();
		e.preventDefault();
	});
	
	$('#agendaListings').delegate('a.registerLargeEvent', 'click', function(e) {
		$('#yellowNavC').trigger('click');
		$('#lrgBus').before('<div class="registrationLightbox"></div>').show();
		$('#lrgBus').show();
		e.preventDefault();
	});
	

	/* Making the previous button greyed out by default. */
	$('#success-stories p.previous a').css({
		'background': 'url(../media/images/large-prev-next-grey.png) 0 -49px',
		'cursor': 'default'
	});

	/**
	 *	Logic for the success stories carousel previous and next buttons.
	 */
	$('#success-stories p.previous a, #success-stories p.next a').bind('click', function(e) {
		var prevButton = $('#success-stories p.previous a');
		var nextButton = $('#success-stories p.next a');
		var slideCounter = $('#success-stories p.slideCounter');
		var activeSlide = slideCounter.children('a.pager-active');

		if (activeSlide.prev().length == 0) {
			prevButton.css({
				'background': 'url(../media/images/large-prev-next-grey.png) 0 -49px',
				'cursor': 'default'
			});
		} else if (activeSlide.next().length == 0) {
			nextButton.css({
				'background': 'url(../media/images/large-prev-next-grey.png) 0 0',
				'cursor': 'default'
			});
		}

		if (!activeSlide.is(':first-child')) {
			prevButton.removeAttr('style');
		}

		if (!activeSlide.is(':last-child')) {
			nextButton.removeAttr('style');
		}

		e.preventDefault();
	});

	pledges = {
		/**
		 *	Sets up selectors and event listeners. Also makes the call to
		 *	initialise the google map.
		 */
		initialise: function() {
			/* Setting a local reference to the object. */
			var instance = this;

			/* Caching reusable selectors / variables. */
			instance.geocoder = new google.maps.Geocoder();
			instance.requestInProgress = false;
			instance.selectors = new Array();
			instance.selectors.pledgeSection = $('#spread-the-word');
			instance.selectors.overlay = $('#pledgeScreenOverlay');
			instance.selectors.mapContainer = $('#pledgeMapContainer');
			instance.selectors.landingModal = $('#pledgeLanding');
			instance.selectors.registerModal = $('#pledgeRegister');
			instance.selectors.registerForm = $('#pledgeForm');
			instance.selectors.flipCounter = $('#flipCounter');

			/* Hiding all modals apart from the landing modal. */
			instance.selectors.mapContainer.children('div.modal').filter(':not(#pledgeLanding)').hide();

			/* Initial setup of the map. */
			instance.setupMap();

			/* Setting the initial pledge counter to zero. */
			instance.pledgeCounter = new flipCounter('flipCounter', { auto: false, value: 0 });

			/* When this section has scrolled into view, update the counter to whatever is attached to the DOM element. */
			instance.selectors.pledgeSection.bind('inview', function(event, in_view, view_x, view_y) {
				if (typeof(instance.pledgeCounter) != 'undefined') {
					instance.pledgeCounter.incrementTo(parseInt(instance.selectors.flipCounter.data('pledges')), 1, 10);
				}
			});

			/**
			 *	Clicking the close button on any modal will make said modal fade out.
			 *	Also checks to see if it needs to fade out the screen overlay.
			 */
			$('div.modal', instance.selectors.pledgeSection).delegate('a.close', 'click', function(e) {
				var parentModal = $(this).parents('div.modal');
				parentModal.fadeOut(500);
				 $("#pledgeRegister span.fillInRequiredFields").css("color", "#8d8d8d");
				 $("#pledgeRegister span.topright_required").css("display", "none");

				if (!instance.selectors.overlay.is(':hidden')) {
					instance.selectors.overlay.fadeOut(500);
				}

				e.preventDefault();
			});

			/**
			 *	Clicking the link in the landing modal or the link below the map will cause the
			 *	landing modal to fade out (if necessary), and the register modal to fade in.
			 */
			$('#pledgeLanding a.callToAction, #addYourBusiness').bind('click', function(e) {
				if (!instance.selectors.registerModal.is(':visible')) {
					if (instance.selectors.landingModal.is(':visible')) {
						instance.selectors.landingModal.fadeOut(500, function() {
							instance.selectors.registerModal.fadeIn(500);
							instance.selectors.overlay.fadeIn(500);
						});
					} else {
						instance.selectors.registerModal.fadeIn(500);
						instance.selectors.overlay.fadeIn(500);
					}
					$.ajax({
						url: '/en/_xhr/cookies?q={"fetch":["firstname", "lastname", "business", "url"]}',
						success : function (re)
						{
							if("firstname" in re.cookies)
							{
								$("#pledgeForm #pledgeFirstName").val(re.cookies.firstname);
							}
							if("lastname" in re.cookies)
							{
								$("#pledgeForm #pledgeLastName").val(re.cookies.lastname);
							}
							if("business" in re.cookies)
							{
								$("#pledgeForm #pledgeBusinessName").val(re.cookies.business);
							}
							if("url" in re.cookies)
							{
								$("#pledgeForm #pledgeWebsiteURL").val(re.cookies.url);
							}
						}
					})
				}

				e.preventDefault();
			});

			/**
			 *	Share window for facebook links in infowindows.
			 */
			instance.selectors.mapContainer.delegate('a.facebook', 'click', function(e) {
				var baseURL = getBaseURL();
				var shareURL = 'www.howtogomo.com/en/#spread-the-word';
				var imgPath = baseURL + 'media/images/gomo-fb.png';
				var summary = 'Help support Mobilizing Mobile and spread the word! #GoMobile howtogomo.com/en/#spread-the-word';
				var url = 'http://www.facebook.com/sharer.php?s=100&p[title]=GoMo: An Initiative From Google&p[url]='+shareURL+'&p[images][0]='+imgPath+'&p[summary]='+summary;
				window.open(url, 'facebook-window', 'height=500,width=750');
				e.preventDefault();
			});

			/**
			 *	Share window for twitter links in infowindows.
			 */
			instance.selectors.mapContainer.delegate('a.twitter', 'click', function(e) {
				var text = 'Help support Mobilizing Mobile and spread the word! #GoMobile" + howtogomo.com/en/#spread-the-word"';
				var url = 'http://twitter.com/intent/tweet?text='+text;
				window.open(url, 'twitter-window', 'height=500,width=750');
				e.preventDefault();
			});


			$("input#clearPledgeForm").click(function(){
				$("form#pledgeForm").resetForm();
			});

			/**
			 *	Validate the form, then on success check to see if a request is already in
			 *	progress. If not, then fade in the loader, make the AJAX request and act
			 *	accordingly.
			 */
			instance.selectors.registerForm.validate({
				errorElement   : "span",
				groups: {
					username: "firstname lastname",
					fulladdress: "address_a address_b"
				},
				highlight: function(element, errorClass, validClass) {
				   $(element).addClass(errorClass).removeClass(validClass);
				   $(element.form).find("label[for=" + element.id + "]").addClass(errorClass);	
				   $('#pledgeForm span.fakeLabel').eq(0).css("color", "red");
				   $('#pledgeForm label').eq(0).removeClass(errorClass);	
		   		   $('#pledgeForm label').eq(1).removeClass(errorClass);
				},
				unhighlight: function(element, errorClass, validClass) {
				   $(element).removeClass(errorClass).addClass(validClass);
				   $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);	
				   $('#pledgeForm span.fakeLabel').eq(0).css("color", "#8F8F8F");
				},
		
				errorPlacement: function(error, element) {
				 },
				submitHandler: function(form) {
					if (!instance.requestInProgress) {
						instance.requestInProgress = true;

						$('.spinner:last').fadeIn(500, function() {
							/* Hide any previous geo-coding or response error messages. */
							instance.selectors.registerForm.find('span.geocodingError, span.responseError').hide();

							/* Builds an address string to pass into the geocoder. */
							var address = instance.selectors.registerForm.find('input[name="address_a"]').val() + ' ';
							if (instance.selectors.registerForm.find('input[name="address_b"]').val().length > 0) {
								address = address + instance.selectors.registerForm.find('input[name="address_b"]').val() + ' ';
							}
							address = address + instance.selectors.registerForm.find('input[name="zip"]').val();

							/* Geocodes the address, updates hidden form inputs and makes an AJAX request. */
							instance.geocoder.geocode({ 'address': address }, function(results, status) {
								if (status == google.maps.GeocoderStatus.OK) {
									var lat = results[0].geometry.location.lat();
									var lng = results[0].geometry.location.lng();

									$('#pledgeLatitude').val(lat);
									$('#pledgeLongitude').val(lng);

									$.ajax({
										type: 'POST',
										url: '/en/_xhr/make_pledge',
										data : instance.selectors.registerForm.serialize(),
										success: function(data) {
											if (data.result != 'error') {
												$('.spinner:last').fadeOut(500, function() {
													if (!instance.selectors.overlay.is(':hidden')) {
														instance.selectors.overlay.fadeOut(500);
													}
													instance.selectors.registerModal.fadeOut(500, function() {
														var formData = { url: $('#pledgeWebsiteURL').val(), business: $('#pledgeBusinessName').val(), address_a: $('#addressA').val(), address_b: $('#addressB').val(), zip: $('#pledgeZipCode').val(), lat: $('#pledgeLatitude').val(), lng: $('#pledgeLongitude').val() }
														instance.requestInProgress = false;
														instance.selectors.registerForm.get(0).reset();
														instance.addMarker(formData);
													});
												});
											} else {
												$('.spinner:last').fadeOut(500, function() {
													instance.selectors.registerForm.find('span.responseError').fadeIn(500);
													instance.requestInProgress = false;
												});
											}
										},
										error: function() {
											$('.spinner:last').fadeOut(500, function() {
												instance.selectors.registerForm.find('span.responseError').fadeIn(500);
												instance.requestInProgress = false;
											});
										}
									});
								} else {
									$('.spinner:last').fadeOut(500, function() {
										instance.selectors.registerForm.find('span.geocodingError').fadeIn(500);
										instance.requestInProgress = false;
									});
								}
							});
						});
					}
				}
			});	
			$('#pledgeForm .submit input').click(function() {
			 if ($("#pledgeForm").valid() == 1) {
				  $("#pledgeRegister span.fillInRequiredFields").css("color", "#8d8d8d");
				  $("#pledgeRegister span.topright_required").css("display", "none");
			  } else if ($("#pledgeForm").valid() == 0){
				  $("#pledgeRegister span.fillInRequiredFields").css("color", "#ff0000");
				  $("#pledgeRegister span.topright_required").css("display", "block");
			  }
			});
		},
		
		/** 
		 *	Creates the google map object centered on the default location (as specified by data-attributes).
		 *	Sets marker properties (image, shadow, shape) for use with any marker to be shown on the map.
		 *	Also sets the infowindow options and creates an instance wide version of the infobox.
		 */
		setupMap: function() {
			/* Setting a local reference to the object. */
			var instance = this;

			/* Setting default map variables. */
			var startingLocation = instance.selectors.mapContainer.data('starting-location').split(', ');
			var latLng = new google.maps.LatLng(startingLocation[0], startingLocation[1]);
			var mapOptions = { center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP, zoom: 15 };

			/* Marker styling options. */
			instance.markerOptions = {
				image: new google.maps.MarkerImage(
					'/media/images/mobilizing-mobile/pledge_marker.png',
					new google.maps.Size(19, 30),
					new google.maps.Point(0, 0),
					new google.maps.Point(10, 30)
				),
				shadow: new google.maps.MarkerImage(
					'/media/images/mobilizing-mobile/pledge_marker_shadow.png',
					new google.maps.Size(37, 30),
					new google.maps.Point(0, 0),
					new google.maps.Point(10, 30)
				),
				shape: {
					coord: [11,0,14,1,15,2,16,3,17,4,17,5,18,6,18,7,18,8,18,9,18,10,18,11,18,12,18,13,17,14,17,15,16,16,16,17,16,18,15,19,15,20,14,21,14,22,13,23,13,24,12,25,11,26,11,27,10,28,10,29,9,29,8,28,7,27,7,26,6,25,6,24,5,23,5,22,4,21,4,20,3,19,3,18,2,17,2,16,2,15,1,14,1,13,0,12,0,11,0,10,0,9,0,8,0,7,1,6,1,5,1,4,2,3,3,2,4,1,7,0,11,0],
					type: 'poly'
				}
			};

			/* Binding the map to the instance, creating a markers array and setting up an infowindow. */
			instance.map = new google.maps.Map(document.getElementById('pledgeMap'), mapOptions);
			instance.markers = new Array();
			instance.infoWindow = new google.maps.InfoWindow({ maxWidth: 500 });

			/* Wait until the bounds_changed event fires before fetching local pledges, and unbinding event. */
			var initialBoundsChanged = google.maps.event.addListener(instance.map, 'bounds_changed', function() {
				instance.getPledges();
				google.maps.event.removeListener(initialBoundsChanged);
			});
		},
		/**
		 *	Performs an AJAX request to get current pledges. Loops through the response and creates a google marker
		 *	for each one, pushing it into an array. A click event is also set for each marker to open the infoBox.
		 */
		getPledges: function() {
			/* Setting a local reference to the object. */
			var instance = this;

			/* Perform AJAX request to return the local pledges within these bounds. */
			$.ajax({
				type: 'GET',
				url: '/en/_xhr/get_local_pledges',
				data: { 'min_lat': '-5.7034477', 'max_lat': '64.73664149999999', 'min_lng': '-161.2792988', 'max_lng': '-30.146483200000034' },
				success: function(data) {
					if (data.result == 'ok' && data.pledges.length > 0) {
						/* Updating the number of pledges with what we got back from the AJAX request. */
						instance.selectors.flipCounter.data('pledges', data.pledges.length);

						/* Loop through, place, and add infoboxes for the new markers. */
						$.each(data.pledges, function(index, pledge) {
							var markerLocation = new google.maps.LatLng(pledge.latitude, pledge.longitude);

							/* Generating infoWindow data. */
							var markerContent = instance.formatInfoWindow(pledge);

							/* Pushing a new marker into the markers array. */
							instance.markers.push(new google.maps.Marker({
								draggable: false,
								icon: instance.markerOptions.image,
								shadow: instance.markerOptions.shadow,
								shape: instance.markerOptions.shape,
								map: instance.map,
								position: markerLocation
							}));

							/* Adding an event listener to open the infoWindow with the relevant details. */
							var i = instance.markers.length - 1;
							google.maps.event.addListener(instance.markers[i], 'click', function() {
								var infoBoxContent = $('<div>')
									.addClass('infoBoxContent clearfix')
									.css('height', 'auto')
									.html(markerContent);

								instance.infoWindow.setContent($('<div>').append(infoBoxContent).html());
								instance.infoWindow.open(instance.map, instance.markers[i]);
								setTimeout(function() {
									gapi.plusone.render('googlePlusInfoWindow', {
										'annotation': 'none',
										'size': 'standard'
									});
								}, 500);
							});
						});
					}
				}
			});
		},
		/**
		 *	Takes a data object and adds a new marker to the stack with its own click handler.
		 *	Pans the map to the new markers location and opens the info window after a few seconds.
		 *
		 *	@param obj data - A data object containing form key / value pairs.
		 */
		addMarker: function(data) {
			/* Setting a local reference to the object. */
			var instance = this;

			/* Creating a google LatLng object from the supplied location data. */
			var markerLocation = new google.maps.LatLng(data.lat, data.lng);

			/* Generating infoWindow data. */
			var markerContent = instance.formatInfoWindow(data, true);

			/* Pushing a new marker into the markers array. */
			instance.markers.push(new google.maps.Marker({
				animation: google.maps.Animation.DROP,
				draggable: false,
				icon: instance.markerOptions.image,
				shadow: instance.markerOptions.shadow,
				shape: instance.markerOptions.shape,
				map: instance.map,
				position: markerLocation
			}));

			/* Targeting the last marker and attaching a click event listener to it. */
			var lastMarker = instance.markers.length - 1;
			google.maps.event.addListener(instance.markers[lastMarker], 'click', function() {
				var infoBoxContent = $('<div>')
					.addClass('infoBoxContent clearfix')
					.css('height', '200px')
					.html(markerContent);

				instance.infoWindow.setContent($('<div>').append(infoBoxContent).html());
				instance.infoWindow.open(instance.map, instance.markers[lastMarker]);
				setTimeout(function() {
					gapi.plusone.render('googlePlusInfoWindow', {
						'annotation': 'none',
						'size': 'standard'
					});
				}, 500);
			});

			/* Determining the markers position, and passing it into the panTo function of the map. */
			instance.map.panTo(instance.markers[lastMarker].getPosition());

			/* Triggering a click on the pin to make it open the infoBox. */
			setTimeout(function() {
				google.maps.event.trigger(instance.markers[lastMarker], 'click');
			}, 2000);
		},
		/**
		 *	Takes a data object and generates an HTML fragment string to be used
		 *	in connection with google info windows. If tagged as a thank you window,
		 *	adds in extra content.
		 *
		 *	@param obj data - A data object containing pledge data.
		 *	@param bool thankYou - A flag to dictate whether or not to add extra info.
		 *	@return string
		 */
		formatInfoWindow: function(data, thankYou) {
			/* Setting a local reference to the object. */
			var instance = this;

			formattedString = '';

			if (thankYou) {
				formattedString = formattedString + '<h3>Thank You</h3>';
				formattedString = formattedString + '<p>Thanks for committing to mobilize your site. To spread the word about what\'s happening in Mobile, AL, share this map with your friends.</p>';
			}

			if (data.business.length > 0) {
				formattedString = formattedString + '<h4>';
				if (data.url.length > 0) {
					formattedString = formattedString + '<a href="' + data.url + '" target="_blank">' + data.business + '</a>';
				} else {
					formattedString = formattedString + data.business;
				}
				formattedString = formattedString + '</h4>';
			}

			formattedString = formattedString + '<p class="address">' + data.address_a;

			if (data.address_b.length > 0) {
				formattedString = formattedString + '<br />' + data.address_b;
			}

			formattedString = formattedString + '<br />' + data.zip;

			if (data.url.length > 0 && data.business.length == 0) {
				formattedString = formattedString + '<br />' + '<a href="' + data.url + '">' + data.url + '</a>';
			}

			formattedString = formattedString + '</p>';


			formattedString = formattedString + '<img class="left" src="/media/images/mobilizing-mobile/infowindow_logo.gif" width="47" height="31" style="display: block;" />';
			formattedString = formattedString + '<ul class="social right"><li><a class="facebook">Facebook</a></li><li><a class="twitter">Twitter</a></li><li><a class="googlePlus" id="googlePlusInfoWindow">Google Plus</a></li></ul>';

			return formattedString;
		}
	};

	pledges.initialise();
	
	/**
	 * Download free PDF
	 */
	 
	$("a.already-registered-link" ).click( function( e ) { 
		return true;
	});

	$(".dlFloodlight").click(function(){
		ad_double_click('momor532');
	});
	
	
	/**
	 * Move the registration 'required' label down the page by 18px
	 * if there are validations errors preventing checkbox overlap
	 */
	/* $('#mobilization-jam-registration .submit input').click(function() { 	
		$('input.cssPush', '#mobilization-jam-registration').each(function(i, element){
			if( $(element).val().length == 0 ) {
				$('#mobilization-register .requiredNotice').css({ bottom : -18 });
			}
		});
	});*/

	/** 
	  * Registration page
	  */
	$('#mobilization-register').hide();
	$('#register-free-link').click(function(e) {
		ad_double_click('momor393');
		
		$('#yellow form .error').removeClass('error');
		$('#mobilization-jam-registration span.requiredNotice,#yellow form label, #yellow form span.fakeLabel').css('color', '#8d8d8d');
		$('#mobilization-register hgroup span.topright_required').css('display', 'none');			
		// reset required label position to 0
		//$('#mobilization-register .requiredNotice').css({ bottom : 0 });
		//Check if Large Business is open
		if ( $( "#lrgBus" ).is(':visible') ) {
			e.preventDefault();
			return false;
		}
																		 
		//Clear all form fields
		$( "#mobilization-jam-registration input" ).each( function( index, value ) { 
			if ( value.type != 'submit' ) {
				value.value = "";
				value.checked = false;
			}
		});	

		//Hide all validation notifications
		mobilization_validation.resetForm();	
		$('#mobilization-register').before('<div class="registrationLightbox"></div>').fadeIn();
		$('#mobilization-register').fadeIn();
		
		$.ajax({
			url : '/en/_xhr/cookies/?q={"fetch":["mobjam"]}',
			success:function(re)
			{
				if ('mobjam' in re.cookies)
				{
					if (re.cookies.mobjam)
					{
						$("#clear-registration").fadeIn();
						$("#clear-registration_options-yes").click(function()
						{
							$("#clear-registration_options-yes").addClass('active');
							$("#clear-registration_options-no").removeClass('active');
						});
						$("#clear-registration_options-no").click(function()
						{
							$("#clear-registration_options-no").addClass('active');
							$("#clear-registration_options-yes").removeClass('active');
						});
						$("#clear-registration_submit").click(function()
						{
							if ($('#clear-registration_options-yes').hasClass('active'))
							{
								$("#clear-registration").fadeOut();
							}
							if ($('#clear-registration_options-no').hasClass('active'))
							{
								$("#clear-registration").fadeOut();
								$('#mobilization-register').fadeOut();
								$('.registrationLightbox').fadeOut().remove();
							}
						});
					}
				}
			}
		})
		
		//Use AJAX to get event data
		$.ajax( { 
			url : "/_xhr/get_latest_events",
			success : function ( data ) { 
				event_data = data;

				var event_html = "";
				var session_html = "";
				var first_id = false;
				var first_session_id = false;

				window.exclusions = []
				for ( var i in data.events ){
					//Create Markup for each event, and it's associated session
					first_id = !first_id ? data.events[i].id : first_id;

					var datePieces = data.events[i].date.split('-');
					var temp_date = new Date(datePieces[0], (datePieces[1] - 1), datePieces[2]);

					event_html += '<li><a href="" id="event_option_'+ data.events[i].id +'" rel="'+ data.events[i].id +'">'+ temp_date.format('l' + ',' + ' F d') +'</a></li>';
					session_html += '<ul class="available-sessions" id="session_table_'+ data.events[i].id +'">';

					for ( var j in data.events[i].sessions ) {
						first_session_id = !first_session_id ? data.events[i].sessions[j].id : first_session_id;
						session_html += 
							'<li id="session_row_'+ data.events[i].sessions[j].id +'">'+ data.events[i].sessions[j].time+
							'<div class="right">'+ ((data.events[i].sessions[j].available > 0) ? data.events[i].sessions[j].available : '0') +' sessions remaining</div></li>';
					}				
					
					session_html += '</ul>';					
					window.exclusions[data.events[i].id] = data.events[i].exclude;
				}

				//Inject Markup
				$("#session-selection-tabs").html( event_html );
				$("#session-container").html( session_html );
				
				//Make first visible
				$( "#session-container ul" ).hide();
				$( "#session_table_" + first_id ).show();
				//Highlight default options
				//$( "#event_option_" + first_id ).attr( "class", "active" );
				$( "#session_row_" + first_session_id ).attr( "class", "active" );
				//Set default values
				$( "#event_id" ).val( first_id );
				$( "#session_id" ).val( first_session_id );
				
				
				$('#session-selection-tabs li a').click(function(e) {
					var id = $( this ).attr( "rel" );
					$( "#session-container ul" ).hide();
					$( "#session_table_" + id ).show();
					$( "#session-selection-tabs li a" ).attr( "class", "" );
					$( "#event_option_" + id ).attr( "class", "active" );
					
					$( "#event_id" ).val( id );

					$("#growBusiness1").parent().show();
					$("#growBusiness2").parent().show();
					$("#growBusiness3").parent().show();
					$("#maxMobile1").parent().show();
					$("#maxMobile2").parent().show();
					$("#maxMobile3").parent().show();

					for (var j in window.exclusions[id])
					{
						$("#"+window.exclusions[id][j]).parent().hide();
					}
					
					e.preventDefault();
				});
				$('#session-selection-tabs li a').eq(0).click();

				$('#session-container ul li').click(function(e) {
					var id = $( this ).attr( "id" );

					$( "#session-container ul li" ).attr( "class", "" );
					$( "#" + id ).attr( "class", "active" );
					
					$( "#session_id" ).val( id.replace( "session_row_", "" ) );
					
					e.preventDefault();
				});
			}
		} );
		
		e.preventDefault();
	});
	
	var mobilization_validation = $( "#mobilization-jam-registration" ).validate( {
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		errorElement   : "span",
		groups: {
    		username: "firstName lastName"
 		},
		highlight: function(element, errorClass, validClass) {
		   $(element).addClass(errorClass).removeClass(validClass);
		   $(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
		   $('#mobilization-jam-registration label').eq(0).removeClass(errorClass);	
		   $('#mobilization-jam-registration label').eq(1).removeClass(errorClass);

		   $('#fakeLabelName').css("color", "red");	
		},
		unhighlight: function(element, errorClass, validClass) {
		   $(element).removeClass(errorClass).addClass(validClass);
		   $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);	
		   $('#fakeLabelName').css("color", "#8F8F8F");		
		},

		errorPlacement: function(error, element) {
			  
		 },
		submitHandler : function( form ) {
		
			var params = {
				firstname : form.firstName.value,
				lastname : form.lastName.value,
				phone : form.fullPhone.value,
				email : form.email.value,
				business : form.businessName.value,
				url : form.websiteURL.value,
				event_id : form.event_id.value,
				session_id : form.session_id.value,
				other_sessions : ''
			};
			
			var current_event = false;
			var current_session = false;
			
			for( var i in event_data.events ) {
				if ( event_data.events[i].id == params.event_id ) {
					current_event = event_data.events[i];
				}
			}
			
			if ( current_event ) {
				for( var i in current_event.sessions ) {
					if ( current_event.sessions[i].id == params.session_id ) {
						current_session = current_event.sessions[i];
					}
				}
			}
			if ( current_session ) {
				var datePieces = current_event.date.split('-');
				var temp_date_obj = new Date(datePieces[0], (datePieces[1] - 1), datePieces[2]);
				
				var temp_date = temp_date_obj.format( 'l F d' );
				var temp_time = current_session.time;
			} else { 
				var temp_date = '';
				var temp_time = '';
			}
			var thankyouinfo = '<li>&bull; A Free website consultation at '+ temp_time +' on '+ temp_date +'.</li>';
			
			$( "#seminars input" ).each( function (index, value) { 
				params[ 'other_sessions' ] += seminars[ value.name ].name +' at '+ seminars[ value.name ].time +' : '+value.checked+', ';
				if ( value.checked ) {
					thankyouinfo += '<li>&bull; ' + seminars[ value.name ].name +' at '+ seminars[ value.name ].time +' on '+ temp_date +'</li>';
				}
			} );
			
			$( '#thankYouSelection' ).html( thankyouinfo );
			
			$('div.spinner').fadeIn();
			$.ajax( {
				url : "/en/_xhr/register_for_session",
				type : "POST",
				data : params,
				success : function( data ) {
					if ( data.result == 'ok' ) {
						$('div.spinner').fadeOut();
						$('#mobilization-register').fadeOut();
						$('#mobilization-thankyou').fadeIn();
					}
					else
					{
						alert("Registration could not be completed. ("+data.text+")");
						$('div.spinner').fadeOut();
					}
				}
			} );
			
			return false;
		}
	});
	
	
	$('#mobilization-jam-registration .submit input').click(function() {
  	 if ($("#mobilization-jam-registration").valid() == 1) {
		  $("#mobilization-jam-registration span.requiredNotice").css("color", "#8d8d8d");
		  $("#mobilization-register hgroup span.topright_required").css("display", "none");	
	  } else if ($("#mobilization-jam-registration").valid() == 0){
		  $("#mobilization-jam-registration span.requiredNotice").css("color", "#ff0000");
		  $("#mobilization-register hgroup span.topright_required").css("display", "block");
		  $('#fakeLabelPhone').css("color", "red");
	  }
	});

	$( "#noWebsite" ).change( function ( e ) {
		if ( this.checked ) {
			$("#mobilizeWebsiteURL").val( "none" );
			$('#mobilizeWebsiteURL').attr("disabled", true); 
		} else {
			$("#mobilizeWebsiteURL").val( "" );
			$('#mobilizeWebsiteURL').removeAttr("disabled"); 
		}
	});
	
	$( "#mobilizeCountryCode, #mobilizeAreaCode, #mobilizePhone" ).change( function ( e ) {
		var phone_value = "";
		
		var country_code = $("#mobilizeCountryCode").val().trim();
		var area_code = $("#mobilizeAreaCode").val().trim();
		var phone = $("#mobilizePhone").val().trim();
		
		if (phone_value == 0 ){
			$('#fakeLabelPhone').css("color", "red");
		}
		if ( country_code.length > 0 ){
			phone_value += '(' + country_code +') ';
			$('#fakeLabelPhone').css("color", "#8F8F8F");	
		}
		if ( area_code.length > 0 ){
			phone_value += area_code +' ';
			$('#fakeLabelPhone').css("color", "#8F8F8F");
		}
		if ( phone.length > 0 ){
			phone_value += phone;
			$('#fakeLabelPhone').css("color", "#8F8F8F");
		}
		
		$("#mobilizeFullPhone").val( phone_value );
	} );	


	$('#shareTheMap').click(function()
	{
		ad_double_click('momos904');
	});
	
	/**
	 * Large Business Registration Form
	 */
	 $('#lrgBus').hide();
	 $('a.register-large-link').click(function(e) {
		
		//Doubleclick ad 
		ad_double_click('momor075');
		
		$('#lrgBus').before('<div class="registrationLightbox"></div>').fadeIn();
		
		//Clear all input fields
		$( "#lrgBus input" ).each( function( index, value ) { 
			if ( value.type != 'submit' ) {
				value.value = "";
				value.checked = false;
			}
		} );
		
		//Hide all validation notifications
		lrgBus_validation.resetForm();
		
		e.preventDefault();
	 });
	 
	 $('#lrgBus a.close').click(function(e) {
		$('#lrgBus').fadeOut();
		$('div.registrationLightbox').fadeOut().remove();
		$('#yellow form .error').removeClass('error');
		$('#lrgBus-form span.requiredNotice,#yellow form label, #yellow form span.fakeLabel').css('color', '#8d8d8d');
		$('#lrgBus hgroup span.topright_required_large').css('display', 'none');
		e.preventDefault();
	 });
	 
	$('#lrgBus-thankyou a.close').click(function(e) {
		/*$('div.registrationLightbox').fadeOut().remove();*/
		$('#lrgBus-thankyou.modal').fadeOut(); 
		$('div.registrationLightbox').fadeOut().remove();
		e.preventDefault();
	});
	
	$('a.triggerSpreadWord', '#register').click(function(e) {		
		$('#lrgBus-thankyou.modal').fadeOut(); 
		$('#mobilization-thankyou.modal').fadeOut(); 
		$('div.registrationLightbox').fadeOut().remove();
		$('#yellowNavD').trigger('click');
		e.preventDefault();
	});
	 
	 var lrgBus_validation = $("#lrgBus-form" ).validate( {
		 rules: {
			email: {
				required: true,
				email: true
			}
		},
		errorElement   : "span",
		groups: {
    		username: "firstName lastName"
 		},
		highlight: function(element, errorClass, validClass) {
		   $(element).addClass(errorClass).removeClass(validClass);
		   $(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
		   $('#lrgBus-form span.fakeLabel').eq(0).css("color", "red");
		   $('#lrgBus-form label').eq(0).removeClass(errorClass);	
		   $('#lrgBus-form label').eq(1).removeClass(errorClass);

		   

		   
		   	
		},
		unhighlight: function(element, errorClass, validClass) {
		   $(element).removeClass(errorClass).addClass(validClass);
		   $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);	
			$('#lrgBus-form span.fakeLabel').eq(0).css("color", "#8F8F8F");
		},
		errorPlacement: function(error, element) { 
		 },
		submitHandler : function( form ) { 
		
			var params = {
				firstname : form.firstName.value,
				lastname : form.lastName.value,
				phone : form.fullPhone.value,
				email : form.email.value
			};
			
			
			$('div.spinner').fadeIn();
			$.ajax( {
				url : "/en/_xhr/register_large_business",
				type : "POST",
				data : params,
				success : function( data ) {
					if ( data.result == 'ok' ) {
						$('div.spinner').fadeOut();
						$('#lrgBus').fadeOut();
						$('#lrgBus-thankyou').fadeIn();
					}
				}
			} );
			
			return false;
		}
	} );
	
	$('#lrgBus-form .submit input').click(function() {
  	 if ($("#lrgBus-form").valid() == 1) {
		  $("#lrgBus-form span.requiredNotice").css("color", "#8d8d8d");
		  $("#lrgBus hgroup span.topright_required_large").css("display", "none");
		  
	  } else if ($("#lrgBus-form").valid() == 0){
		  $("#lrgBus-form span.requiredNotice").css("color", "red");
		    $("#lrgBus hgroup span.topright_required_large").css("display", "block");
		    $('#lrgBus-form span.fakeLabel').eq(1).css("color", "red");
	  }
	});
	 
	 $( "#lrgBusCountryCode, #lrgBusAreaCode, #lrgBusPhone" ).change( function ( e ) {
		var phone_value = "";
		
		var country_code = $("#lrgBusCountryCode").val().trim();
		var area_code = $("#lrgBusAreaCode").val().trim();
		var phone = $("#lrgBusPhone").val().trim();
		
		if (phone_value == 0 ){
			$('#lrgBus-form span.fakeLabel').eq(1).css("color", "red");
		}
		if ( country_code.length > 0 ){
			phone_value += '(' + country_code +') ';
			$('#lrgBus-form span.fakeLabel').eq(1).css("color", "#8F8F8F");
		}
		if ( area_code.length > 0 ){
			phone_value += area_code +' ';
			$('#lrgBus-form span.fakeLabel').eq(1).css("color", "#8F8F8F");
		}
		if ( phone.length > 0 ){
			phone_value += phone;
			$('#lrgBus-form span.fakeLabel').eq(1).css("color", "#8F8F8F");
		}
		
		$("#lrgBusFullPhone").val( phone_value );
	} );
	 
	var event_data = {};
	 
	 var seminars = {
		growBusiness1 : { name : 'Growing Your Business Online', time : '10:30 AM' },
		growBusiness2 : { name : 'Growing Your Business Online', time : '1:30 PM' },
		growBusiness3 : { name : 'Growing Your Business Online', time : '4:30 PM' },
		maxMobile1 : { name : 'Maximizing Mobile', time : '9 AM' },
		maxMobile2 : { name : 'Maximizing Mobile', time : 'NOON' },
		maxMobile3 : { name : 'Maximizing Mobile', time : '3 PM' },
	 }
	 
	 
	 
	 Date.prototype.format = function(format) {
		//Extends the DATE object to allow PHP style date formatting
		var formats = {Y: '#_year_#', m: '#_month_#', d: '#_day_#', H: '#_hour(24)_#', i: '#_minute_#', s: '#_seconds_#', F: '#_monthstring_#', l: '#_daystring_#', S : '#_suffix_#' };
		var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
		var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
		
		var d = this.getDate();
		var dMod = d % 10;
		var ex = (d >= 10 && d <= 20 ) ? 'th' : ( dMod == 1 ) ? 'st' : ( dMod == 2 ) ? 'nd' : ( dMod == 3 ) ? 'rd' : 'th';
		
		for ( var i in formats ) {
			var format = format.replace( i, formats[i] );
		}
		
		format = format.replace( formats['Y'], this.getFullYear() );
		format = format.replace( formats['m'], this.getMonth() + 1 );
		format = format.replace( formats['d'], this.getDate() );
		format = format.replace( formats['H'], this.getHours() );
		format = format.replace( formats['i'], this.getMinutes() );
		format = format.replace( formats['s'], this.getSeconds() );
		format = format.replace( formats['F'], months[ this.getMonth() ] );
		format = format.replace( formats['l'], days[ this.getDay() ] );
		format = format.replace( formats['S'], ex );
		
		return format;
	};
	
});

