jQuery(document).ready(function($) {

	/*------------------------------------------------------------*/
	
	// Allow for wide templates
	if (typeof layout_type == "undefined") layout_type = "standard";
	if (layout_type == "wide")
		$('#content_middle').addClass('wide');
	

	/*------------------------------------------------------------*/
	$('#nav li')
	.hover(function() {
		$(this).addClass('selected_hover').find('ul:first').show();
	}, function() {
		$(this).removeClass('selected_hover').find('ul').hide();
	});

	$('#nav li').each(function() { $(this).find('ul').hide(); });
	$('#nav li ul li ul').each(function() {	$(this).parent().addClass('menuMore'); });

	/*------------------------------------------------------------*/

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(2000);

	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		$('#mask').hide();
		$('.window').hide();
	});

	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});


	$('h1').each(function(){
		 var me = $(this);
		 me.html(me.html().replace(/^(\w+)/, '<span>$1</span>'));
	});


	/*------------------------------------------------------------*/

	$('#nav a:first').addClass('first');
	var sWidth = 0;	var cWidth = 0;	var count = 0;	var wCount = 0; var lastEl = "";
	$('ul#nav > li > a').each(function () {
		count = count +1;
		cWidth = cWidth + parseInt($(this).width());
		lastEl = this;
	});
	sWidth = parseInt((899 - cWidth)/count);
	/* 920 less 20 left padding less 1 for good measure */

	$('ul#nav > li > a').each(function () {
		wCount = parseInt($(this).width());
		//alert(wCount+sWidth + "px");
		$(this).css('width', wCount+sWidth + "px");
	});
	//alert(parseInt($(lastEl).width())+"px");
	$(lastEl).css('width', parseInt($(lastEl).width())+"px");
	//$(lastEl).css('padding-right','auto');

	/*------------------------------------------------------------*/

	$("[placeholder]").focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr("placeholder")) {
		input.val("");
		input.removeClass("placeholder");
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == "" || input.val() == input.attr("placeholder")) {
		input.addClass("placeholder");
		input.val(input.attr("placeholder"));
	  }
	}).blur();

	$("[placeholder]").parents("form").submit(function() {
	  $(this).find("[placeholder]").each(function() {
		var input = $(this);
		if (input.val() == input.attr("placeholder")) {
		  input.val("");
		}
	  })
	});

	/*------------------------------------------------------------*/

});


