/**
 * Client Information
 *
 * Echo 
 * http://www.echoclinics.org
 * designed by Switch Creative Group
 * http://www.groupswitch.com
*/

$(document).ready(function(){
	
	
	/* Current Clinics sorting by state */
	/* ------------------------------------------------- */
	var seen = {};
	$('option').each(function() {
	    var txt = $(this).text();
	    if (seen[txt])
	        $(this).remove();
	    else
	        seen[txt] = true;
	});
	
	var options = $('#sort_states option');
	var vals = [];
	
	for ( i=0; i < options.length; i++) {
	    vals.push(options[i].innerHTML);
	}
	
	vals.sort();
	
	for ( i=0; i < options.length; i++) {
	    options[i].innerHTML = vals[i];   
	}
	
	// $('#sort_states').prepend('<option selected="selected">Sort By State:</option>');

	
	
	/* Forms - drop_down -> selection menu */
	/* ------------------------------------------------- */
	// <input type="checkbox" name="question_3[]" id="question_3_breakfast" value="Breakfast" />
	
	$('.form .checkbox').each(function(){
	
		var name 		= $(this).attr('id');
		var cbs 		= $(this).find('li');
		var cbs_text= [];
		
		for (i=0; i<cbs.length; i++) {
			
			cbs_text[i] = cbs[i].innerHTML;
			
			var 
			div		 = '<div class="checks check'+i+'">';
			div		+= '<input type="checkbox" name="'+name+'[]" id="check'+i+'" value="'+cbs_text[i]+'" /> ';
			div		+= '<label for="check'+i+'">'+cbs_text[i]+'</label>';
			div		+= '</div>';
			
			if (i==0) {
				$(this).find('ul').after(div);
			} else {
				$(this).find('.check'+(i-1)).after(div);
			}
			
		}
		
		$(this).find('ul').remove();
		
	});
	
	
	
	/* Forms - drop_down -> selection menu */
	/* ------------------------------------------------- */
	$('.form .drop_down li').each(function(){
		var text = $(this).text();
		var option = '<option value="'+text+'">'+text+'</option>';
		$(this).parent().next().append(option);
	});
	
	$('.form .drop_down ul').remove();

	
	
	/* add highlight to Stories */
	/* ------------------------------------------------- */
	var pathname = window.location.pathname;
	var str="stories";
	if (pathname.search("stories")!=-1) {
		$('.level_1:eq(5)').addClass('here');	
	} else if (pathname.search("current_clinics")!=-1) {
		$('.level_1:eq(4)').addClass('here');
	}
		
		
		
	/* FAQ last | remove border */
	/* ------------------------------------------------- */
	if ($('#faq_nav').length > 0 ) {
		$('.faq').last().addClass('no_border');
		}
	
	
	/* Google Maps Fancybox */
	/* ------------------------------------------------- */
	$("#clinic_bu").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'overlayColor'		: '#001f34',
				'height'					: 450,
				'width'						: 600
			});



	/* Home Slider */
	/* ------------------------------------------------- */
	if ($('#home_slider').length > 0 ) {
		
		$('#home_slider').anythingSlider({
													width: 680,
													height: 380,
													autoPlay: true,
													delay: 5000,
													startPanel: 1,
													onBeforeInitialize: function(slider){
  													$('#home_gallery').css({ 'visibility':'visible', 'opacity':0 }).animate({'opacity':1}, 'slow');
 														}
													});
	
		}
	
													
													
													
	/* Input Remember */
	/* ------------------------------------------------- */
	$('input[type=text], textarea').each(function(){
	
		var val = $(this).attr('value');
		
		$(this)
			.bind('click',function(){
				$(this).val('');
			})
			.bind('blur',function(){
				var a = $(this);
				if(a.val() == ''){
					a.val(val);
				}
		});
		
	});

});
