(function($) {
  
  var browserWarning = function($element) {
    
    function init() {
      warn();
    }
    
    function warn() {
      browser_version = $.browser.version.split('.');
      if (($.cookie("browserWarned") != "yesx") && ($.browser.msie || ($.browser.mozilla && (new Number(browser_version[0])) < 1  && (new Number(browser_version[0])) < 9 && (new Number(browser_version[0])) < 2))) {
        $('#warningcontainer').show();
        $('#warningcontainer').load('/browser_warning', function() { $('#browserwarnack').click(function() { acknowledge() }) });
      }
    }

    function acknowledge() {
      $.cookie("browserWarned", "yes");
      $('#warningcontainer').hide();
    }

    init();
  };

  // jQuery plugin method
  $.fn.browserWarning = function() {
    return this.each(function() {
      var $this = $(this);
      
      // If not already stored, store plugin object in this element's data
      if (!$this.data('browserWarning')) {
        $this.data('browserWarning', browserWarning($this));
      }
    });
  };
})(jQuery);

$(document).ready(function() {
  $(document).browserWarning();
  
	Cufon.replace('h1, .content h2, h2');
	Cufon.replace('.pb101 h3', {
		textShadow: '0 1px 0 #f2f4f5'
	});
	Cufon.replace('.nav.site li a', {
		textShadow: '0 1px 0 #dcdfe2',
		hover: false
	});
	Cufon.replace('.nav.site li.current a', {
		textShadow: '0 1px 1px #6d6e71',
		hover: false
	});
	Cufon.replace('.nav.image li a', {
		textShadow: '0 1px 0 rgba(255, 255, 255, 0.25)',
		hover: {
			color: '#ffffff',
			textShadow: '0 1px 1px #222222'
		}
	});
	Cufon.replace('ul.cufontext', {
	  textShadow: '0px 1px 0px #333'
	  }
	);
	Cufon.replace('h1', {
    textShadow: '0px 1px 0px #fff'
    }
  );
 	Cufon.replace('#subheader h1', {
    textShadow: '0px 1px 0px #111',
		hover:true
    }
  );
	Cufon.replace('#subheader-nav a:not(.fb_share, .subheader-nav-extra, .export-types-container a)', {
    textShadow: '0px 1px 0px rgba(255,255,255,0.5)',
		hover:true
    }
  );
	Cufon.replace('.subheader-nav-extra:not(.export-types-container a)', {
    textShadow: '0px 1px 0px rgba(0,0,0,0.5)',
		hover:true
    }
  );
	Cufon.replace('h2.cufontext', {
    textShadow: '0px 1px 0px #fff'
    }
  );
	Cufon.replace('.last-route-info-pane h2.cufontext', {
    textShadow: '0px -1px 0px rgba(0,0,0,0.3)'
    }
  );
  Cufon.replace('h5.cufontext', {
    textShadow: '0px 1px 0px #fff'
    }
  );
	Cufon.replace('.cyclist-plans', {
    textShadow: '0px -1px 0px rgba(0,0,0,0.2)'
    }
  );
	Cufon.replace('.error-page h1', {
    textShadow: '0px 2px 3px rgba(0,0,0,0.2);'
    }
  );
	$('input.hint, textarea.hint').hint
	
	/* Dashboard Fakery */
	
	$(".rider-radar-map-small").click(function(){
			$(this).hide();
			$(".rider-radar-map").show();
			$(".main-container-column").addClass("large-map-open");
			$(".rider-radar-header").hide();
	});
	
	$(".rider-radar-map").click(function(){
			$(this).hide();
			$(".rider-radar-map-small").show();
			$(".main-container-column").removeClass("large-map-open");
			$(".rider-radar-header").show();
	});
	
	$("#new-event-1").delay(5000).fadeIn();
	$("#new-event-2").delay(20000).fadeIn();
	$("#new-event-3").delay(40000).fadeIn();
		
	/* Comment Tree Shenanigans */	
	
	$(".new-comment-3").delay(25000).fadeIn(function(){
		$(this).html("comments (1)");
		$("#comment-tree-1").fadeIn();
		});
	$(".new-comment-3").delay(30000).fadeIn(function(){
		$(this).html("comments (2)");
		$("#comment-2").fadeIn();
		});
	
	$(".new-comment-3").click(function(){
			$("#comment-tree-1").toggle();
	});
	
	
	
	$(".new-comment-1").delay(7500).fadeIn(function(){
		$(this).html("comments (1)");
		});
	$(".new-comment-1").delay(10000).fadeIn(function(){
		$(this).html("comments (2)");
		});
		
	$(".new-comment-2").delay(50000).fadeIn(function(){
		$(this).html("comments (1)");
		});
	$(".new-comment-2").delay(90000).fadeIn(function(){
		$(this).html("comments (2)");
		});	
});

/* Date/Time Functions */
function seconds_to_time_string(seconds) {
  hours = Math.floor(seconds / (60 * 60.0));
  minutes = Math.floor((seconds % (60 * 60)) / 60.0);
  if (minutes < 10) { minutes = '0'+minutes }
  seconds = Math.round(seconds % 60);
  if (seconds < 10) { seconds = '0'+seconds }
  s = minutes+':'+seconds;
  if (hours > 0) { s = hours+':'+s }
  return s;
}

function seconds_to_short_time_string(seconds) {
  hours = Math.floor(seconds / (60 * 60.0));
  minutes = Math.floor((seconds % (60 * 60)) / 60.0);
  seconds = Math.round(seconds % 60);
  
  if (hours > 0) {
    return hours+'hr';
  }
  if (minutes > 0) {
    return minutes+'m';
  }
  return seconds+'s';
}

