/* default template js */
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$(document).ready(function()
{

	if ( $('#menu').length )
	{
		$('#menu li').hover(function(){
			//$(this).children().css({'color':'#ffffff','text-shadow':'#003333 2px 2px 1px'});
			//$(this).addClass('menu-over')
			return false;
			},
		function(){
			//$(this).children().css({'color':'#ffffff','text-shadow':'#064268 1px 1px 1px'});
			//$(this).removeClass('menu-over');}
			return false;
			}
			);
	}

	/* prefill search button */
	if ( $('#searchterm').val()=='' )
	{
		input_show_default('#searchterm', 'Search..');
	}

	/* support for accordion */
	if($(".accordion").length)
	{
		$(function() {
			$(".accordion").accordion({
				active: false,
				collapsible: true,
				autoHeight: true,
				clearStyle: true
			});
		});
	}

	/* lightbox gallery support for CMS */
	if($(".seriesLightbox").length)
	{
		$(function()
		{
			var lightbox2 = $(".seriesLightbox").ariaLightbox({
				imageArray: [],
				altText: "alt",
				descText: "title",
				useDimmer: true,
				pos: "auto",
				autoHeight: 100,
				title: "Gallery",
				em: false
			});

		});
	}

	/* support for tabs */
	if($(".tabs").length)
	{
		$(".tabs").tabs();
	}

	if($(".slideshow").length)
	{
		$('.slideshow').cycle({
			prev:   '#prev',
			next:   '#next',
			timeout: 5000
		});
	}

	// set cookie by date
    $('a#sampleok').click(function() {
    	$('#sample_dialog').hide();
        $.cookie('sample_acknowleged', 1);
        return false;
    });



	/* Page rating stats */
	if($(".rating").length)
	{
		var page_id = $('.rating').attr('id');

//		if(!$.cookie(page_id))
//		{
			$('.rating').rater({ postHref: 'rate/page' });
//		}
	}
	/* page commenting  */
	if($("form.page_comment").length)
	{
		$("form.page_comment").submit(function()
		{


//			$(this).remove();

			return false;
		});

	}


	/* page commenting  */
	if($(".submit_comment").length)
	{
		$(".submit_comment").click(function()
		{
			$.ajax({
				   type: "POST",
				   url: "/comment/page/item_id/"+$(this).attr('id').replace('_comment', '').replace('page_', ''),
				   data: {body: $(".page_comment textarea[name='body']").val(), data: $(".page_comment input[name='data']").val() },
				   beforeSend: function(){
					   if($(".page_comment textarea[name='body']").val()=="")
					   {
						   if(!$("table#comment_table tr#comment_notice").length)
						   {
							   $("table#comment_table tr:first").before('<tr id="comment_notice"><td></td><td><span>Please fill in the comments box before sending.</span></td></tr>')
							  // alert('here');
						   }
						   return false;
					   }
					},
				   success: function(msg){
						 $(".page_comment").replaceWith('Your comment has been submitted for approval.');
				}

			});


			return false;
		});

	}

	/* Comment body area */
	if($("textarea.comment_body").length)
	{

//		$("textarea.comment_body").focus(function(evt)
//		{
//			$(this).css({'height': '30px'});
//		});
//
//		$(".field .comment_body").blur(function(evt)
//		{
//			if($(this).val()=='')
//			{
//				$(this).css({'height': '30px'});
//			}
//
//		});

		$("textarea.comment_body").autogrow();
	};
	if($("span#count_before").length)
	{
		countdown(2010,02,28,$("span#count_before").text(),$("span#count_today").text());
	};

	/* Comment body area */
	if($("#custom").length)
	{
		$("#content_center").css('height', $("#content_right").height());
	}

	/* let's make the columns the same length */
	/* autoresizing height */
	/*
	 * There are three columns content_left, content_center, content_left
	 * This only matters if they have a class of cms_content_1
	 * We only need content_left and content_center to be same length
	 *
	 */
	if($('#content_center').length && $('#content_center').attr('class')=='cms_content_1')
	{
		var leftColheight = 0;
		var centerColheight = 0;
		var rightColheight = 0;
		var max = 0;
		var adjust = true;
		if($('#content_left').css('display') != 'none')
		{
			 leftColheight = $("#content_left").outerHeight();
			 max = leftColheight;
		}
		if($('#content_center').css('display') != 'none')
		{
			 centerColheight = $("#content_center").outerHeight();
			 if(centerColheight > max)
			 {
				 max = centerColheight;
			 }
		}
		if($('#content_right').css('display') != 'none')
		{
			 rightColheight = $("#content_right").outerHeight();
			 if(rightColheight > max - 10)
			 {
				 max = rightColheight - 10;
			 }
			 else
			 {
				 adjust = false;
			 }
		}
		if(adjust)
		{
			if($('#content_left').css('display') != 'none')
			{
				$("#content_left").css("height", max);
			}
			if($('#content_center').css('display') != 'none')
			{
				$("#content_center").css("height", max);
			}
			if($('#content_right').css('display') != 'none')
			{
				$("#content_right").css("height", max);
			}
		}
	}
	if(!$("form#take_action_form").length && !$("#special-home").length)
	{

		/* autoresizing height */
		if($(".left_col").length)
		{
			var divHeight = $(".left_col").outerHeight();
			/* also need to allow for 10px margin of top and bottom of main and 8px each for top and bottom cells */
			divHeight = parseInt(divHeight) - 36;
		}
		if($(".main").length)
		{
			var mainHeight = $(".main").outerHeight();
		}
		if(mainHeight && divHeight)
		{
			if(mainHeight < divHeight)
			{
				$(".main").css("height", divHeight);
			}
		}
	}
	/* end column resizing */
});


/* faq - show more */
function faq_show_more( span_id )
{
	$("#"+span_id).hide();
	$("#"+span_id+"_more").show();
}
/* faq - show more */
function show_comments( id )
{

	$("#"+id+"_comments").show();
}

