$(function () {

	$.gaTracker('UA-6741087-2');

	var change_css = function(new_opt)
	{
		if (new_opt != undefined)
		{
			$('#css_type option:selected').val(new_opt);
			document.switch_css.submit()
		}
	};

	var set_required = function()
	{

		$('.required_input').each(function()
		{
			if (($(this).val() == '') || ($(this).val() == 'required'))
			{
				$(this).val('required').addClass('gray');
				$(this).parents('form').addClass('required_form');
			}
		});
	};

	set_required();

	/*---------------------------------------------------------------------------------------*/
	/* reset_required                                                                        */
	/*                                                                                       */
	/* if any of the required input field, contain the value 'required'                  	 */
	/* replace it with nothing before submitting to php for validation                       */
	/*---------------------------------------------------------------------------------------*/

	$.fn.reset_required = function()
	{
		$(this).each(function(event)
		{
			if ($(this).val() == 'required')
			{
				$(this).val('');
			}
		});
	}

	$('form.required_form').submit(function()
	{
		$(this).find('.required_input').reset_required();
	} );

	$('.required_input').focus(function()
	{
		if (this.value == 'required')
		{
			$(this).val('').removeClass('gray');
		}
	} );

	$('.required_input').blur(function()
	{
		if (this.value == '')
		{
			$(this).val('required').addClass('gray');
		}
	} );



	$('p.prev').click(function()
	{
		prev = $('#css_type option:selected').prev().val();
		if (prev == undefined)
		{
			prev = $('#css_type option:last').val();
		}
		change_css(prev);
	} );

	$('p.next').click(function()
	{
		next = $('#css_type option:selected').next().val();
		if (next == undefined)
		{
			next = $('#css_type option:first').val();
		}
		change_css(next);
	} );

	$('#css_type').change(function()
	{
		document.switch_css.submit()
	} );

	$('.css_type').click(function()
	{
		change_css($(this).children('h4').text().toLowerCase().replace(' ','_'));
	} );

	$('.all_comments').hide();

	$('.comments_link').click(function()
	{
		$(this).next().toggle('slow')
	} );

	$('.add_comment').click(function()
	{
		$(this).next().toggle('slow');
	} );


	$(document).ready(function()
	{
		var selected = ($('#css_type option:selected').val()).replace('.','');

		$(this).find('.'+selected).addClass('active_type');
	});
});