 
	
$(document).ready(function(){
	$('a[rel*=facebox]').facebox(); 
	
	$('.forgotPW').click(function(){
		ColdFusion.Window.show('forgotPWWindow');
		return false;
	});		
	
	$('.forgotUsername').click(function(){
		ColdFusion.Window.show('forgotUsernameWindow');
		return false;
	});
	
	$('.forgotContributorPW').click(function(){
		ColdFusion.Window.show('forgotContributorPWWindow');
		return false;
	});		
	
	$('.forgotContributorUsername').click(function(){
		ColdFusion.Window.show('forgotContributorUsernameWindow');
		return false;
	});
	
	contributeForm.init();
	patientUI.init();

	/*
$('.contentRight').append($('.ad234x60'));
	$('.contentLeft .ad234x60').remove();
	$('.ad234x60').css('margin-left', '-240px');
	if ($('.adminContent').height() < $('.contentLeft').height()) {
		var admargin = 388 - $('.adminContent').height();
		if (admargin > 0) {
			$('.ad234x60').css('margin-top', admargin);
		}
	}
*/

//JUSTIN - THIS IS WHAT WAS CAUSING THE LINKS NOT TO WORK ON THOSE PAGES, BUT ALLOWS FOR THE SUBNAV TO WORK IN IE7.
//THIS IS WHERE I GOT THIS... http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/comment-page-1/
$(function() {
if ($.browser.msie) {
	var zIndexNumber = 1000;
	$('div').each(function(){
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 1;
	});
}
});
	
	function addMega(){ 
	  $(this).addClass("hovering"); 
	  $(this).children("a").addClass("selected"); 
	}
	 
	function removeMega(){ 
	  $(this).removeClass("hovering"); 
	  $(this).children("a").removeClass("selected");
	 } 

	var megaConfig = {     
	     interval: 500, 
     	 sensitivity: 4, 
		 over: addMega, 
		 timeout: 500, 
		 out: removeMega 
	};

	$("li.mega").hoverIntent(megaConfig);

	var default_values = new Array();
	$("* .default").focus(function() {
		if (!default_values[this.id]) {
				default_values[this.id] = this.value;
		 }
		if (this.value == default_values[this.id]) {
			this.value = '';			
		}
		$(this).blur(function() {
			if (this.value == '') {				        
				    this.value = default_values[this.id];
		    }
		});
	});

});
	
var contributeForm = {};
var patientUI = {};

patientUI.init = function(){
	var fields = ['detail_field','url_field','document_field'];
	for(i=0; i<fields.length; i++){
		$('#'+fields[i]).hide();
	}
	$('.fieldControl').change(function(){
		for(i=0; i<fields.length; i++){
			$('#'+fields[i]).hide();
		}		
    	$('#'+fields[$(this).val()]).show();
	});
}

contributeForm.init = function(){
	this.initHeaders();
	this.recurrance();	
	this.contribute();
	this.honor();
}

contributeForm.initHeaders = function(){
	$('h4.toggleheader').wrap('<div class=\"toggle\">');
	$('.toggle:last').css('margin-top','50px');
	
	$('.toggle').mouseover(function(){
		$(this).addClass('hover');
	})
	$('.toggle').mouseout(function(){
		$(this).removeClass('hover');
	})	
	$('.toggle').click(function(){
		$(this).removeClass('hover');
		$(this).toggleClass('selected')
		$(this).next().toggle();
	})
	$('.toggle:last').addClass('selected')
}

contributeForm.recurrance = function(){
	//$('.recurringFields').hide();
	$('.contribType select').change(function(){
		//alert($(this).val())
		if($(this).val() == 1){
			$('.recurringFields').show();
		}else{
			$('.recurringFields').hide();
		}
	});
}

contributeForm.contribute = function(){
	//$('.ntafContribForm').hide();
	//$('.patientContribForm').hide();
	
	$('.patientContribForm .find').click(function(){
		var urlString = '/contribute/patient_results.cfm';
		urlString += '?first=' + $('#contribFirstNameValue').val();
		urlString += '&last=' + $('#contribLastNameValue').val();
		urlString += '&type=' + $('#contribTypeValue').val();
		
		//ColdFusion.navigate(urlString,'patientResults');
	})
	//$('.patientContribForm').show();
	//$('.toggle:last').addClass('selected');
}

contributeForm.honor = function(){
	//$('.honorForm').hide();
	//$('.honorForm .mail').hide();
	//$('.honorForm .email').hide();
	
	$('.contribNotify').change(function(){
		if($(this).val() == 1){
			$(this).parent().parent().next().show();
		}else{
			$(this).parent().parent().next().hide();
		}
	});
	
	$('.notification').change(function(){
		if($(this).val() == 1){
			$(this).parent().parent().next().show();
			$(this).parent().parent().next().next().hide();
		}else{
			$(this).parent().parent().next().hide();
			$(this).parent().parent().next().next().show();			
		}		
	});
	
}

function contribChange(obj){
	var tmp = $(obj);
		if($(tmp).val() == 1){
			$('.patientRecurringFields').show();
		}else{
			$('.patientRecurringFields').hide();
		}
}


function photoForm(photoId,galleryId){
		if(photoId != 0){
			var url = '/patients/photo-form.cfm?photo_id='+photoId+'&id=' + galleryId;
			ColdFusion.navigate(url,'pForm');
		}
		if($('#aphotoFormMultiple').attr('display','block')){
			$('#aphotoFormMultiple').slideUp();
		}
		$('#aphotoForm').slideToggle();
		sIFR.replace(rockwell, {
		  selector: '.rockwelltitle',
		  fitExactly:true,
			css: [
			  '.sIFR-root { font-size:16px; color:#0a91e3; font-weight: bold; text-transform: uppercase;}',
			  'a{ font-size:16px; color:#0a91e3; font-weight: bold; text-decoration:none;}',
			  'a:hover{ font-size:16px; color:#BD0016; font-weight: bold; text-decoration:none;}'
			  ],
		  wmode: 'transparent'
		});
		return false; 	
}

function photoFormMultiple(galleryId){
		if($('#aphotoForm').attr('display','block')){
			$('#aphotoForm').slideUp();
		}	
		$('#aphotoFormMultiple').slideToggle();
		sIFR.replace(rockwell, {
		  selector: '.rockwelltitle',
		  fitExactly:true,
			css: [
			  '.sIFR-root { font-size:16px; color:#0a91e3; font-weight: bold; text-transform: uppercase;}',
			  'a{ font-size:16px; color:#0a91e3; font-weight: bold; text-decoration:none;}',
			  'a:hover{ font-size:16px; color:#BD0016; font-weight: bold; text-decoration:none;}'
			  ],
		  wmode: 'transparent'
		});
		return false; 	 	
}

function loadGalleryImage2(id,photoid){
		jQuery.facebox({ajax: '/includes/gallery-images-full.cfm?id='+id+'&photoid='+photoid});
		return false;
  }
  
function loadGallery2(gallery){
	  jQuery.facebox({ajax: '/includes/gallery-images.cfm?id='+gallery});
  }