
	var frms = 2;
	var frm = 0;
	var fmax = 2;
	
	//cache first
	function loadPic()
	{
		frm += 1;
		
		if (frm>fmax) 
		{
		$('.frames').css('background','none');
		frm = 0;
		rotate();
		return true;
		}
		
		$('.frames').append('<img src="'+root+'media/images/f'+frm+'.jpg" style="visibility:hidden;" onload="loadPic()" />');
		
	}
	
	function rotate()
	{
		$('.frames img:visible').fadeOut();
		frm += 1;
		
		if (frm>fmax) frm = 1;
		$('.frames img:eq('+ (frm-1) +')').css({visibility:'visible',display:'none'}).fadeIn
		(
			function ()
				{
				setTimeout('rotate()',10000);
				}
		);
	}
	
	
	$(document).ready
	(
		function()
			{
			
			$('.vid').each
			(
			function ()
			{
			var vn = 1;
			var so = new SWFObject(root+"media/flash/player.3.swf", "movief", "320", "240", "9", "#000000");
			so.addParam("loop", "false");
			so.addParam("wmode", "window");
			so.addParam("menu", "false");
			so.addParam('allowFullScreen', 'true');
			so.addParam('scale', 'showall');
			so.addVariable("loc", root);
			so.addVariable('playme',2);
			so.addVariable("vid", vn);
			so.write(this);
			}
			);
			
			loadPic();
			
			}
	);
	
$('.form input.tb').each
(
 	function ()
		{
			$(this).attr('autocomplete','off');
			this.value = this.title;
			var dv = this.value;
			this.dv = dv;
			$(this).focus
				(
				 	function ()
						{
							if (this.value==dv)
								this.value = '';
						}
				);
			$(this).blur
				(
				 	function ()
						{
							if (this.value=='') this.value = dv;
						}
				);				
		}
);

$('.form textarea.ta').each
(
 	function ()
		{
			var dv = this.innerHTML;
			this.dv = dv;
			$(this).attr('autocomplete','off');
			
			$(this).focus
				(
				 	function ()
						{
							
							if (this.innerHTML==this.dv)
								$(this).html('');
							if (this.value==this.dv) this.value = '';
						}
				);
			$(this).blur
				(
				 	function ()
						{
							if (this.value=='') this.value = this.dv;
						}
				);				
		}
);

function showform(from,isReset) //show form if unsuccessful
{
	var form = $(from).parents('form');
	if (isReset) $(form).trigger('reset');
	$('.fields',form).fadeIn('normal',function () {$('.rtb:first',form).trigger('focus');} );
	$('.response',form).empty();
	return false;
}

function procJSON(json,form)
{
	
	var rs = json.response;
	switch (json.action)
	{
		case 'success': rs += "<br /><br /><p><a href='#' onclick='return showform(this,true)'>Submit again?</a></p>"; break;
		case 'retry': rs += "<br /><br /><p><a href='#' onclick='return showform(this,false)'>Submit again?</a></p>"; break;
		case 'reload': self.location.reload(); break;
	}
	$('.response',form).html(rs);
	$('.response a',form).trigger('focus');
	
}

$('.form').submit
(
	function ()
	{
			var form = this;
			if (!validate(form)) return false;
			var dt = $(this).serializeArray();
			var action = root+'main/post';
			$('.fields',this).slideUp('fast');
			$('.response',this).html("<div class='load'>Processing, please wait...</div>");
			
				$.ajax({
				   type: 'POST',
				   url: action,
				   data: dt,
				   dataType: 'json',
				   success: function(data){procJSON(data,form);}
				 });

			return false;
	}
);	
	