$(document).ready(function() {
	var shellHeight = $('.col6').height();
	$('.pic-video a').click(function(e) {
		e.preventDefault();
		$('#videoLightbox').html('<iframe src="http://player.vimeo.com/video/30954210?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="640" height="424" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>');
		$('.pic-video a').colorbox({inline:true, href:'#videoLightbox'});
		rebindClose();
	});
	
	
	//
	//$('.video').colorbox({inline:true, href:'#videoLightbox'});

	$('.homeVideo').click(function(e) {
		e.preventDefault();
		$('.title-pic').html('<iframe src="http://player.vimeo.com/video/30954210?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="1104" height="521" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>');
	});

	if($('#franchisePage').length > 0 && document.location.search !== '') {
		var city = queryString('c');
		var state = queryString('s');
		var zip = queryString('z');
		
		$('.addressInput').val(zip);
		$('#addressInput2').val(city);
		$('#state').val(state);
		setTimeout('triggerLocationSubmit()', 1000);
	}
	
	$('.submitMailchimp').click(function(e) {
		e.preventDefault();
		$('#mc_signup_submit').trigger('click');
	});
	
	setTimeout("setSidebarHeight()",1000);
	
	$('.triggerEmail').click(function(e) {
		e.preventDefault();
		$('.form-contact').show();
	});
	
	$('.growthMarkets li a').click(function(e) {
		e.preventDefault();
		$(this).parent().parent().find('.active').not('.growthMarkets li ul li ul .active').removeClass('active');
		$(this).addClass('active');
		
		if($(this).text() === 'Canada' || $(this).text() === 'U.S.A.') {
			$('.growthMarkets li ul').hide();
		} else {
			$('.growthMarkets li ul li ul').hide();
		}
		
		$(this).next().show();
		var blockHeight = $(this).next().height();
		
		
		$('.col6').css({height : shellHeight + blockHeight + 'px'});		
	});

	
	setTimeout("bindForm()",1000);
	setTimeout("bindForm2()",1000);
});

function rebindClose() {
	$('#cboxOverlay, #cboxClose').click(function() {
		$('#videoLightbox').html('');
	});
}

function setSidebarHeight() {	
	if($('.blogcol').length === 0) {
		$('#rightcol').css({minHeight : $('#centercol').height() + 'px'});
		$('.rightcolShell').css({height : $('#rightcol').height() - 835 + 'px'});
	} else {
		$('#rightcol').css({minHeight : $('#centercol').height() + 'px'});
		$('.rightcolShell').css({height : $('#rightcol').height() - 635 + 'px'});
	}
		
	if($('#rightcol').length > 0 && $('#rightcol-content').length > 0) {
		$('#rightcol-content').stickyfloat();
	}
}

function triggerLocationSubmit() {
	$('#addressSubmit').trigger('click');
}

function queryString(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function bindForm() {
	$('.submitbtn').live('click', function(e) {
		e.preventDefault();
		$('#letusCare').trigger('submit');
	});
	
	
	$('#letusCare').submit(function(e) {
		var email = ($('#franchiseEmail').attr('name') !== '') ? $('#franchiseEmail').attr('name') : '';
		e.preventDefault();
		var str = $(this).serialize();
		$.ajax({
			type: 'POST',
			url: '/emailScript.php',
			data: str + '&frEmail='+email,
			success: function(response) {
				$('#result').html(response);
			}
		});
		return false;
	});
}

function bindForm2() {
	$('#homeForm .btn').live('click', function(e) {
		e.preventDefault();
		$('#homeForm').trigger('submit');
	});
	
	
	$('#homeForm').submit(function(e) {
		e.preventDefault();
		var str = $(this).serialize();
		$.ajax({
			type: 'POST',
			url: 'http://www.nursenextdoorfranchise.com/emailScript2.php',
			data: str,
			success: function(response) {
				if(response =='error')
				{
					$('#result').html('Please enter a valid email address.');
				}
				else
				{
				//$('#result').html(response);
				window.location.href="http://www.nursenextdoorfranchise.com/form-thank-you/";
				//setTimeout("window.location.href='http://web2.anzleads.com/NND/dev/nursenextdoorfranchise/'",2000);
				}
			}
		});
		return false;
	});
	
	$('.homeForm .btn').live('click', function(e) {
		e.preventDefault();
		$('.homeForm').trigger('submit');
	});
	
	
	$('.homeForm').submit(function(e) {
		e.preventDefault();
		var str = $(this).serialize();
		$.ajax({
			type: 'POST',
			url: 'http://www.nursenextdoorfranchise.com/emailScript2.php',
			data: str,
			success: function(response) {
				if(response =='error')
				{
					$('#result2').html('Please enter a valid email address.');
				}
				else
				{
				//$('.result').html(response);
				window.location.href="http://www.nursenextdoorfranchise.com/form-thank-you/";
				//setTimeout("window.location.href='http://web2.anzleads.com/NND/dev/nursenextdoorfranchise/'",2000);
				}
			}
		});
		return false;
	});
}
