/* Main .JS file for Pardee Hospital. T. Markle, integritive.com 2009-03-30 */


	// form validation functions

	function validate(input,type,form,title){
		value=input.value;
		note=input.name+"Note"; // Need this for notifications
		$('#submitNote').html(" ");
			// check exception (matches to previous input) needs to be JS for simplicity
			if(type=='check'){ // we assume that the check is named 'email2' or similar
				previousDiv="tM"+input.name.substr(0,input.name.length-1);
				previous=$('#'+previousDiv+' > input').val();
				if(previous!=value){ 
					$('#'+note).html("Please make sure this matches the previous value.");
				} else {
					checkFade(note);
				}
			} else { // usual ajax check
				$('#'+note).html(" ");
				$('#'+note).load("../classes/tables.class.php",{'ajax':'1','value':value,'type':type,'form':form,'title':title},function(a,b){
					if(a=='' && b=='success'){
						checkFade(note);
						checkFade("submitNote");
					} else if(a!='' && b=='success'){

						$('#submitNote').html("Please fix noted items");
					} else if(b=='error'){
						$('#'+note).html("");
						$('#submitNote').html("");
					}
					
			 });
		}
	}
	
	function cleared(){
	$('#submitNote').html("");	
	warning='';
	$('.note').each(function(){
	warning=warning+$(this).text(); 
	});
	if(warning!=''){
		$('#submitNote').html("Please fix items with notes");
		return false;
	} else {
		return true;
	}
	}


	function checkFade(note){
		$('#'+note).html("");
		$('#'+note+"Check").fadeOut(1000);
   	$('#'+note+"Check").queue(function () {
        $(this).remove();
        $(this).dequeue();
      });

	}


$(document).ready(function(){	   

	// $("body").prepend('<div id="overlay"><img src="./sprites/contact.jpg"></div>');
	// $("body").prepend('<div id="overlay"><img src="./sprites/pardeeWho_we_are.jpg"></div>'); // home
	 $("#overlay").css({'position' : 'absolute', 'top' : '0px', 'left' : '113px', 'z-index' : '1000'});
	 $("#overlay").fadeTo(1, 0.5);   
	 $("#overlay").toggle(
			function () {
				$(this).fadeTo(2, 1.0);   
    	},
			function () {
				$(this).fadeTo(2, 0.5);   
    	},
			function () {
				$(this).fadeTo(2, 0.01);   
			},
			function () {
				$(this).fadeTo(2, 0.5);   
    	}
			);

// font-resize
  $('#resizeDown').click(function(){
    size="12px";
    resizeContent(size);
  });

  $('#resizeZero').click(function(){
    size="16px";
    resizeContent(size);
  });

  $('#resizeUp').click(function(){
    size="18px";
    resizeContent(size);
  });

  function resizeContent(size){
    $('#content p').css('font-size',size);
    $('#content p a').css('font-size',size);
    $('#content li a').css('font-size',size);
    $('#content li').css('font-size',size);
    $('#content').css('font-size',size);
  }

	$('ul.faq li p').hide();
	$('ul.faq li').toggle(function(){
		$(this).children().slideDown();
	},function(){
		$(this).children().slideUp();
	});

});


// Menu Behavior
$('.leftNav').ready(function(){
	// hide subnavs.
	$('.subNavHolder').each(function(){
		if($(this).children("ul").children(".selected").length==0){$(this).hide();}
	});
	// show subnavs that have an element that is selected
	$('.subNav > .selected').parent().parent().show();
	
	// show subnavs that have the preceeding LI selected
	$('.selected + li').show();

/*
var config = {    
     sensitivity: 6, // number = sensitivity threshold (must be 1 or higher)    
     interval: 100, // number = milliseconds for onMouseOver polling interval    
     over: doSubs, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: doNothing // function = onMouseOut callback (REQUIRED)    
};
 //this function includes all necessary js files for the application  
 function include(file)  
 {  
   
   var script  = document.createElement('script');  
   script.src  = file;  
   script.type = 'text/javascript';  
   script.defer = true;  
   
   document.getElementsByTagName('head').item(0).appendChild(script);  
   
 }  
   

 include('jquery.hoverIntent.minified.js');  
$('.leftNav > li').hoverIntent( config )


	// add hover behavior
function doSubs(){}

	$('.leftNav > li').each(function(){$(this).removeClass("currentHover");}); // strip hover flag from all lis
	if($(this).next().hasClass("subNavHolder")){ // if it's a title for a subNav
		$(this).next().addClass("currentHover"); // add the hover flag to this li
		$('.subNav').each(function (){
			// don't hide subnavs that have thir children selected or are siblings of the current leftNav LI, or are the current subnav
			if($(this).children(".selected").length==0 && $(this).parent().prev().hasClass("selected")==false && !$(this).parent().hasClass("currentHover")){ 
			$(this).parent().slideUp(420);
			}
		}); 
		$(this).next().stop(true,true);
		if($(this).next(":hidden").length==1){$(this).next().slideDown(420);} // dont re-slide already open subNavs
	}
}
*/
function doNothing(){}
});

// Index Slideshow
/*$('#homeGraphic img').ready(function(){
	setTimeout("cycleSlide(0)",5000);
});*/

	function cycleSlide(i,images,links){
		
		//images=Array('homeGraphic2.jpg','homeGraphic3.jpg','homeGraphic4.jpg','homeGraphic1.jpg');
		thisimg=images[i];
		
		imageCount=images.length-1;
		//alert(i+" "+images[i]);
		nextimg=(i==imageCount ? images[0] : images[i+1]);
		//alert("step "+i+" "+thisimg+">"+nextimg);
		// fade the current img
		$('#homeGraphic img').fadeTo(800,0.01);
		// swap img to current hG bg
		$('#homeGraphic img').queue(function(){
			$(this).attr('src','./sprites/slideshow/'+thisimg);
      $(this).dequeue();
	  
	 if(thisimg=='homeGraphic1.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='http://blog.pardeehospital.org/take-time-take-charge/' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			$('#homeGraphic a').remove();
			if(thisimg=='homeGraphic2.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='https://careportal.pardeehospital.org/PUCC/default.aspx'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='homeGraphic3.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='http://blog.pardeehospital.org/pardee’s-comprehensive-cancer-center-receives-outstanding-achievement-award/'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='homeGraphic4.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='http://www.pardeehospital.org/health_services/?page=emergency_department'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='homeGraphic5.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='http://lightenup4life.com/pardee/' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='homeGraphic6.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='http://blog.pardeehospital.org/tag/pardeegreen/' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}

			if(thisimg=='foundGraphic1.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='https://www.pardeehospital.org/foundation/give_happiness/donate.php'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='foundGraphic2.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='https://www.pardeehospital.org/foundation/ways_to_give/?page=women_helping_women' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='foundGraphic3.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='https://www.pardeehospital.org/foundation/give_happiness/donate.php' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
			if(thisimg=='foundGraphic4.jpg' && links==1){
			$('#homeGraphic').prepend("<a href='https://www.pardeehospital.org/foundation/ways_to_give/?page=generations_of_excellence' target='_blank'><img src='../js/blank.gif' class='homeBlank'></a>");
			}
		});

		$('#homeGraphic img').fadeTo(1,1);      
		// swap bg to next img
		$('#homeGraphic img').queue(function(){
			$(this).parent().css('background',"url('./sprites/slideshow/"+nextimg+"') no-repeat 0px 0px");			
			$(this).dequeue();
		});
		// wipe hands on pants, rinse, repeat
		j=(i==imageCount ? 0 : i+1);
		setTimeout(function(){cycleSlide(j,images,links);},5000);
	
	}

// Run the news ticker (triggered in the pod itself)
var tickerLine=0;
function cycleTicker(){
	//Get the subs of ticker div into an array
	var subs=$('#newsPodTicker').children();
	//if(tickerLine==0){$(subs).hide();}
	// fade all tickers
	$(subs).fadeOut(800);
	$(subs[tickerLine]).queue(function(){	
		$(this).fadeIn(800);
        $(this).dequeue();
	});
//	$(subs[tickerLine]).show();

		// show the next one


		// set cycle for next
			setTimeout(function(){ 
				tickerLine=tickerLine+1;	
				if(tickerLine>=subs.length){tickerLine=0;} 	
				cycleTicker();},4000);

}
