$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});

/* NAVIGATION TEST */
$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
	}
	/*	//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	*/
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 200, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);



});

/* END TEST */


/* MAIN NAVIGATION */

$(document).ready(function(){
	
		// remove link background images since we're re-doing the hover interaction below 
		// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
		// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
		$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	


		// create events for each nav item
		attachNavEvents(".nav", "nav1");
		attachNavEvents(".nav", "nav2");
		attachNavEvents(".nav", "nav3");
		attachNavEvents(".nav", "nav4");
		attachNavEvents(".nav", "nav5");
		attachNavEvents(".nav", "nav6");
	

		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}



	});

/* END MAIN NAVIGATION */

/* BANNER REPLACEMENT */

$(document).ready(function() {
	$('#banner img').addClass('hidden1');
	$('#banner').append(' <a href="/index.html"><img src="/chop/system/galleries/webresources/hospital/images/logo_contrast.gif" alt="Home" id="homebutton" class="hidden2" /></a>');
	});
	
$(document).ready(function() {
	$('.evidencelink').click(function(){
		$('.evidence').fadeIn();
		});
	$('.closer').click(function(){
		$('.evidence').fadeOut();
		});
	});	
	
	
/*accordion*/
jQuery(document).ready(function(){
	$('.accordion .section').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
});

$(document).ready(function(){
  $('.hideme').click(function(){
    $(this).parent().toggle('slow');

  });
});

$(document).ready(function() {
    	$('.preventer').click(function(e) {
    	e.preventDefault();
    });
    });
    
$(document).ready(function(){
  $('.nursebutton').click(function(){
    $('.preconference1 .nursing').toggleClass('nursingcolor');
    $(this).toggleClass('onbackground');
    /* $('.preconference1 tr').removeClass('presentercolor');
    $('.preconference1 tr').removeClass('admincolor');
    $('.preconference1 tr').removeClass('pedcarecolor');*/
  });
});

$(document).ready(function(){
  $('.adminbutton').click(function(){
    $('.preconference1 .admin').toggleClass('admincolor');
    $(this).toggleClass('onbackground');
   /* $('.preconference1 tr').removeClass('presentercolor')
    $('.preconference1 tr').removeClass('pedcarecolor');
    $('.preconference1 tr').removeClass('nursingcolor'); */
  });
});


$(document).ready(function(){
  $('.pedcarebutton').click(function(){
    $('.preconference1 .pedcare').toggleClass('pedcarecolor');
    $(this).toggleClass('onbackground');
   /* $('.preconference1 tr').removeClass('presentercolor')
    $('.preconference1 tr').removeClass('nursingcolor');
    $('.preconference1 tr').removeClass('admincolor'); */
  });
});

/*end accordion*/

/*$(document).ready(function() {	
$('#featurehome p:last').after('<div class="extranav"><div class="lefty"><div class="littletext" style="height: 14px;">VOICE your approval!</div><a href="https://donate.chop.edu/site/Donation2?df_id=4340&4340.donation=form1&JServSessionIdr004=17oi336ad3.app205b" target="_blank">Give a gift supporting THE VOICE</a><a href="https://donate.chop.edu/site/Donation2?df_id=4340&4340.donation=form1&JServSessionIdr004=17oi336ad3.app205b" target="_blank"><img src="/chop/system/galleries/webresources/hospital/images/gift-button.jpg" /></a></div><div class="righty"><div class="littletext" style="height: 14px;"></div><a href="http://giving.chop.edu/site/PageServer?pagename=give_TheVoice" target="_blank">About THE VOICE</a><a href="http://giving.chop.edu/site/PageServer?pagename=give_TheVoice" target="_blank"><img src="/chop/system/galleries/webresources/hospital/images/arrow-button.jpg" /></a></div></div>');
	});*/
	
	
/*$(document).ready(function() {
$('.button').each(function() {
     $(this).attr('src', 'img_contrast_' + $(this).attr('src'));
});
});*/
	
/*$(document).ready(function() {
	$('.buttoncontrast').attr('src', 'contrast_');
	});*/
	
/*$(document).ready(function() {
	$('.button').remove('input[type="image"]');
	$('.button').append('input[type="submit"]');
	});*/
	
	
/*$("input[type='image']").each(function(){
  var name = $(this).attr('search_text'); // grab name of original
  var value = $(this).attr(''); // grab value of original
  // create new visible input
var html = '<input type="text" name="'search_text'" value="'+value+'" />';
  $(this).after(html).remove(); // add new, then remove original input
});*/
	

/* INSERT HIGH CONTRAST LINKS */


   
/*$(document).ready(function() {
	$('#navaccess ul').append('<li class="hidden3"><a href="serversideSwitch.html?style=contrast" rel="contrast" class="styleswitch">High Contrast</a></li><li class="hidden4"><a href="serversideSwitch.html?style=default" rel="default" class="styleswitch">Normal Contrast</a></li>')
  	});*/
  	
/* $(document).ready(function() {
	$('#footer1').prepend('<h6>Web Accessibility</h6><ul><li><a href="/accessibility/web-accessibility.html">Web Accessibility and CHOP</a></li><li class="hidden3"><a href="serversideSwitch.html?style=contrast" rel="contrast" class="styleswitch">High Contrast Style Sheet</a></li><li class="hidden4"><a href="serversideSwitch.html?style=default" rel="default" class="styleswitch">Normal Contrast Style Sheet</a></li></ul>')
  	});*/
  	
  	
  $(document).ready(function() {
	$('#footer1').prepend('<h6>Web Accessibility</h6><ul><li><a href="/accessibility/web-accessibility.html">Web Accessibility and CHOP</a></li></ul>')
  	});
  	
  	
  /*$(document).ready(function() {
	$('p#justfor6').after('<h2 class="hidden3">High Contrast</h2><p style="line-height: 24px;" class="hidden3">A <strong><a href="serversideSwitch.html?style=contrast" rel="contrast" class="styleswitch">high contrast</a></strong> version of this Web site is offered.</p><h2 class="hidden4">High Contrast</h2><p style="line-height: 24px;" class="hidden4">A <strong><a href="serversideSwitch.html?style=default" rel="default" class="styleswitch">normal contrast</a></strong> version of the site is offered.</p>')
  	});*/
 

/* SOCIAL NETWORKING TOOLS */

$(document).ready(function() {
	$('#column2 #tools ul, #column2dept #tools ul').append('<li class="followus"><strong>Follow us:</strong></li><li class="icn_twitter"><a class="pop2" href="http://twitter.com/ChildrensPhila">Twitter</a></li><li class="icn_facebook"><a class="pop2" href="http://www.facebook.com/ChildrensHospitalofPhiladelphia">Facebook</a></li><li class="icn_youtube"><a class="pop2" href="http://www.youtube.com/ChildrensHospPhila">Youtube</a></li>');
	});
	
$(document).ready(function() {
	$('#deuxcolumn #tools').append('<ul><li class="followus2"><strong>Follow us:</strong></li><li class="icn_twitter"><a class="pop2" href="http://twitter.com/ChildrensPhila">Twitter</a></li><li class="icn_facebook"><a class="pop2" href="http://www.facebook.com/ChildrensHospitalofPhiladelphia">Facebook</a></li><li class="icn_youtube"><a class="pop2" href="http://www.youtube.com/ChildrensHospPhila">Youtube</a></li></ul>');
	});

/* END SOCIAL NETWORKING TOOLS */

/* START ICONS */

  
 $(document).ready(function() {
  	$('<span class="doc">(Word)</span>').insertAfter("a[href$='.doc']");
  	$('<span class="doc">(Word)</span>').insertAfter("a[href$='.dot']");
  	$('<span class="doc">(Word)</span>').insertAfter("a[href$='.dotx']");
  	$('<span class="doc">(Word)</span>').insertAfter("a[href$='.docx']");
  	$('<span class="pdf">(PDF)</span>').insertAfter("a[href$='.pdf']");
  	$('<span class="zip">(Zip)</span>').insertAfter("a[href$='.zip']");
  	$('<span class="xls">(XLS)</span>').insertAfter("a[href$='.xls']");
  	$('<span class="ppt">(PPT)</span>').insertAfter("a[href$='.ppt']");
  	});
  	
 $(document).ready(function() { 	
 	$('.hideicon span.doc').hide();
 	$('.hideicon span.pdf').hide();
 	$('.hideicon span.zip').hide();
 	$('.hideicon span.xls').hide();
 	$('.hideicon span.ppt').hide();
 	});
  	
 //	$('(zip)').not('.nodoctype').insertAfter("a[href$='.zip']");

 
 // NEED TO FIGURE OUT HOW TO REMOVE THE FILETYPE

  /* POP UP STYLES */
  
  $(function() {
			$('a.pdf1').click(function() {
			var href = $(this).attr('href');
			ko = new Date();
			ji = ko.getTime();
			var winName = ji;
			window.open(href, ji, 'height=550,width=612,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes, statusbar=yes,location=yes');
			return false;
			});
		});
		
  $(function() {
			$('a.pop1').click(function() {
			var href = $(this).attr('href');
			ko = new Date();
			ji = ko.getTime();
			var winName = ji;
			window.open(href, ji, 'height=550,width=760,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes, statusbar=yes,location=yes');
			return false;
			});
		});
		
  $(function() {
			$('a.transcript').click(function() {
			var href = $(this).attr('href');
			ko = new Date();
			ji = ko.getTime();
			var winName = ji;
			window.open(href, ji, 'height=550,width=612,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes, statusbar=yes,location=yes');
			return false;
			});
		});
		
$(function() {
			$('a.pop2').click(function() {
			var href = $(this).attr('href');
			ko = new Date();
			ji = ko.getTime();
			var winName = ji;
			window.open(href, ji, 'height=600,width=980,toolbar=yes,resizable=yes,scrollbars=yes');
			return false;
			});
		});
		
		
//ko = new Date();
//ji = ko.getTime();
//var winName = ji;

/* HIDE AND SHOW ON FOCUS ACCESSIBILITY NAV */

$(document).ready(function() {
			$('#navaccess a').addClass("idlenav");
       		$('#navaccess a').focus(function() {
       			$(this).removeClass("idlenav").addClass("focusnav");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('#navaccess a').blur(function() {
    			$(this).removeClass("focusnav").addClass("idlenav");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		});		
		
/* END HIDE AND SHOW ON FOCUS ACCESSIBILITY NAV */
		

/* START STRIPED TABLES - keep at end for now, or icons stop working, don't know why */
	
$(document).ready(function() {
	var rowClass = 'even';
	var rowIndex = 0;
	$('table.table2 tbody tr').each(function(index) {
		if ($('th', this).length) {
			rowClass = 'subhead';
			rowIndex = -1;
			} else if (rowIndex % 1 == 0) {
				rowClass = (rowClass == 'even' ? 'odd' : 'even');
			};
			$(this).addClass(rowClass);
			rowIndex++;
		});
	});

/* END STRIPY TABLES */

/* REMOVE THE P TAGS */


/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/


/*$('.button').each(function() {
     $(this).attr('src', 'img_contrast_' + $(this).attr('src'));
});*/

/*FOR TRANSCRIPT TITLE HIDE*/
/*$(document).ready(function() {
	$('#transcript p:first').before('<h5>Transcript</h5>');
	});*/



$(document).ready(function() {
	$('#tools ul li.icn_print a').click(function() {
		window.print();
		return false;
	});
});

$(document).ready(function() {
	$('#transcript p.icn_print a').click(function() {
		window.print();
		return false;
	});
});



