$(document).ready(function() {
	
	
	if($('.memberPageInformation').size() > 0) {
		$('.memberPageInformation').before('<strong>Hospital Statistics:</strong>');
		$(".memberPageInformation tr:odd").addClass('odd');
	}
	if($('#member_login').size() > 0) {
		var html = $('#member_login').get(0);
		$('#member_login').remove();
		$('#inner-content h1').after(html);
	}


	$(".calendarItems span h3 .itemday span").each(function() {
		var day = $(this).html();
		var time = $(this).parent().next().next("span").html();
		$(".pdcalendar li:not(.day):not(.empty)").each(function() {
			if ($(this).children("span").html() == day) {
				$(this).addClass("highlight");
				$(this).append("<br />" + time);
			}
		});
	});

	$(".pdcalendar li.highlight").hover(
		function() {
			$(this).css('background-color', '#C3D9FF');
		},
		function () {
				$(this).css('background-color', '#ddd9d9');
		}
	);
	$(".pdcalendar li.highlight").live('click', function() {
		var day = $(this).children("span").html();
		var first = 0;
		var offset = $(".calendarItems").offset().top;
		$(".calendarItems span h3 .itemday span").each(function() {
			$(this).parent().parent().parent().children().css('background-color', 'transparent');
			
			if ($(this).html() == day) {
				temp = $(this).parent().parent().parent().position().top; 
				$(this).parent().parent().parent().children().css('background-color', '#C3D9FF');
				if(temp > first)
					first = temp;
			}
		});
	//console.log(first + " " + offset + " " + " scroll to: " + $(".calendarItems").scrollTop());
		var scrollTo = first - offset - 5 + $(".calendarItems").scrollTop();
		$(".calendarItems").animate({scrollTop: scrollTo}, 1000);
	});
	
	$("#login").click(function() {
		var user = $("#PageContents_TB_User").val();
		var pass = $("#PageContents_TB_Password").val();
		var fo = '<form id="atomicLoginForm" method="POST" action="http://reports.gdaha.org/admin/default.aspx"><input type="hidden"  name="ctl00$PageContents$BTN_Login" value="Login"><input type="hidden" name="__EVENTTARGET" value=""><input type="hidden name="__EVENTARGUMENT" value=""><input type="hidden" name="__LASTFOCUS" value=""><input type="hidden" name="__VIEaWSTATE" value="/wEWBwLkgr6LCgK6956qDQLwq7P9BQKRyZuEBgKdi9zkCALf37W6BwL939XNDLCl5tg952UgtKG2ihyAUe3Etq6J"><input type="hidden" name="ctl00$PageContents$TB_User" value="' + user + '"><input type="hidden" name="ctl00$PageContents$TB_Password" value="' + pass + '"></form>';
		$("body").prepend(fo);
		$("#atomicLoginForm").submit();
    });
    
    $(".subpages li").each(function(index) {
		if (index == 10) {
			$(this).after("</div>");
		}
    });

      $("a[rel^='prettyPhoto']").prettyPhoto();
      var totalPics = $("a[rel^='prettyPhoto']").length;
      $("a[rel^='prettyPhoto']").each(function(index) {
		if(index == 0) {
			$(this).children('img').css('padding-left', 0);
		}
		$(this).children('img').css('float', 'none');
		
		if(index == 3 && totalPics > 4) {
			var obj = $("<img id='moreLink' src='/images/more.png' />");
			$(this).after(obj);
			$("#moreLink").click(function() {
				$($("a[rel^='prettyPhoto']")[4]).click();
			}).css('z-index', 100).css('position', 'absolute').css('cursor', 'pointer').css('float', 'none');
		}
        if (index >= 4) {
         $(this).hide();
        }
        
        if (index == (totalPics - 1)) {
         $(this).after("<div style='clear:both'></div>"); 
        }
      });

   if($("#map[alt]").length > 0) {
		$("#inner-content").css('position', 'relative');
	}
	if($("#voteVoiceRedirect").size() > 0) {
		location.href = 'http://votervoice.net/groups/gdaha';
	}
	if($("a[href='/advocacy/take-action']").size() > 0) {
		$("a[href='/advocacy/take-action']").attr('href', 'http://votervoice.net/groups/gdaha');
	}


});
