$.widget("rwha.members", {
	// default options
	options: {
		debug:	true,
		showDirectory: false
   	},
	_init: function() {
		$("#mainNav ul").megamenu();	
/*
		$('#directoryBtn').click(function() { 
			$('#directory').slideToggle('fast'); 			
			$('#directoryBtn').toggleClass('open'); 
			return false; 
		})
*/
//		$("#mainContent input[itemRel!=nouniform], #listContent input[itemRel!=nouniform], #directory select, #mainContent textarea, #listContent textarea, select, #mainContent button[itemRel!=nouniform], input:checkbox, input:radio").uniform(); 
		$("#mainContent input[itemRel!=nouniform], #directory select, #mainContent textarea, select, #mainContent button[itemRel!=nouniform], input:checkbox, input:radio").uniform(); 
		$(".uniform input[itemRel!=nouniform], .uniform textarea").uniform(); 
		$('#jclock').jclock();
		$("a[rel^='prettyPhoto']").prettyPhoto({ keyboard_shortcuts: false });
		//$('img').jcaption({ copyStyle: true, animate: true, show: {height: "show"}, hide: {height: "hide"} });
		if (this.options.showDirectory) { $('#directory').show(); }
		$('#hmGallery').cycle({
			fx:     'scrollHorz',
			timeout: 0,
			prev:    '#hmGallery .prev',
			next:    '#hmGallery .next',
			slideExpr: '.galSlide'
		 });
/*
		 $('#midGallery').cycle({
			fx:     'scrollHorz',
			timeout: 0,
			prev:    '#midGallery .prev',
			next:    '#midGallery .next',
			slideExpr: '.galSlide'
		});
*/
/*
		$('#midGallery').each(function() {
			var $gal = $(this);
			 $gal.cycle({
				fx:     'scrollHorz',
				timeout: 0,
				prev:    $('.prev', $gal),
				next:    $('.next', $gal),
				slideExpr: $('.galSlide', $gal)
			});
		});
*/
		$('#midGallery').each(function() {
			var $this = $(this);
			var $scrollerDiv = $this.children('div').eq(0);
        
			var scrollerLength = $('li', $scrollerDiv).length;
			if (scrollerLength > 2)
			{
				$scrollerDiv.jCarouselLite({
					circular: true,
					visible: 2,
					scroll: 1,
					btnPrev: $('a.prev', $this),
					btnNext: $('a.next', $this),
					speed: 1000
				});
			}
			else
			{
				$('a.prev,a.next', $this).click(function() { return false; });
			}
		});

		//$('.sub').bgiframe();
		//$.pop();
   	},
	welcome: function () {
		$('#slideshow').cycle({ fx:'scrollHorz', timeout:20000, prev:'#slideshow .prev', next:'#slideshow .next', slideExpr:'.feature', containerResize: false });	 
		$('#comNews').cycle({ fx:'scrollHorz', timeout:0, prev:'#comNews .prev', next:'#comNews .next', slideExpr: '.comSlide' });
		//$('.rightBanner').cycle({ fx:'fade', timeout: 20000, slideExpr: 'a' });
		$('#comNews').cycle({
			fx:     'scrollHorz',
			timeout: 0,
			prev:    '#comNews .prev',
			next:    '#comNews .next',
			slideExpr: '.comSlide'
		});
		$('#hmGallery').cycle({
			fx:     'scrollHorz',
			timeout: 0,
			prev:    '#hmGallery .prev',
			next:    '#hmGallery .next',
			slideExpr: '.galSlide'
		 });
/*
		 $('#midGallery').cycle({
			fx:     'scrollHorz',
			timeout: 0,
			prev:    '#midGallery .prev',
			next:    '#midGallery .next',
			slideExpr: '.galSlide'
		 });
*/
		 $('#endorsement').cycle({
			fx:     'fade',
			timeout: 6000,
			slideExpr: 'h1'
		 });
	},
	sitemap: function () {
		$(".sitemap ul").css("opacity", "0.5");
		$(".sitemap ul").sitemap({ fadeColor: "#362b40" });
		$(".sitemap ul ul").sitemap({ fadeColor: "#354668" });
		$(".sitemap ul ul ul").sitemap({ fadeColor: "#304531" });
		$(".sitemap ul ul ul ul").sitemap({ fadeColor: "#72352d" });
	}
});
// Scroll to top funcitons
$(function () { // run this code on page load (AKA DOM load)
 
	/* set variables locally for increased performance */
	var scroll_timer;
	var displayed = false;
	var $message = $('#infscr-top');
	var $window = $(window);
	var top = $(document.body).children(0).position().top;
 	
 	$message.hide();
	/* react to scroll event on window */
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // use a timer for performance
			if($window.scrollTop() <= top) // hide if at the top of the page
			{
				displayed = false;
				$message.fadeOut(500);
			}
			else if(displayed == false) // show if scrolling down
			{
				displayed = true;
				$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
			}
		}, 100);
	});
});
// Sitemap
jQuery.fn.sitemap = function(settings) {

    // if no paramaters supplied...
   settings = jQuery.extend({
      fadeColor: "black",
      duration: 200,
      fadeOn: 0.95,
      fadeOff: 0.5
   }, settings);

    var duration = settings.duration;
    var fadeOff = settings.fadeOff;
    var fadeOn = settings.fadeOn;
    var fadeColor = settings.fadeColor;

    $(this).hover(function(){
     $(this)
         .stop()
         .data("origColor", $(this).css("background-color"))
         .animate({
             opacity: fadeOn,
             backgroundColor: fadeColor
         }, duration)
   }, function() {
     $(this)
         .stop()
         .animate({
             opacity: fadeOff,
             backgroundColor: $(this).data("origColor")
         }, duration)
   });

};
// Gravatar
$.gravatar = function(emailAddress, overrides) {
    // Defaults are not hardcoded here in case gravatar changes them on their end.
    var options = {
        // integer size: between 1 and 512, default 80 (in pixels)
        size: '',
        // rating: g (default), pg, r, x
        rating: '',
        // url to define a default image (can also be one of: identicon, monsterid, wavatar)
        image: 'identicon'
    };
	console.log("Gravatar");
    $.extend(options, overrides);

    var img = 'http://www.gravatar.com/avatar/' + hex_md5(emailAddress) + '.jpg?' + (options.size ? 's=' + options.size + '&' : '') +
        (options.rating ? 'r=' + options.rating + '&' : '') +
        (options.image ? 'd=' + encodeURIComponent(options.image) : '');
	console.log(img);

    return img;
};

