// JavaScript Document

$('.btp').click
(
 	function ()
		{
					$('html,body').animate({scrollTop: 0}, 2000);
					return false;
		}
);

$('.promo').animate({opacity: 'show', width: 'show'},'slow');

$('.loginform input.rtb, .buyform input.rtb').each
(
 	function ()
		{
			$(this).attr('autocomplete','off');
			this.value = '';
			this.dv = this.value;
		}
);

$('#qsearch, .footer input.tb, .contact input.tb').each
(
 	function ()
		{
			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;
						}
				);				
		}
);

$('#qsearch, .footer textarea.tb, .contact textarea.tb').each
(
 	function ()
		{
			var dv = this.innerHTML;
			this.dv = dv;
			$(this).focus
				(
				 	function ()
						{
							if (this.innerHTML==dv)
								this.innerHTML = '';
						}
				);
			$(this).blur
				(
				 	function ()
						{
							if (this.innerHTML=='') this.innerHTML = dv;
						}
				);				
		}
);



$('.buynow2').each
(
 	function ()
		{
			var url = this.title;
			this.title = "Click to Buy Now";
			$(this).click
			(
			 	function ()
					{
					location.href = url;
					}
			);
		}
);

$("div.onsale").each
(
	function ()
	{
		var swf = this.title;
		$(this).removeAttr('title');
		var obj = this;
		var url = $(obj).parent().attr('href');
		$(obj)
		.css('z-index','999');
		if (!url) url = $(this).next().attr('href');
	   var so = new SWFObject(root+'media/flash/' + swf + '.swf', "onsale"+swf, "239", "289", "8", "#ffffff");
	   so.addParam("loop", "false");
	   so.addParam("wmode", "transparent");
	   so.addParam("menu", "false");
	   so.addVariable("go", url);
	   so.write(this);			
		
	}
);

$(".prodgallery a, .diagram a").hover
(
 	function ()
	{
		$('.magnify',this).addClass('vmagnify');
	},
	function ()
	{
		$('.magnify',this).removeClass('vmagnify');
	}
);

$(".fsect form, form.loginform, .contact form").submit
(
 	function ()
		{
			if (!validate(this)) return false;
			var dt = $(this).serializeArray();
			var form = this;
			$('.fields',this).slideUp();
			$('.response',this).html("<div class='load'>Processing, please wait...</div>");
			$.post
				(
				 	root + 'main/post',
					dt,
					function (data)
						{
							$('.response',form).html(data + "<p><a href='#' onclick='return resetform(this)'>Submit another?</a></p>");
							$('a',form).trigger('focus');
						}
				);
			return false;
		}
);

$("form.buyform").submit
(
 	function ()
		{
			if (!validate(this)) return false;
			var dt = $(this).serializeArray();
			var form = this;
			window.scrollTo(0,100);
			$('.fields',this).slideUp();

			$.post
				(
				 	root + 'main/post',
					dt,
					function (data)
						{
							$('.response',form).html(data);
						}
				);

			$('.response',this).html("<div class='load'>Processing, please wait...</div>");
			return false;
		}
);

$('.copyabove').click
(
 	function ()
		{
			if (!this.checked) {
			$('#dfullname').val('');
			$('#dphone').val('');
			$('#dstreet').val('');
			$('#dcity').val('');
			$('#dstate').val('');
			$('#dzip').val('');
			} else {
			$('#dfullname').val($('#nfullname').val());
			$('#dphone').val($('#nphone').val());
			$('#dstreet').val($('#street').val());
			$('#dcity').val($('#city').val());
			$('#dstate').val($('#state').val());
			$('#dzip').val($('#zip').val());
			}
		}
);

function resetform(from)
{
	var form = $(from).parents('form');
	$(form).trigger('reset');
	$('.fields',form).fadeIn('normal',function () {$('.rtb:first',form).trigger('focus');} );
	$('.response',form).empty();
	
	return false;
}

$(".search form").submit
(
 	function ()
		{
			location.href = root + 'search/' + $('#qsearch').val();
			return false;
		}
);
	
$('.mainflash').each
(
 	function ()
		{
		   var so = new SWFObject(root+"media/flash/main.swf", "mainf", "500", "280", "8", "#ffffff");
		   so.addParam("loop", "false");
		   so.addParam("wmode", "transparent");
		   so.addParam("menu", "false");
		   so.write(this);			
		}
);

$('.movie').each
(
 	function ()
		{
		   var so = new SWFObject(root+"media/flash/player.swf", "movief", "230", "150", "8", "#ffffff");
		   so.addParam("loop", "false");
		   so.addParam("wmode", "transparent");
		   so.addParam("menu", "false");
		   so.addVariable("loc", root);
		   so.addVariable("vid", 1);
		   so.write(this);			
		}
);		