// CUSTOM.js

var isactive = 0;
var goToCurrent = 0;
var zipis = 0;
var setInt = 1;
var thisHeight = 0;
var href = '';
var requireszip = false;
var topCord;
var valid = true;
var scroll_top = 0;

	var interval_for_input = 0;
	var last_input = '';
	var current_input = '';


function console_log(n){
	//console.log(n);
	//$('#column_left').append(n+'<br />');
}


function isValidZipCode(value) {
   var re = /^\d{5}([\-]\d{4})?$/;
   return (re.test(value));
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	return true;
	else
	return false;
	
  // var re = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  // return (re.test(value));
}

function IsNumeric(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}

function getCityStateZip(addr){
	var city; var state;var zip;
	city = ''; state = ''; zip = '';
	var addrLen = addr.length;
	if ( IsNumeric( addr.substring(addrLen - 1) ) ) {
		//contains a zipcode - just a sanity check
		//get last 10 characters for testing easily
		var lastTen = addr.substring( addrLen - 10 );
		if ( lastTen.indexOf('-') > 0 && ( lastTen.indexOf(' ') == -1 ) ) {
			//found a hyphen and no space (matches our complex rule for zipcodes)
			zip = lastTen;
		} else {
			zip = addr.substring( addrLen - 5 ); //assume a basic 5 zip code
		}
	}
	var zipLen = zip.length;
	addrLen = addrLen - zipLen - 0;
	addr = addr.substring(0, addrLen ); //remove the chars we just moved into zip
	
	var lastComma = addr.lastIndexOf(',');
	if ( lastComma == -1 ) {
		//you have a problem, how do you want to handle it?
	}
	city = addr.substring(0,lastComma); //skip the comma itself, yes?
	state = addr.substring(lastComma + 2);
	//alert(addr);
	return { 'city':city,'state': state,'zip': zip };
}



function fancyClosings(){

	var msg          = $('div#closing_message').html();
	var opening_time = $('div#closing_message').attr('rel');
	var closing_date = $('div#closing_message').attr('alt');
	
	if(opening_time == 'Closed all day.'){
	
		opening_time = 'We will be closed all day today';
	}
	
	else {
		
		opening_time = 'This store will reopen today at ' + opening_time;
	}

	//alert(closing_date);
	
	// <h3>This store is closed today.</h3>
	
	$.fancybox(
		'<div id="fancy_closing_message"><h3>'+closing_date+'</h3><p>'+msg+'</p><p>'+opening_time+'.</p></div>',
		{
			'padding'        		: 10,
			'margin'        		: 0,
			'scrolling'        		: 'no',
			'transitionIn'		    : 'none',
			'showCloseButton'		: true,
			'transitionOut'		    : 'none'
	});

}

$(document).ready(function(){






	$('body.press-release .wrap_entry h2').click(function(){
		
		//alert('-');
		
		var link_to_href = $(this).closest('.wrap_entry').find('a').attr('href');
		
		if(link_to_href){
			window.location = link_to_href;
		}
	});












	var is_index = $('body.home').length;

	if(is_index){
	
		setTimeout(function(){
						
			$('body').append('<div id="zip_input_tip2"><p>Tell us a bit<br />about yourself.</p></div>');
		
		}, 1500);
	
	} // if .home
	

	// STORE CLOSING
	// does closing exit?
	var closing_date = $('div#closing_message').length;
	
	if(closing_date){
	
		fancyClosings();
		
	}
	
	$('li#happy_closing a#closing_alert').click(function(){
	
		fancyClosings();
		return false;
	
	});







	// realign top nav based on the width of the local phone #
	var local_phone_exist = $('div#local_phone_wrap').length;
	
	if(local_phone_exist){
		
		var local_phone_width = $('div#local_phone_wrap').width();
		
		var new_padding = local_phone_width + 30;
		
		//setTimeout(function(){
		
		$('div#local_phone_wrap').parent().css({'width':local_phone_width+3});
			
		//},1000);
	
	} // if

	
	setTimeout(function(){
	
		//alert('under construction');
		$('a#locations_directory').hide(); //.css({'text-indent':'-999px', 'overflow':'hidden'});	
	
	},2000);
	

	var greenFloatBoolean = $('div#green_float').length;
	var greenBoolean = $('div#store_locations_top').length;
	var greenBooleanAll = $('div#store_locations_all').length;
	
	if(greenBoolean || greenBooleanAll){
		
		$('#green_float').remove();
		
	}

	if(greenBooleanAll){
		
		//window.location = "/index.php";
		
	}

	
	var currentpathname = window.location.pathname;
	
	$('a[href*="'+ currentpathname +'"]').addClass('current_page');
		
	goToCurrent = 1;

	function toggle_green_bar_height(){
		if(thisHeight > 18) {
			$('div#green_float').css('background-image','url(/assets/img/green_float_tall.png)');
		}	
		else {
			$('div#green_float').css('background-image','url(/assets/img/green_float.png)');
		}	
	}

	function initial_current_nav_state(speed) {
		
		//console.log('initial_current_nav_state');
		
		//var topCord = 0;
		var newText = '';
		var currentBoolean = $('a.current_page').length;
		
		//console.log('currentBoolean: '+currentBoolean);
		
		//alert(currentBoolean);
		newText = $('a.current_page').html();
		newURL = $('a.current_page').attr('href');
		
		//console.log('newText: '+newText);
		//console.log('newURL: '+newURL);
		
		// double check to seee if the greenbar href is actually in the nav
		var green_href_in_nav = $('ul#left_column_nav li a[href="'+newURL+'"]').length;
				

		//topCord.top = 0;
		//alert(topCord);
		thisHeight = $('a.current_page').height();
		//$('div#green_float').find('a').fadeOut('slow');

		if(goToCurrent && greenFloatBoolean){
		
			//console.log('green_href_in_nav: ' + green_href_in_nav);
			
			if(!currentBoolean || !green_href_in_nav){ 
			
				$('div#green_float').hide(); 
			
			}
			else {
				toggle_green_bar_height();
					var topCord = $('a.current_page').offset(); // position = { left: 42, top: 567 }
					var topCordTop = topCord.top -6;

				//alert(topCordTop);
				
				if(topCordTop <= 0) {
					topCordTop = '-222';
				}

				$('div#green_float').stop().animate({
					top: topCordTop
					}, speed, function() {
					// Animation complete.
					
					//$('div#green_float').find('a').fadeIn('slow');
				});
				
				$('div#green_float').find('a').html(newText).attr('href',newURL);
			}
		} // if
		else {
			
		}
		clearTimeout (setInt);
		goToCurrent = 0;
		
	} // initial_current_nav_state
	
	setTimeout(initial_current_nav_state, 200, 0);
	






// MOVE GREEN BAR //

	$('ul#left_column_nav a').mouseover(function() {
		//alert($(this));
		$('div#green_float').show();
		var newText = '';
		goToCurrent = 0;
		newText = $(this).html();
		newURL = $(this).attr('href');
		topCord = $(this).offset(); // position = { left: 42, top: 567 }
		thisHeight = $(this).height();
		toggle_green_bar_height();
		//$('div#green_float').find('a').animate({opacity: 0.5,}, 0);
		//alert(thisHeight);
		
		$('div#green_float').stop().animate({
			top: (topCord.top -6)
			}, 300, function() {
			// Animation complete.
			//$('div#green_float').find('a').stop().animate({opacity: 1,}, 0);
			
		});
		$('div#green_float').find('a').html(newText).attr('href',newURL);
		
	});
	
	$('div#green_float').mouseover(function() {
		goToCurrent = 0;
	});
	
	$('div#green_float').mouseout(function() {
		goToCurrent = 1;
	});
	
	$('ul#left_column_nav').mouseout(function() {
		goToCurrent = 1;
		setInt = setTimeout(initial_current_nav_state, 3500, 500);
	});
		
	$('div#orange_bar h4').click(function(){
		//alert('choices');
		$('ul#drop_down_choices').fadeIn('fast');
		$('div#zip_input_tip2').remove();
	});
	
	$('ul#drop_down_choices').mouseleave(function(){
		//alert('orange');
		$(this).fadeOut('fast');
	});
	
	
	$('div#go_button').attr('active', 'false');
	$('form#user_type').attr('disabled', true);
	$('div#go_button').fadeTo('fast',0.4);

	
	// CHOICES
	$('ul#drop_down_choices a').click(function(){
				
		$('div#go_button').attr('active', 'true');
		$('form#user_type').removeAttr('disabled');
		
		//go button not gray
		$('div#go_button').fadeTo('fast',1.0);


			$('body').append('<div id="zip_input_tip"><p>Enter your zip code<br />or city & state (EX: City, ST).</p></div>');
		//$('body').append('<div id="zip_input_tip"><p>Enter your zip code.</p></div>');

		
		//alert('asdf');
		href      = $(this).attr('href');
		var href_text = $(this).html();
		//alert(href);
		$('input#user_type_html').attr('value',href);
		$('div#orange_bar h4').html(href_text);
		$('ul#drop_down_choices').fadeOut('fast');
		$('div#orange_bar h4').autoEllipsis();
		if($(this).attr('alt') == 'need_zip'){
			$('input#zip_input').removeClass('zip_gray');
			requireszip = true;
			//$('input#user_type_html').attr('alt', altis);
		}
		else {
			$('input#zip_input').addClass('zip_gray');	
			requireszip = false;
		}
		$('form#user_type input#zip_input').focus(); //.val('');
		
		var zip_input_val = $('form#user_type input#zip_input').val();
		if(zip_input_val == 'Enter Your Location'){
		
			$('form#user_type input#zip_input').val('');
		}
		
	//	$('form#user_type input#zip_input').focus();
		return false;
	});
	
	
/*		

	$('input#zip_input').autocomplete({
		source: "/assets/ajax/auto_complete_zip_city.php"		
	});
	
*/

	function init_autocomplete(){

		$('body input#zip_input').autocomplete({  
	   
	             //define callback to format results  
	             source: function(req, add){  
	   
	                 //pass request to server  
	                 $.getJSON("/assets/ajax/auto_complete_zip_city.php?callback=?", req, function(data) {  
	   
	                     //create array for response objects  
	                     var suggestions = [];  
	   
	                     //process response  
	                     $.each(data, function(i, val){  
	                     
	                     suggestions.push(val.name);
	                     
	                 });  
	   
	                 //pass array to callback  
	                 add(suggestions);  
	             });  
	         }
	    });  	

	} // init_autocomplete
	
	init_autocomplete();
	
	
	
	$('form#user_type input#zip_input').click(function(){
			
			//$('form#user_type input#zip_input').trigger('focus');

			//var init_val = 	$(this).attr('rel');	
			//$(this).attr('rel', init_val);			
			
			
			var thisval = $('form#user_type input#zip_input').val();
			//alert(thisval);
			if(thisval == 'Enter Your Location') {
				$('form#user_type input#zip_input').val('');
				$('form#user_type input#zip_input').removeClass('zip_gray');
			}
			
			//alert('focus');
			var zip_input_tip = $('div#zip_input_tip').length;
			
			if(!zip_input_tip){
			
			$('body').append('<div id="zip_input_tip"><p>Enter your zip code<br />or city & state (EX: City, ST).</p></div>');
				//$('body').append('<div id="zip_input_tip"><p>Enter your zip code.</p></div>');
				
			}
			//$('#local_phone_center big').html('focus');
			
			/*
			
			interval_for_input = setInterval(function(){
			
				current_input = $("form#user_type input#zip_input").val();
			
				//$('#local_phone_center big').html(current_input +' - '+ last_input);
			
				if(current_input != last_input){			
							
					//$('#local_phone_center big').html(current_input +' - '+ last_input);	
							
					current_input = $("form#user_type input#zip_input").val();		
							
					$.ajax({
							type: "POST",
							url: '/assets/ajax/auto_complete_zip_city_session.php',
							data: "current_input="+current_input,
							success: function(msg){
														
								//console_log(msg);
								last_input = current_input;
								
							} // success
							
					}); //ajax
					
				} // if
			
			}, 200);
			
			*/
				
					
	});
	
	
	$('form#user_type input#zip_input').bind('blur',function(){
										
			//$(this).removeClass('zip_gray');
			var thisval = $(this).val();
			//alert(thisval);
			if(thisval == '') {
				$(this).val($(this).attr('rel'));
			}
			
			$('div#zip_input_tip').remove(); 
		
			//clearInterval(interval_for_input);	
			
	});
	
	
	
	
	
	$('div#orange_bar h4').autoEllipsis();

	$('div#go_button').click(function(){
					
		$.fancybox.showActivity();			
					
		isactive = $(this).attr('active');
		
		console_log('485: '+isactive);
		
		href = $('input#user_type_html').val();
		
		var addr = $('input#zip_input').val();
		
		var addr_array = getCityStateZip(addr);
		
		zipis = addr_array.zip;
		
		if(zipis == ''){
			
				//alert(addr_array.state);
			
				$.ajax({
						type: "POST",
						url: '/assets/ajax/fill_in_zip.php',
						data: "city="+addr_array.city+"&state="+addr_array.state,
						success: function(msg){
													
							//alert(msg);
							zipis = msg;
							check_zip_code();
						} // success
						
				}); //ajax
			
			
		}
		
		else {
		
			check_zip_code();
		
		}
		
		//var zipis = $('input#zip_input').val();
		
		//alert(zipis);
		
	});
	
	
	
	
		function check_zip_code(){	
		
			console_log('requireszip: '+requireszip);
			console_log('zipis: '+zipis);
		
			if(requireszip){
				
				var isthisvalidzip = isValidZipCode(zipis);
				//alert(isthisvalidzip);
				
				if(!isthisvalidzip) {
					valid = false;
					//alert('Please enter a valid zip code.');
					alert('Please enter a valid zip code or city and state (example: City, ST)');
					$.fancybox.hideActivity();
				}
				else {
					valid = true;
				}
				
			} // if
		
			//check_zip_code();
			console_log('valid: '+valid);
			console_log('isactive: '+isactive);
			console_log('href: '+href);
		
			if(valid && isactive == 'true'){
				
				/*	*/		
				$.ajax({
					type: "POST",
					url: "/assets/scripts/set_zipcode_session.php",
					data: "z="+zipis+"&href="+href,
					success: function(msg){
						//alert(msg);
						window.location	= href;
					}
				}); //ajax
				
			} // if
		
		} // check_zip_code
	
	
	
	// LOCATION SIDE BAR
	
	$('div#column_left input#zip_input').live('click',function(){
		
		$(this).focus();
		
		init_autocomplete();
		
		var zip_input_tip = $('div#zip_input_tip3').length;
		
		if(!zip_input_tip){
		
			$('body').append('<div id="zip_input_tip3"><p>Enter your zip code<br />or city & state (EX: City, ST).</p></div>');
			//$('body').append('<div id="zip_input_tip3"><p>Enter your zip code.</p></div>');
			
		}
		
		var pos = $("input#zip_input").position();
		
		$('div#zip_input_tip3').animate({top:pos.top-70}, 1000);
		
		var thiszipis = $(this).val();
		
		if(thiszipis == "Enter Your Location"){
			$(this).val('');	
		}
		
		
	});
	
	$('a#change_location').live('click',function(){
					
		$('div#wrap_side_map').slideUp('fast');
		$('div#wrap_side_enter_zip').slideDown('fast');
		$('input#zip_input').val("Enter Your Location");
		return false;
		
	});



/* LEFT COLUMN - CHANGE MY ZIPCODE */
	$('form#capture_zip_code').live('submit',function(){
		
		$.fancybox.showActivity();
		
		valid    = '1';
		isactive = 'true';
		requireszip = true;
		
		var addr = $('input#zip_input').val();
		
		console_log('form#capture_zip_code');
		console_log('addr: '+addr);
				
		var addr_array = getCityStateZip(addr);
		
		zipis = addr_array.zip;
		
		console_log('zipis: '+zipis);
				
				
		href = window.location.pathname;
		
				
		if(zipis == ''){
			
				//alert(addr_array.state);
			
				$.ajax({
						type: "POST",
						url: '/assets/ajax/fill_in_zip.php',
						data: "city="+addr_array.city+"&state="+addr_array.state,
						success: function(msg){
													
							//alert(msg);
							zipis = msg;
							check_zip_code();
						} // success
						
				}); //ajax
			
			
		}
		
		else {
		
			check_zip_code();
		
		}

		
		//var zipis = $('input#zip_input').val();
/*		
		
		var addr_arrary = getCityStateZip(addr);
		
		zipis = addr_arrary.zip;
			
		
				
		href = window.location.pathname;
		
		//alert(href);
		
		
		
		
		var valid = isValidZipCode(zipis)
				
		if(!valid){
			alert('Please enter a valid zip code.');	
		}

	
		else {
			
			//var href = window.location.href;
			
			$.ajax({
				type: "POST",
				url: "/assets/scripts/set_zipcode_session.php",
				data: "z="+zipis+'&href='+href,
				success: function(msg){
					//alert(msg);
					window.location	= href;
				}
			}); //ajax
			
		}
*/
		return false;
	});
	
	
	//$("a.youtube").click(playVid);
	
	$("a.youtube").each(function($i){
								 
		var url =$(this).attr('href'); //alert(url);
			
		$(this).parent().parent().find('a.right_column_img').click(function(){
					  
			open_vid(url);	
			return false;
			
		}).removeClass('fancybox'); //click
		
		
		$(this).click(function(){
					  
			open_vid(url);	
			return false;
			
		}); //click
		
	});

	function open_vid(url) {
			var vidId = url.split('v=')[1].split('&')[0];
			var vidSrc = "http://www.youtube.com/v/" + vidId + "&hl=en&fs=1&autoplay=1&rel=0";
			$.fancybox(
			'<object width="480" height="355"><param name="movie" value="'+vidSrc+'" bgcolor="#000000"></param><param name="allowFullScreen" value="true"></param><param name="bgcolor" value="#000000"><param name="allowscriptaccess" value="always"></param><embed src="'+vidSrc+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="355"></embed></object>',
			{
				'autoDimensions'	: false,
				'width'         		: 480,
				'height'        		: 355,
				'padding'        		: 10,
				'margin'        		: 0,
				'scrolling'        		: 'no',
				'transitionIn'		    : 'none',
				'showCloseButton'		: true,
				'transitionOut'		    : 'none'
			});
		
	}	
		
	
	
	$("a.more").each(function(i){
	
		$(this).parent().siblings('p').hide();
		var h2 = $(this).parent().parent().find('h2').html();
		var more_img = $(this).parent().parent().find('a.right_column_img').find('img').attr('rel');
		//alert(more_img);
		more_img = more_img.replace('"', "");
		more_img = more_img.replace('"', "");
		//alert(more_img);
		var content = '<div class="wrap_more"><h2>'+h2+'</h2>';
		content += '<div class="more_img shadow"><img src="'+more_img+'" /></div>';
		
		$(this).parent().siblings('p').each(function(v){
			content += '<p>' + $(this).html() + '</p>';					 
		});
		
		content += '</div>';
		
		//alert(content);
		
		$(this).click(function(){
							   
			//alert(content);
			//var sibs = '';
			//$(this).parent().siblings().show('slow');				
			//alert(sibs); 
			$.fancybox(
			content,
			{
				'autoDimensions'	: false,
				'width'         		: 580,
				'height'        		: 'auto',
				'padding'        		: 40,
				'margin'        		: 0,
				'scrolling'        		: 'auto',
				'showCloseButton'		: true,
				'transitionIn'		    : 'none',
				'transitionOut'		    : 'none'
			});
			return false;
		});
	});
	
	
	
	
	
	
	
	
	
	$("a.manage").fancybox({
			'autoDimensions': false,
			'showCloseButton': true,
			'width': 630,
			'height': 500,
			'margin': 10,
			'padding': 25,
			'titleShow': false,
			'onComplete': function(){ 
				init_form();
			}

	});
	
	$("a.fancybox").fancybox({
			'autoDimensions': true,
			'showCloseButton': true,
			'width': 400,
			'titleShow': false
	});

	
	$("a.map_lightbox").fancybox({
			//'autoDimensions': true,
			'width': 700,
			'showCloseButton': true,
			'titleShow': false,
			'onComplete': function(){ 
				start_focus();
			}
	});
	/* */


	function start_focus() {
		
				$('input#start').focus(function(){
					//alert('hi');
					var val = $(this).val();
					if(val == 'Start Location:') {
						$(this).val('');
					}
				});
				$('input#start').blur(function(){
					//alert('hi');
					var val = $(this).val();
					if(val == '') {
						$(this).val('Start Location:');
					}
				});
				
				$('form#get_directions_form').submit(function(){
					var startvalue = $(this).find('input#start').val();
					if(startvalue == '' || startvalue == 'Start Location:') {
						alert('Please provide a Starting Location.');
						return false;
					}
				});
				
				$('form#get_directions_form2').submit(function(){
					var startvalue = $(this).find('input#start').val();
					if(startvalue == '' || startvalue == 'Start Location:') {
						alert('Please provide a Starting Location.');
						return false;
					}
				});
	}

	start_focus();
	//$("a.map_lightbox").fancybox();

	$('a#other_locations').live('click',function(){
										  
		//alert('hello');
		$('ul#other_locations_nearby').toggle('slow');
		return false;
										  
	});
	
	//$('div.wrap_entry_copy').hide();
	
	$('div.wrap_entry_expand').each(function(index) {
    	//alert(index + ': ' + $(this).text());
		if(index){
			$(this).find('div.wrap_entry_copy').hide();
		}
		else {
			$(this).find('h2').addClass('arrow_down');
		}
  	});

	$('div.wrap_entry_expand h2').click(function(){
		$(this).toggleClass('arrow_down');
		$(this).parent().find('div.wrap_entry_copy').slideToggle();
		$(this).parent().siblings('.wrap_entry_expand').find('div.wrap_entry_copy').slideUp();
	    $(this).parent().siblings('.wrap_entry_expand').find('h2').removeClass('arrow_down');
	});
	
	
	
	
	
	/* ON SUBMIT FOR HOME */
	

	
	$('form#user_type').submit(function() {
		//alert(requireszip);
		
		$.fancybox.showActivity();
		
		isactive = $('div#go_button').attr('active');
				
		if(requireszip){
			
			var addr = $('input#zip_input').val();
			
			var addr_array = getCityStateZip(addr);
			
			zipis = addr_array.zip;
			
			console_log(addr);
			console_log(addr_array.city);
			console_log(addr_array.state);
	
			if(zipis == ''){
				
					//alert(addr_array.state);
				
					$.ajax({
							type: "POST",
							url: '/assets/ajax/fill_in_zip.php',
							data: "city="+addr_array.city+"&state="+addr_array.state,
							success: function(msg){
														
								//alert(msg);
								zipis = msg;
								console_log('zipis: '+zipis);
								check_zip_code();
							} // success
							
					}); //ajax
				
				
			}
			
			else {
								
				console_log('zipis: '+zipis);
				check_zip_code();
			
			}
	
			//console_log(zipis);

/*
	
			//var zidcodeis = $('input#zip_input').val();
			
			
			var isvalid = isValidZipCode(zipis);
			
			//alert(isvalid);
			
			if(isvalid) {
				
			}
			
			else {
			
				alert('Please enter a valid zipcode.');
				return false;
				
			}
			
*/
			
		}
		//var needs_zip = alt
		else {
		
		}
		
		return false;
	});
	
	
	
	$("a.gallery_image").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'showCloseButton' : true
		//'overlayShow'	:	false
	});



	/* VALIDATE FORM */
	var valid_form = true;
	var error_msg = '';
	
	function init_form() {
	
		$("form").each(function($i){
			$(this).submit(function(){
							
					valid_form = true;
					error_msg = '';
					
					$(this).find(".required").each(function($i){
						var this_val = $(this).val();
						if(this_val == ''){
							valid_form = false;
							error_msg = 'Please fill in all the required fields.';
							$(this).css('border','1px solid red');
							$(this).parent().parent().find('label.description').css('color','red');
						}
						else {
							$(this).css('border-color','#7C7C7C #C3C3C3 #DDDDDD');
							$(this).parent().parent().find('label.description').css('color','#0094DA');
							//valid_form = true;
						}
					});
					
					$(this).find(".required_email").each(function($i){
						var this_val = $(this).val();
						if(this_val == ''){
							valid_form = false;
							error_msg = 'Please fill in all the required fields.';
							$(this).css('border','1px solid red');
							$(this).parent().parent().find('label.description').css('color','red');
						}
						else {
							$(this).css('border-color','#7C7C7C #C3C3C3 #DDDDDD');
							$(this).parent().parent().find('label.description').css('color','#0094DA');
						}
						var isemailvalid = isEmail(this_val);
						//alert(isemailvalid);
						if(!isemailvalid){
							valid_form = false;
							error_msg = "\n\r"+'Please enter a valid email address.';
							$(this).css('border','1px solid red');
							$(this).parent().parent().find('label.description').css('color','red');
						}
					});
					
					if(!valid_form) {
						
						alert(error_msg);
						return false;
					
					}
												  
			});
			
		});

	}
	
	init_form(); 


	$('form#remove_me_form #first_name').focus(function(){
														
		$('span#hide_left_form').show('slow');							
	});
	
	
	
	
	var move_form = $('div#form_here').length;
	
	if(move_form){
		
		$('div#form_container').remove().clone().appendTo('div#form_here');
		init_form(); 
		
	} // if move_form
	
	
	
	
	
	
	
	
	// BOTTOM SLIDER
	var slider_width  = 960;
	var slide_count   = 0;
	var total_sliders = $('ul#slider_ul li').size();
	var new_height = $('ul#slider_ul li:eq(0)').height();
	animate_slider();
	//alert(total_sliders);
	
	//$('ul#slider_ul li').hide();
	//$('ul#slider_ul li:eq(0)').slideDown();
		
	$('div#bottom_sliders #left').click(function(){
	
		slide_count--;
		if(slide_count < 0){
			slide_count = total_sliders - 1;
		}
		animate_slider();
	});
	
	$('div#bottom_sliders #right').click(function(){
	
		slide_count++;
		if(slide_count >= total_sliders){
			slide_count = 0;
		}
		animate_slider();
	});
	
	
	function animate_slider() {
	
		var slide_by = -1 * (slide_count * slider_width);
		
		//$('ul#slider_ul li:eq('+slide_count+')').siblings().slideUp();
		//$('ul#slider_ul li:eq('+(slide_count+1)+')').slideDown();

		
		$('ul#slider_ul').animate({
			left: slide_by
			}, 1000, function() {
			
			// Animation complete.
			//alert(new_height);
			
		});
			
		new_height = $('ul#slider_ul li:eq('+(slide_count)+')').height();
		
		$('div#bottom_sliders').animate({
		
			height: new_height
			
		}, 500);


	}
	
	
	
	
	
	/* AUTHORIZATION FORM */
	
	$('form#authorization_form').submit(function(){
	
		$.fancybox.showActivity();
		
		var form_values = $(this).serialize();
		
		//console_log(form_values);
		
		$.ajax({
				type: "POST",
				url: '/assets/ajax/process_authorization_form.php',
				data: form_values,
				success: function(msg){
											
					$('div#warp_auth form#authorization_form').replaceWith(msg);
					$.fancybox.hideActivity();

				} // success
				
		}); //ajax
		
	
		return false;
	
	}); // authorization_form








	/* AUTHORIZATION CODE FORM */

	$('form#authorization_code_form').submit(function(){
	
		$.fancybox.showActivity();
		
		var form_values = $(this).serialize();
		
		$.ajax({
				type: "POST",
				url: '/assets/ajax/process_authorization_code_form.php',
				data: form_values,
				success: function(msg){
											
					$('div#warp_auth').html((msg));
					$.fancybox.hideActivity();
					
				} // success
				
		}); //ajax
		
	
		return false;
	
	}); // authorization_code_form
	
	
	
	
	
	
	
	
	
	
	
	
	// see if #load_kool_locations exist
	
	var load_kool_locations_exist = $('div#load_kool_locations').length;
	
	//console.log(load_kool_locations_exist);
	
	if(load_kool_locations_exist) {
	
					$.ajax({
							type: "POST",
							url: '/assets/ajax/ajax_template_locations.php',
							data: "entry_id=",
							success: function(msg){
														
								//console.log(msg);
								$('div#load_kool_locations').html(msg);
								
									$("a.map_lightbox").fancybox({
											//'autoDimensions': true,
											'width': 700,
											'showCloseButton': true,
											'titleShow': false,
											'onComplete': function(){ 
												start_focus();
											}
									});

								
							} // success
							
					}); //ajax
		
	
	}
	
	
	
	
	
	// ==================== FLOATING BLUE NAV ==================== //
	
	$('div#floating_blue_nav').hide();
	
	$('ul.floating_blue_nav_boxes').each(function(i){
	
		var this_height = $(this).height();
		console.log(this_height);
		
	});
	
	$(window).scroll(function() {
	
		//alert('scroll');
	
		var opacityy = 0;
		
		scroll_top = $(window).scrollTop();

		if(scroll_top > 180){
			$('div#floating_blue_nav').stop().show(); //.css({'opacity':'.9'});
			//alert('...');
		}
		
		else {
			$('div#floating_blue_nav').stop().hide(); //.css({'opacity':'.0'});
		}

		//$('#back_to_press_releases').html(scroll_top);
		
		//opacityy = (scroll_top -180)*(0.15);
		
		//if(opacityy > 5){ opacityy = 9; }
		//else { opacityy = 0; }
		
		//$('div#floating_blue_nav').stop().fadeTo(500, '.'+opacityy);
	
	});	
	
	
	var count_floating_blue_nav_lis = $('div#floating_blue_nav .floating_blue_nav_boxes li').length;
	var current_floating_blue_nav_li = 0;
	
	$('div#floating_blue_nav a.left_arrow').fadeTo(500, '.25');
	
	// move dom elements
	$('div#floating_blue_nav .floating_blue_nav_boxes li').each(function(i){
	
		$(this).click(function(){
		
			var link = $(this).find('.subtitle a').attr('href');
			//alert(link);
			window.location.href = link;

		});
		
	
	});
	
	function animate_floating_blue_nav() {
	
		var floating_blue_nav_li_width = $('div#floating_blue_nav .floating_blue_nav_boxes li').outerWidth(true);
		var leftt = (floating_blue_nav_li_width * current_floating_blue_nav_li) * -1;
	
		//alert(floating_blue_nav_li_width);
		$('div#floating_blue_nav ul.floating_blue_nav_boxes').animate({'left':leftt}, 1000);
	
	}
	
	//alert(count_floating_blue_nav_lis);
	
	$('div#floating_blue_nav a.left_arrow').click(function(){
	
		current_floating_blue_nav_li--;
			
		$('div#floating_blue_nav a.right_arrow').fadeTo(500, '1.0');
		
		if(current_floating_blue_nav_li <= 0){
			current_floating_blue_nav_li = 0;
			$('div#floating_blue_nav a.left_arrow').fadeTo(500, '.25');
		}
		else{
			//$('div#floating_blue_nav a.left_arrow').show();
		}
		
		animate_floating_blue_nav();
	
		return false;
	
	});
	
	$('div#floating_blue_nav a.right_arrow').click(function(){
	
		current_floating_blue_nav_li++;
		
		$('div#floating_blue_nav a.left_arrow').fadeTo(500, '1.0');
		
		if(current_floating_blue_nav_li >= (count_floating_blue_nav_lis-3) ){
			current_floating_blue_nav_li = count_floating_blue_nav_lis-3;
			$('div#floating_blue_nav a.right_arrow').fadeTo(500, '.25');
		}
		else{
		
		}
		
		animate_floating_blue_nav();
	
		return false;
	
	});
	
	
	

});
