// wait for DOM to be ready
$(function() {
/****** Submenu Logic *******/
  //local review
  //$currentPath1 = jQuery.url.segment(4);
  //$currentPath2 = jQuery.url.segment(5);
  //client review
  //$currentPath1 = jQuery.url.segment(3);
  //$currentPath2 = jQuery.url.segment(4);
  //client server
  $currentPath1 = jQuery.url.segment(0);
  $currentPath2 = jQuery.url.segment(1);
  //if we're in the treatment section but not the cancer type section
	if($currentPath1 == "treatmentinformation" && $currentPath2 != "cancertypes") {
		$('li a.top-category:eq(0)').addClass('active').next('.sub-category').addClass('open');	 
	//if we're in the treatment section and also the cancer type section
	} else if($currentPath1 == "treatmentinformation" && $currentPath2 == "cancertypes") {
		$('li a.top-category:eq(1)').addClass('active').next('.sub-category').addClass('open');
	}	   
  //toggle the sub navigation
  $('li a.top-category').click(function(){
    $(this).toggleClass('active').next('ul.sub-category').slideToggle(600);
	return false;
  })
  
/****** Add "Active" class to main navigation*******/
  //client review
  $currentPath3 = jQuery.url.segment(0);
  //if we're in the about us section set class on the main navigation link to mark our section
	if($currentPath3 == "aboutus") {
		$('#nav-2 li a:eq(0)').addClass('active');	 
  //if we're in the dictionary section set class on the main navigation link to mark our section
	} else if($currentPath3 == "dictionary") {
		$('#nav-2 li a:eq(1)').addClass('active');
  //if we're in the statistics section set class on the main navigation link to mark our section		
	} else if($currentPath3 == "statistics") {
		$('#nav-2 li a:eq(2)').addClass('active');
  //if we're in the treatment information section set class on the main navigation link to mark our section		
	} else if($currentPath3 == "treatmentinformation") {
		$('#nav-2 li a:eq(3)').addClass('active');
  //if we're in the resources information section set class on the main navigation link to mark our section				
	} else if($currentPath3 == "resources") {
		$('#nav-2 li a:eq(4)').addClass('active');
	}
/****** Animated Scrolling  *******/  
  //setup local scrolling of anchors for website
  $.localScroll();
  
/****** Oncologist Finder Form *******/
  var $advancedElements = $('#ctl00_lastname, #ctl00_lastlabel, #ctl00_company, #ctl00_complabel, #ctl00_zip, #ctl00_ziplabel, #ctl00_country, #ctl00_countrylabel, #ctl00_languages, #ctl00_langlabel');
  $($advancedElements).hide();
  	 toggle = 1;
    $('#advsearch').click(function(){
		if(toggle==1) {	
		$($advancedElements).each(function(){
			$(this).fadeIn(500).attr("disabled", false); 
				});
		$(this).html("Basic Search");
		toggle -=1;
		} else if(toggle==0) {
		$($advancedElements).each(function(){
		 $(this).hide().attr("disabled", true); 
				});
		$(this).html("Advanced Search");
		toggle +=1;
		}
	return false;
	});
	
/****** Text Re-Sizing Feature *******/
 	// set initial toggle
	txtToggle = 1;
	// click function
	$("a#text").click(function(){
	//set jQuery object with items we want to resize
	var $mainText = $('#s-lv-3 p, #s-lv-3 h1, #s-lv-3 h2, span.alpha, p.header-lg, div.txtcall p, #s-lv-3 li, div.rt-nav li a').not('ul.dictionary li');
	// iterate through the JQuery object and grab current sizes of elements
    $mainText.each(function() {
	var currentSize = $(this).css('font-size');
	var num = parseFloat(currentSize, 2);
	//set up variables for 
	var newLargerSize = num + 2 +'px';
	var newSmallerSize = num - 2 +'px';
	// resize larger or smaller
	if(txtToggle==1) {	
     $(this).css('font-size', newLargerSize);
	}
	else if(txtToggle==0) {
     $(this).css('font-size', newSmallerSize);
	}
    });
	// change text for link and toggle value
	if(txtToggle==1) {	
	 $("a#text").html("Smaller Text").attr("title","Smaller Text");
	   txtToggle -=1; 
	}
	else if(txtToggle==0) {
	 $("a#text").html("Larger Text").attr("title","Larger Text");
	 txtToggle +=1;  
	}
   return false;
	});
});
