// javascript for main page - radiology
	
	// **** T O P - R I G H T - N A V **** 
		var timeout    = 500;
		var closetimer = 0;
		var ddmenuitem = 0;  
		
		function verticalDropList_close(){
			if(ddmenuitem) ddmenuitem.css('visibility', 'hidden')
		;}
		
		function getActiveDropdown()
		{
			//headerNavTopList
			$('#mainContentTopRightNavList > li').bind('mouseover', verticalDropList_open);
			$('#mainContentTopRightNavList > li').bind('mouseout',  verticalDropList_timer);
			$('#headerNavTopList > li').bind('mouseover', verticalDropList_open);
			$('#headerNavTopList > li').bind('mouseout',  verticalDropList_timer);
			
			function verticalDropList_open(){  
				verticalDropList_canceltimer();
				verticalDropList_close();
				ddmenuitem = $(this).find('ul').css('visibility', 'visible')
			;}
					
			function verticalDropList_timer(){
				closetimer = window.setTimeout(verticalDropList_close, timeout)
			;}
			
			function verticalDropList_canceltimer(){
				if(closetimer){ 
					window.clearTimeout(closetimer);
					closetimer = null
				;}
			}	
		}
	
	// *** S L I D E S H O W ***
		// redefine Cycle's updateActivePagerLink function
		$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
			$(pager).find('a').removeClass('activeSlide')
				.filter('a:eq('+currSlideIndex+')').addClass('activeSlide');
		};
	
	// D O C U M E N T - R E A D Y...	
		$(function() {
			// topnav & toprightnav
			getActiveDropdown();
			document.onclick = verticalDropList_close;
			
			// 	BIND SLIDESHOW SLIDES FROM SOURCE HTML
			//	retrieve html from source file
			//	iterate html and strip h3 tags 
			//	apply 'title' attribute to all img tags
			$.ajax({
			  url: "slides.html",
			  cache: true,
			  success: function(html){
				$("#slideshow").append(html);
				$("#slideshow > h3").remove(); 
				$("#slideshow > img").attr("title", function() {
					return this.alt;
				});
				startSlideshow();		
			  }
			});
			
			function startSlideshow() {			
				var $slideshow = $('#slideshow'); 
				var totalSlideCount=4;
				
				// start slideshow 
				$('#slideshow').cycle({ 
					fx: 'fade', 
					startingSlide: 0,
					/*speed:    400, */
					speedIn: 1800,
					speedOut: 2000,
					sync: true,
					timeout: 9000,
					pause: 0,
					delay: 0, 
					prev:    '#prev', 
					next:    '#next', 
					pager: '#slideshowToolbarNav',
					pagerAnchorBuilder: function(idx, slide) {
						return '<li><a href="#">&nbsp;</a></li>'; 
					},
					before:  onBefore,
					after:   onAfter
				});
				
				// DISPLAY CONTROLS AFTER PRE-LOADING OF FIRST SLIDE
				$('#slideshowToolbarControls').attr({ style: "display:block;"});			
				
				$('#slideshowToolbarControlsPausePlay').toggle(function() {
					$('#slideshow').cycle('pause');
					$(this).attr({ src: "system/images/homepage/slideshowControlPlay.png", title: "resume autoplay"});
					}, function() {
					$('#slideshow').cycle('resume', true);
					$(this).attr({ src: "system/images/homepage/slideshowControlPause.png", title: "pause autoplay"});
				});
					
				function onBefore(curr, next, opts, fwd) {
					$('#slideshowToolbarCaption').html('loading...'); 
					if (!opts.addSlide) 
						return; 
						 
					// have we added all the slides? 
					if (opts.slideCount == totalSlideCount) 
						return; 
		 
					// shift or pop from our slide array  
					var nextSlideSrc = fwd ? slides.shift() : slides.pop(); 
					 
					// add our next slide 
					opts.addSlide('<img src="'+nextSlideSrc+'" />', fwd == false); 
				}; 
					
				function onAfter(curr, next) {
					$('#slideshowToolbarCaption').html(this.title);
				}; 
			}; 
		});