$(function() {
		$("#datepicker").datepicker();
		$("#format").change(function() { $('#datepicker').datepicker('option', {dateFormat: $(this).val()}); });
});


$(function() {	
		$('#img_rotator').cycle({
		delay:  5000,
		speed:  1000
		});
})

function appt_step1() {
		$('ul#appt_nav li').removeClass('active');		
		$('ul#appt_nav li').eq(0).addClass('active');
};	
function appt_step2() {
		$('ul#appt_nav li').removeClass('active');			
		$('ul#appt_nav li').eq(1).addClass('active');
};	

function appt_step3() {
		$('ul#appt_nav li').removeClass('active');			
		$('ul#appt_nav li').eq(2).addClass('active');
};	

function appt_step4() {
		$('ul#appt_nav li').removeClass('active');
		$('ul#appt_nav li').eq(3).addClass('active');
};	

function makeAppt() {
		$('ul#appt_slide').animate({marginLeft:'-880px'}, 900);
		$('a#make_appt').animate({opacity:'0'},900,function(){
			$('a#make_appt').hide();
		});
		$('ul#appt_nav').show(100);
		appt_step1();
		return false;
};

//======================================COOKIE FUNCTIONS

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};


function eraseCookie(name) {
	createCookie(name,"",-1);
};

function increaseFontSizePopup(){
		$('#office_out p, #surgery_out p').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
		$('#office_out a, #surgery_out a').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
		$('#office_out label, #surgery_out label').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
};

function increaseFontSize(){
		$('p').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
		$('a').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
		$('label').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize + 2 );
		});
};
function decreaseFontSize(){
		$('p').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize - 2 );
		});
		$('a').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize - 2 );
		});
		$('label').each(function(){
			fontSize = parseInt($(this).css('font-size'));
			$(this).css('font-size', fontSize - 2 );
		});
		
};

function fontSizeButtonColor(){
	if (fontInterval = 0){
			$('a.textsize_smaller').css('background', '#acacac');
	}
	
	if (fontInterval = 3){
			$('a.textsize_larger').css('background', '#acacac');
	}
	
	else {
	$('a.textsize_larger').css('background', '#5192CE');
	}
};


$(document).ready(function(){


//======================================CHANGE FONT SIZE/ SET COOKIE VALUE


	$('a.textsize_larger').live('click', function(){
		if (fontInterval < 2)
		{
			increaseFontSize();
			fontInterval++;
			createCookie('text_cookie',fontInterval,0)
		}	

	});
	
	$('a.textsize_smaller').live('click', function(){
		if (fontInterval > 0)
		{	
			decreaseFontSize();
			fontInterval--;
			createCookie('text_cookie',fontInterval,0)
			
		}
		
	});
	
	$('a.textsize_lrg').live('click', function(){
		$('p').removeClass('med');
		$('p').addClass('lrg');	
		//$('p').css('font-size','120%');
		//$('#container').css('height','auto');
		$('#text_control a').removeClass('active');
		$(this).addClass('active');
		//createCookie('text_cookie','lrg',0)
	});

//======================================CHANGE FONT SIZE/ SET COOKIE VALUE
	
var text_size = readCookie('text_cookie');
fontInterval = text_size;

if (text_size == null){
createCookie('text_cookie',0,0);
}

function applyCookies(){
	for( i=1; i <= text_size; i++){
		increaseFontSize();
	}
};

function applyCookiesPopup(){
	for( i=1; i <= text_size; i++){
		increaseFontSizePopup();
	}
};

applyCookies();


/*if (text_size == 'norm') {
	$('p').css('font-size','100%');
	$('a.textsize_norm').addClass('active');
	
};

if (text_size == 'med') {
	$('p').css('font-size','110%');
	$('a.textsize_med').addClass('active');
};

if (text_size == 'lrg') {
	$('p').css('font-size','120%');
	$('a.textsize_lrg').addClass('active');
};*/

	
//======================================MAKE AN APPOINTMENT
	$('#q_optional').css('opacity', 0);
	$('li#forms1').css('opacity', 0);
	$('ul#appt_slide2').css('opacity', 0);
	$('ul#appt_nav').hide();
	$('#insured_under_container').hide();  
	
	$('input[type=text].clear').focus(function(){
		value = $(this).attr('value');
		number = $('input[type=text].clear').index(this);
		label = $('label.clear').eq(number);
		labelValue = $(label).html();
		label.show(200);
		if ( value == labelValue) {
			$(this).attr('value', '');
		}		
	});
	
	$('input[type=text].clear').blur(function(){
		$('label.clear').hide(200);
	});
	
	

	$('a#make_appt').click(function (){
	makeAppt();
	});
	
	$('a#continue_1').click(function(){
		$('ul#appt_slide').animate({opacity:'0'}, 200,function(){
			$('ul#appt_slide').hide();
			$('#q_optional').animate({opacity:'1'}, 200);			
			return false;
			
		});
		appt_step2();

		/*$('input.required').each(function(){
		value = $(this).attr('value');
		if ($(this).attr('value') == value){
		$(this).css('border', '2px solid red');
		}
		});
		return false;*/
	});
	
	$('a#no_returning').click(function(){
		$('li#q_returning').animate({opacity:'0'}, 200,function(){
			$('li#q_returning').hide();
			$('li#forms1').animate({opacity:'1'}, 200);			
			return false;			
		});
		$('#radio_no_return').attr('checked', true);
		
	});
	
	$('a#yes_returning').click(function(){
		$('li#q_returning').animate({opacity:'0'}, 200,function(){
			$('li#q_returning').hide();
			$('li#forms1').animate({opacity:'1'}, 200);			
			return false;			
		});
		$('#radio_yes_return').attr('checked', true);
		$('#q_optional p').html('If your insurance has changed since your last visit you can <br />make changes now to save time when you come in for your appointment. <br /> Would you like to update your insurance information?');
	});
	
	$('a#no_insur').click(function(){
	});
	
	$('a#yes_opt').click(function(){
		$('#q_optional').animate({opacity:'0'}, 200,function(){
			$('#q_optional').hide();
			$('ul#appt_slide2').animate({opacity:'1'}, 200);		
			return false;
		});
	});
	
	$('li#insurance a.continue_2,  li#insurance a.skip_2').click(function(){
		$('ul#appt_slide2').animate({marginLeft:'-890px'}, 800);
		return false;
	});

	$('#others_plan').click(function(){	
		if ($(this).is(':checked')) { 
		$('#insured_under_container').show() 
		$('ul.dropdown_values').hide();	
		} 
		else {
		$('#insured_under_container').hide() 
		}
		

	});
	
	$('a#yes_insur, a#no_opt, #med_conditions a.skip_2, #med_conditions a.continue_2').click(function(){
		var dataString=$('#appointmentForm').serialize();
		//alert("POSTING: "+dataString);
		$.ajax({
			type: $('#appointmentForm').attr("method"),
			url: $('#appointmentForm').attr("action"),
			data: dataString,
			success: function() {
				$('#appointment').load('includes/confirmation.asp'+'?'+dataString);
				appt_step3();

			}
		});
		return false;	
	});
	
	//$('a#yes_insur, a#no_opt, #med_conditions a.skip_2, #med_conditions a.continue_2').click(function(){
		//$('#appointment').load('includes/confirmation.asp');
		//appt_step4();			
	//});
	
	
	$('ul.conditions li input').hide();
	$('ul.conditions .dropdown').hide();
	
	$('ul.conditions li a').click(function(){
		$('ul.dropdown_values').hide();
		$(this).hide();
		$(this).parent().find('input.clear').show().focus();
		$(this).parent().find('.dropdown').show();
	});
	
	$('ul.conditions li input.clear').blur(function(){
		value = $(this).val();
		//alert(value);
		if (value == ''){
		$(this).hide();
		$(this).parent().find('a').show();
		}
		else{};
	});

//======================================DROPDOWN REAL
	$('ul.dropdown_values').hide();
	$('.dropdown_holder').click(function(){	
		$('.dropdown_holder').removeClass('open');
		pos = $(this).offset();
		height = $(this).height() + 10;	
		$('ul.dropdown_values').hide();
		$(this).addClass('open');
		values = '<ul class="dropdown_values">' + $(this).parent().find('ul.dropdown_values').html() + '</ul>';
		$('#dropdown_outer_holder').html(values);
		$('#dropdown_outer_holder').css({"left": pos.left + "px", "top": (pos.top + height)+ "px"});
		//$(values).show();
		return false;		
	});
	
		
	$('#dropdown_outer_holder ul.dropdown_values li a').live('click',function(){
		value = $(this).attr('title');
		//alert(value);
		$('#welcome').find('.open').html(value);
		$('#welcome').find('.open').parent().find('input').attr('value',value);
		$('.dropdown_holder').removeClass('open');
		$(this).parent().parent().hide();
		$(this).parent().parent().parent().find('ul.dropdown_values li a').removeClass('active');
		$(this).addClass('active');
		//hiddenForm = $(this).parent().parent().parent().find('input');
		//$(hiddenForm).attr('value', value);
	});

//======================================DROPDOWN2 REAL
	$('ul.dropdown2_values').hide();
	
	$('.dropdown2_holder').click(function(){		
		$('ul.dropdown2_values').hide();
		values = $(this).parent().find('ul.dropdown2_values');
		$(values).show();
		//alert('yo');		
		return false;
	});
			

	$('ul.dropdown2_values li a').click(function(){
		value = $(this).attr('title');
		$(this).parent().parent().parent().find('.dropdown2_holder').html($(this).html());
		$(this).parent().parent().hide();
		$(this).parent().parent().parent().find('ul.dropdown2_values li a').removeClass('active');
		$(this).addClass('active');
		hiddenForm = $(this).parent().parent().parent().find('input');
		$(hiddenForm).attr('value', value);
		link = $(this).attr('title');
		$(this).parent().parent().parent().parent().find('a.go').attr('href', link);
		return false;
	});
	
	$(document).click(function() {
		$('ul.dropdown_values, ul.dropdown2_values').hide();
		$('.dropdown_holder').removeClass('open');
		$('.dropdown_holder').removeClass('open');
	});


	
//======================================PRIVACY SCROLL
	$('.privacy a.scroll_right').toggle(function(){
		$('#scroll_container').animate({marginLeft:'-890px'}, 1000);
		return false;
	},function(){
		$('#scroll_container').animate({marginLeft:'-1760px'}, 1000);
		scrollImage = $(this).find('img');
		$(scrollImage).attr('src','assets/images/scroll_left.gif');
		$(this).addClass('scroll_left');
		return false;
	},function(){
		$('#scroll_container').animate({marginLeft:'0px'}, 1000);
		scrollImage = $(this).find('img');
		$(scrollImage).attr('src','assets/images/scroll_right.gif');
		$(this).addClass('scroll_right');
		return false;
	});

//======================================ABOUT SCROLL
	$('.pre_post_op a.scroll_right').toggle(function(){
		$('#scroll_container').animate({marginLeft:'-880px'}, 1000);
		scrollImage = $(this).find('img');
		$(scrollImage).attr('src','assets/images/scroll_left.gif');
		$(this).addClass('scroll_left');
		return false;
	},function(){
		$('#scroll_container').animate({marginLeft:'0px'}, 1000);
		scrollImage = $(this).find('img');
		$(scrollImage).attr('src','assets/images/scroll_right.gif');
		$(this).addClass('scroll_right');
		return false;
	});

	
//======================================DROPDOWN 1	
	$('#dropdown').mouseenter(function(){
		$('ul#locations').show();
	}).mouseleave(function(){
		$('ul#locations').hide();		
	});
		

//======================================FIND DOCTORS 
	
	$('.home .doctors_thumbs').hide();
	$('.doctor_info').hide();	
	$('#doctor_info_holder').hide();
	
	$('.find_doctor ul li a').click(function(){
		doctorsDiv = $(this).parent().find('.doctors_thumbs');
		$('.doctors_thumbs').hide();
		$('.find_doctor ul li a').removeClass('active');			
		$(this).addClass('active');		
		$(doctorsDiv).slideDown(200);

	});
	$('.close').click(function(){
		$(doctorsDiv).hide();		
		$('#doctor_info_holder').hide();		
	});
	
	$('.doctors_thumbs ul li a img').mouseenter(function(){
		doctorInfo = $(this).parent().parent().find('.doctor_info').html();
		//alert(doctorInfo);
		var pos= $(this).offset();
		var height = $(this).height() + 8;
 		$('#doctor_info_holder').html(doctorInfo);
		$("#doctor_info_holder").css( { "left": pos.left + "px", "top": (pos.top + height) + "px" } );
		$('#doctor_info_holder').show();
	}).mouseleave(function(){
		$(this).parent().parent().find('.doctor_info').hide();	
		$('#doctor_info_holder').hide();		
		
	});
	
//====================================Doc Thumb Opacity/Hover
	var pathname = window.location;	
	docUrlSplit = $(pathname).attr('href').split('=');

	docName = docUrlSplit[1];
	$('.doctors .doctors_thumbs ul li').find('.'+docName).css('cssText', 'opacity:1 !important;');
	$('.doctors .doctors_thumbs ul li a img').mouseenter(function(){
		$(this).parent().parent().find('.doctor_info').show();
		$(this).css('opacity', '1');		
	}).mouseleave(function(){
		$(this).css('opacity', '.6');	
		$('#doctor_info_holder').hide();				
	});
	
//=============================================================Locations/Surgeries Hover
	$('.all_locations .box3_outer a.moreinfo, .surgeries .box3_outer a.moreinfo').mouseenter(function(){
		$(this).parent().parent().css('background-color', '#90b438');
	}).mouseleave(function(){
		$(this).parent().parent().css('background-color', '#a9adae');
	});


//=============================================================Office Popups

	$('#office_out').hide();
	
//============================Checks for #officeName in url on load	
	theAnchor=document.location.hash.substring(1);
	if (theAnchor == ""){
	}
	else {
		$('#office_out').load("includes/office.asp?office=" + theAnchor);
		$('#office_out').show();
		setTimeout(function() {
			applyCookiesPopup();
		}, 20); 
	};	

//============================Changes locations dropdown href's to #officeName	
	$("ul#locations li a").each(function(){
		urlSplit = $(this).attr('href').split('=');
		officeName = urlSplit[1];
		$(this).attr("href", "all_locations.asp#" + officeName);
	});
	
//============================Changes "more info" href's to #officeName	
	$(".all_locations .box3_inner a").each(function(){
		urlSplit = $(this).attr('href').split('=');
		officeName = urlSplit[1];
		$(this).attr("href", "#" + officeName);
	});

//============================Pops up office info when clicking "more info"		
	$('.all_locations .box3_inner a').live('click',function(){		
		officeName = $(this).attr("href").substring(1);
		$('#office_out').load('includes/office.asp?office=' + officeName);
		$('#office_out').show();		
		text_size = fontInterval;
		
		setTimeout(function() {
			applyCookiesPopup();
		}, 20); 


	});
	
	$('ul#locations a').live('click',function(){		
		officeName = $(this).attr("href").substring(18);
		$('#office_out').load('includes/office.asp?office=' + officeName);
		$('#office_out').show();	
	
		$(this).parent().parent().hide();
		setTimeout(function() {
			applyCookiesPopup();
		}, 20); 
	});
	
	$('.all_locations .box3_inner a').mouseenter(function(){	
		$(this).parent().parent().parent().css('background', '#8FB438');
	}).mouseleave(function(){
		$('.all_locations .box3_outer').css('background', '#a9adae');	
	});
	
	
	
//============================Pops up SURGERY info when clicking "more info"		
	$('#surgery_out').hide();
	surgUrlSplit = $(pathname).attr('href').split('#');
	if(surgUrlSplit[1]!=null){ //if there's something after #
		surgUrlSplit2 = surgUrlSplit[1].split('-');
		surgName = surgUrlSplit2[0];
		surgSectName = surgUrlSplit2[1];
		//alert(surgName);
		if(surgName!= ""){	//if there's a surgery name
			loadsurgery(surgName);
			if(surgSectName!=null){ //if there's a question name
				setTimeout(function(){loadquestion(surgSectName);}, 500);

			}
		}
		
	}
/*
	if (surgName != ""){
		loadsurgery(surgName);
		}
		
	if (surgSectName != ""){		
		sectionID = "." + surgSectName;
		$(sectionID).show();
		}
	*/
	/*$('.surgeries .box3_inner a').click(function(){		
		procedure = $(this).attr("href").substring(1);
		$('#surgery_out').load('includes/surgery.asp?surgery=' + procedure);
		$('#surgery_out').show();
		alert('yo');		
	});
	*/
	
	$('a.close').live("click",function(){
		$('#surgery_out').hide();
	});
	
	$("a.moreinfo").click(function(){
		loadsurgery($(this).attr("href").substring(1) );
		setTimeout(function() {
			applyCookiesPopup();
		}, 20); 

		
	});
	
	$(".links a").live("click",function(){
		ques=$(this).attr("href").substring(1).split("-");
		loadquestion(ques[1]);
	});

	function loadsurgery(surgName){
		$('#surgery_out').load('includes/surgery.asp?surgery=' + surgName);
		$('#surgery_out').show();
	}
	
	function loadquestion(quesName){
		$("#rcol p").hide();
		$("#rcol p."+quesName).show();		
	}

	
//============================Services Content Switch	
	$('.services #lcol div').hide();	
	$('ul.dropdown2_values li a').each(function(){
		id= $(this).attr('title').substring(1);
		//alert(id);
		$(this).addClass(id);
	});
	
	if (theAnchor == ""){
	$('.services #lcol div.macular').show();	
	$('.services .dropdown2_holder').html('MACULAR DEGERATION TREATMENTS');
	$('.services a.macular').addClass('active');
	}
	else {
		sectionID = theAnchor;
		$('.services #lcol div.' + sectionID).show();
		sectionTitle = $('ul.dropdown2_values').find('a.'+sectionID).html();
		$('a.'+sectionID).addClass('active');
		$('.dropdown2_holder').html(sectionTitle);
	};	
	
	
	$('.services #rcol a.go').click(function(){
		$('.services #lcol div').hide();	
		sectionID = $(this).attr('href').substring(1);
		$('.services #lcol div.' + sectionID).show();
	});

	
//============================Eye Conditions
	$('.eye_conditions ul li a, a.popup_trig').click(function(){
		alert("hi");
		link = "http://www.wikipedia.com/wiki/" + $(this).attr('title');
		condition = $(this).html();
		$('#overlay').slideDown(400);
		$('#popup_out').show(400);
		$('#popup_in p').html('Information regarding ' + condition + ' is hosted at <a href="http://www.wikpedia.org">Wikipedia.org</a>'); 
		$('a#wiki').attr('href', link);
		
	});

//============================Contact
	$('p#resume').hide() 		

	$('#employment').click(function(){	
		if ($(this).is(':checked')) { 
		$('p#resume').show() 
		} 
		else {
		$('p#resume').hide() 		
		};
	});
	
	$('#seeking_employment h3').click(function(){
		var target = $(this).parent();
		
		if(target.hasClass('on')){
			target.animate({
				height: 64
			}, 500, function(){
				target.toggleClass('on');
			});
		} else {
			target.animate({
				height: 450
			}, 500, function(){
				target.toggleClass('on');
			});
		}
		
		
	
	});

});

