
var photo_gallery_init = function()
{
	caption_array = new Object();
	caption_array['patrickw'] = "Thanks to Fresenius Medical Care\'s dialysis program, Patrick Woods has his days free to work full-time as a facilities manager.";
	caption_array['francisb'] = "Fresenius Medical Care patient Francis Boeding enjoys spending his free time performing with his senior singing group, the Golden Tones.";
	caption_array['nikis'] = "Fresenius Medical Care patient Niki Summers (center) with her parents after a celebratory dinner in her honor.";
	caption_array['kellym'] = "In addition to fishing and golfing, Fresenius Medical Care dialysis patient Kelly Miller keeps physically fit by refereeing community basketball games.";
	caption_array['pamelam'] = "Pamela Murchison, a Fresenius Medical Care dialysis patient, is dedicated to helping fellow patients and the kidney community.";
	caption_array['graciec'] = "Fresenius Medical Care patient Gracie Castro with her two sons and grandson in Florida.";
	caption_array['maryannm'] = "Fresenius Medical Care patient Mary Ann Milo with her niece, Grace Ann Miller, at a family dinner.";
	caption_array['ronnieg'] = "Fresenius Medical Care dialysis patient Ronnie Glasper with his Little Brother, who he's been mentoring for over two years.";
	caption_array['vickiel'] = "Fresenius Medical Care dialysis patient Vickie Lusby and her son, Ken, visit her parent's house in her hometown of Mound Bayou, Miss during a summer vacation.";
	caption_array['kelvinw'] = "Fresenius Medical Care dialysis patient Kelvin Wright dances in a conga line during his honeymoon trip to Walt Disney World.";
	caption_array['johnh'] = "Fresenius Medical Care patient John Hrivnak enjoys reading to his daughters.";	
	caption_array['andrews'] = "Fresenius Medical Care patient Andrew Stasny loves spending his free time with his wife, pictured above, and family.";
	caption_array['anthonyc'] = "Anthony Culotta, a Fresenius Medical Care dialysis patient, with floats he designed and built for parades in Louisiana.";
	caption_array['anthonyl'] = "Fresenius Medical Care patient Anthony Lee encourages other patients to live life to the fullest.";
	caption_array['cecelh'] = "Cecel Hollingsworth, Fresenius Medical Care dialysis patient, volunteers at the Dell Children's Medical Center coffee shop.";
	caption_array['charlisah'] = "Fresenius Medical Care patient Charlisa Holmes (left) with a soldier who is wearing one of her knitted helmet liners.";
	caption_array['davidb'] = "David Bosse, Fresenius Medical Care dialysis patient, keeps fit by paying close attention to his diet.";
	caption_array['harveyj'] = "One of Harvey Jones' many stops on the road as a singer was the set of The Tonight Show with Jay Leno. When not traveling, Harvey receives dialysis treatment at Fresenius Medical Care Southwest Greensboro in North Carolina.";
	caption_array['homers'] = "A traveling showman, Fresenius Medical Care patient Homer Scott is pictured near props that were part of his \"Old Time Medicine Show.\"";
	caption_array['joannr'] = "Fresenius Medical Care dialysis patient Joann Ratliff enjoys reading, playing billiards and cooking.";
	caption_array['joef'] = "Fresenius Medical Care patient Joe Farrar, pictured second from the right, enjoys spending time with his family.";
	caption_array['joem'] = "Fresenius Medical Care dialysis patient Joseph Mann is an avid antique car collector.";
	caption_array['manueli'] = "Manuel Ibarra, Fresenius Medical Care dialysis patient, enjoys fishing in his spare time.";
	caption_array['marianc'] = "Marian Carr, Fresenius Medical Care dialysis patient, maintains a rigorous travel schedule to keep up with all her work.";
	caption_array['marlenem'] = "Fresenius Medical Care patient Marlene Meza with her son, Jose Luis, cooking for a family dinner.";
	caption_array['robertw'] = "Fresenius Medical Care Lenoir dialysis patient Robert Whitley shows students how to make balloon animals and juggle for a school fundraiser.";
	caption_array['rolandm'] = "Fresenius Medical Care dialysis patient Roland Martinez is an accomplished drummer who still enjoys playing in a local band.";
	caption_array['tanyshap'] = "Fresenius Medical Care patient Tanysha Pitts is studying to be a medical assistant and is graduating in March 2010.";
	caption_array['timm'] = "Fresenius Medical Care dialysis patient Tim Morgan has lived with ESRD for 32 years, but he doesn't let that get in the way of his family time or his favorite hobby, gardening.";
	caption_array['nancyw'] = "A patient advocate in Hagerstown, Md., Fresenius Medical Care dialysis patient Nancy Weirich enjoys traveling with her husband Ned and dog Molly.";
	caption_array['richardm'] = "Fresenius Medical Care dialysis patient Richard Marietta has been teaching in Southington, Conn. for over forty years.";

	$('.photo_gallery_thumb').hover(function() {
		$(this).css('cursor','pointer');
	});
	
	$('div.photo_gallery_thumb').click(function() {
		var src = $('img', this).attr('src');
		var lgsrc = src.replace(/_thumb/,'');
		var photoid = src.substring(src.indexOf('gallery_')+8, src.indexOf('_thumb.jpg'));
		//alert(photoid);
		$('#photo_gallery_image').css('background-image','url(' + lgsrc + ')');
		$('#photo_gallery_blurb').html(caption_array[photoid]);
	});
	
}

var nav_hover_init = function() {
	$('#mainNav td a img, #top_subnav td a img')
		.not('#mainNav td a.current img')
		.not('#top_subnav td a.current img')
		.not('#mainNav td a.current_is_subpage img')
		.hover(function() {
		var src = $(this).attr('src');
		//alert(s);
		var spl = src.split(".gif")[0];
		var new_src = spl+'-over.gif';
		$(this).attr('src',new_src);
	}, function() {
		var src = $(this).attr('src');
		//alert(s);
		var spl = src.split("-over.gif")[0];
		var new_src = spl+'.gif';
		$(this).attr('src',new_src);
	});
	
}

var healthgrades_init = function() {

	if ($('#HealthGradesWidget').length > 0) { 
		c=document.cookie.indexOf("hg=");
		if (c != -1) {				
			//alert('yes');
			document.cookie = 'hg=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
			var Widget = new HGW(document.getElementById('HealthGradesWidget'));
		} else {
			//alert('no');
			document.cookie='hg=y';
			window.location.reload();
		}
	}
}

var zipcode_field_init = function() {
	$('#zipcode_home').val('Your Zip code');
	
	$('#zipcode_home').click(function() {
		if ($(this).val() == 'Your Zip code') {
			$(this).val('');
			$(this).addClass('zipcode_input_active');
		}
	});

	$('#zipcode_home').blur(function() {
		if ($(this).val() == '') {
			$(this).val('Your Zip code');
			$(this).removeClass('zipcode_input_active');
		}
	});
}

var intval = "";

var banner_rotate = function(arr,i,a,a_tab)
{

    function rotate()
    {

        b = a;
        b_tab = a_tab;
        a = $(arr[i] + "_area");
        a_tab = $(arr[i]);
        
        i = (i==arr.length-1) ? 0 : i+1;

        //a.fadeIn("slow");
        //b.fadeOut("slow");
        a.addClass('active');
        b.removeClass('active');
        a_tab.addClass('active');
        b_tab.removeClass('active');

    }    
        
    intval = setInterval(rotate, 7000);

}

var banner_rotate_init = function() 
{
    var arrDiv = new Array();
    arrDiv[0] = "#tab1";
    arrDiv[1] = "#tab2";
    arrDiv[2] = "#tab3";
    arrDiv[3] = "#tab4";
    arrDiv[4] = "#tab5";
    var ini = 1;
    firstDiv = $(arrDiv[0] + "_area");   
    firstTab =  $(arrDiv[0]); 
    
    banner_rotate(arrDiv,ini,firstDiv,firstTab);
}

var homepage_init = function() {
	$('#hero_tabs div.hero_tab').mouseenter( function() {
		$(this).addClass('hover');
	});
	$('#hero_tabs div.hero_tab').mouseleave( function() {
		$(this).removeClass('hover');
	});
	
	$('div.hero_tab').click( function() {
		$('div.hero_tab').removeClass('active');
		$(this).addClass('active');
		
		tabID = $(this).attr('id');
		
		$('.hero_area').removeClass('active');
		$('#' + tabID + '_area').addClass('active');
		
		clearInterval(intval);
	});
	
	banner_rotate_init();
	zipcode_field_init();
	
	var videoArray = new Array();
	videoArray[0] = '0810';
	videoArray[1] = '1563';
	videoArray[2] = '1535';
	videoArray[3] = '1512';
	videoArray[4] = '1526';
	videoArray[5] = '0181';
	
	$('#featuredVideos div.videoPanel').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('#featuredVideos div.videoPanel').click(function() {
		var vidclass = $(this).attr('class');
		//var vidnum = parseInt(vidclass);
		
		var vidnum = new String(vidclass); 
		vidnum = vidnum.replace(/[^0-9]/g, ''); 

		window.location = 'renderpage.asp?pid=s' + videoArray[vidnum-1] + '&purgecache=1';
		
		//alert(vidnum);
	});
	
	var scrollspeed = 350;
	var vidwidth = 176;
	var numvideos = 6;
	
	var scrollwidth = vidwidth * numvideos;
	var visiblewidth = vidwidth * 5;
	var hiddenwidth = scrollwidth - visiblewidth;
	
	var rightClicksAvail = hiddenwidth / vidwidth;
	var leftClicksAvail = 0;
	
/*
	$('#scrollLeft').click(function() {
		if (!$(this).hasClass('disabled')) {
			$('#scrollAreaContent').animate({
				left:'+=' + vidwidth	
			}, scrollspeed, 'swing', function() {
				var scrollarealeft = Math.abs(parseInt($('#scrollAreaContent').css('left')));
				//alert(scrollarealeft);
				$('#scrollRight').removeClass('disabled');
				if (scrollarealeft >= 0) {
					$('#scrollLeft').addClass('disabled');
				} else {
					$('#scrollLeft').removeClass('disabled');
				}			
			});
		}
	});
	

	
	var rightClickScroll = function() {
		$('#scrollRight').unbind('click');
		if (!$('#scrollRight').hasClass('disabled')) {
			scrollRight();
		}
		$('#scrollRight').click(rightClickScroll);
	}
	
	

*/



	var toggleScrollButtons = function() {		
		if (leftClicksAvail > 0) {
			$('#scrollLeft').removeClass('disabled');
		} else {
			$('#scrollLeft').addClass('disabled');
		}

		if (rightClicksAvail > 0) {
			$('#scrollRight').removeClass('disabled');
		} else {
			$('#scrollRight').addClass('disabled');
		}		
	}
	
	var scrollRight = function() {
		leftClicksAvail += 1;
		rightClicksAvail -= 1;
		toggleScrollButtons();
		
		$('#scrollAreaContent').animate({
			left:'-=' + vidwidth	
		//}, scrollspeed, 'swing', function() {
		}, scrollspeed, 'swing');
			//$('#scrollLeft').removeClass('disabled');
			//alert('rightmost = ' + rightmost + ', scrollarealeft = ' + scrollarealeft);		
			//var scrollarealeft = Math.abs(parseInt($('#scrollAreaContent').css('left')));
			/*
			if (scrollarealeft >= rightmost) {
				$('#scrollRight').addClass('disabled');
			} else {
				$('#scrollRight').removeClass('disabled');
			}			
			*/
		//});
	}

	var scrollLeft = function() {
		leftClicksAvail -= 1;
		rightClicksAvail += 1;
		toggleScrollButtons();
		
		$('#scrollAreaContent').animate({
			left:'+=' + vidwidth	
		}, scrollspeed, 'swing');
	}
	
	$('#scrollLeft').click(function() {
		if (!$(this).hasClass('disabled')) {
			scrollLeft();
		}
	});
	
	$('#scrollRight').click(function() {
		if (!$(this).hasClass('disabled')) {
			scrollRight();
		}
	});
	
}

var main_init = function()
{
	//alert('inside main_init');	
	photo_gallery_init();
	nav_hover_init();
	
	//healthgrades_init();
	homepage_init();
}

jQuery().ready(main_init);