$(document).ready(function(){

	/* dropdown navigation */

	$("ul.menu > li > ul.sub-menu").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.menu > li > a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.sub-menu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.sub-menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	/* sponsors carousel */
	
	$("#sponsors").jCarouselLite({
		visible: 10,
		auto: 2000,
		speed: 1000
	});
	
	
	/* rounded corners */
	
	$(".post_content img.rounded").each(function() {
		var img = $(this);
		
		// build wrapper
		var wrapper = $('<div class="rounded_wrapper"></div>');
		wrapper.width(img.width());
		wrapper.height(img.height());
		
		// move CSS properties from img to wrapper
		wrapper.css('float', img.css('float'));
		img.css('float', 'none');
		
		wrapper.css('margin-right', img.css('margin-right'));
		img.css('margin-right', '0');

		wrapper.css('margin-left', img.css('margin-left'));
		img.css('margin-left', '0');
		
		if (img.attr('class').indexOf("aligncenter") != -1) {
			wrapper.css('margin-left', 'auto');
			wrapper.css('margin-right', 'auto');
		}

		wrapper.css('margin-bottom', img.css('margin-bottom'));
		img.css('margin-bottom', '0');

		wrapper.css('margin-top', img.css('margin-top'));
		img.css('margin-top', '0');

		wrapper.css('display', 'block');
		img.css('display', 'block');
		
		if ($.browser.msie && $.browser.version.substr(0,1) > 8 || !$.browser.msie) {
			//adam's mod
			img.hide();
			wrapper.css("backgroundImage", "url('"+img.attr('src')+"')");
		}

		// wrap image
		img.wrap(wrapper);
		
		if ($.browser.msie && $.browser.version.substr(0,1) <= 8) {
			// add rounded corners
			img.after('<div class="tl"></div>');
			img.after('<div class="tr"></div>');
			img.after('<div class="bl"></div>');
			img.after('<div class="br"></div>');
		}
	});
	
	$(".post_content img.shadowed").each(function() {
		/*$(this).css("border-right", "solid 2px #ddd");
		$(this).css("border-bottom", "solid 2px #ddd");*/
		var opts = {
			left: 2,
			top: 2,
			blur: 2,
			opacity: 0.4,
			color: "#000"
		};
		$(this).css('background', '#000');
		$(this).dropShadow(opts);
	});
	
	
	/* event registration auto-fill */
	
	function getUrlVars() {
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for (var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
	var eventid = getUrlVars()["eventi"];
	var eventtitle = getUrlVars()["event"];
	var eventdate = getUrlVars()["eventd"];
	var eventvolunteers = getUrlVars()["eventv"];
	if (eventtitle.length >= 2) {
		$("#eventtitle").attr("readonly", "readonly");
		$("#eventtitle").val(decodeURIComponent(eventtitle.replace(/\+/g, ' ')));
	}
	if (eventdate.length >= 8) {
		var myDate = new Date(eventdate * 1000);
		$("#eventdate").attr("readonly", "readonly");
		$("#eventdate").val(myDate.toLocaleString());
	}
	if (eventvolunteers != null && eventvolunteers.length >= 1) {
		$("#eventvolunteers").live("keydown", function(event) {
			if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) {
			} else if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) {
				event.preventDefault();
			}
		});
		$("#eventvolunteers").live("keyup", function() {
			if (parseInt($(this).val()) > parseInt(eventvolunteers)) {
				var text = $(this).val();
				$(this).val(text.substring(0, text.length - 1));
			}
		});
	}
	$("#eventid").parents("tr").css({ visibility: "hidden" });
	$("#eventid").attr("readonly", "readonly");
	$("#eventid").val(eventid);

});
