$(function() {
	$('input[@type=text]').focus(function(){
		var currentVal = $(this).val();										// Read initial field value
		$(this).val('');														// Clear initial value

		$(this).blur(function(){
			var getNewVal = $(this).val();										// Read new input value
			if ( getNewVal == '' || getNewVal == ' ' ) {
				$(this).val(currentVal);										// Switch to initial value
			}
		});
	});	

	// Submit forms through A tag
	$('a.submit').click(function(){
		$('form#'+$(this).attr('rel')).submit();
	});

	// handle custom scrollbar on homepage
	if ( browser != "Safari" ) {
		if ( $('#paper .holder').length ) { $('#paper .holder').jScrollPane({wheelSpeed:24, scrollbarWidth: 13}); }
	}

	// open new windows
	$('a.new-window').click(function(){
        window.open(this.href,"_target","directories=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0");
        return false;
    });

	// handle new window width and height
	if ( $("body#popup").length ) {
		var getImage = $("img");
		var getText = $("div");

		var with_ = getImage.width()+65;
		var height_ = getImage.height()+getText.height()+190;

		top.resizeTo(with_,height_);
	}

	// handle paypal icon
	$('p#paymentagree').hide();
	$('input#accept_TOC').click(function(){$('p#paymentagree').toggle();});

	// open new windows
	$("a[target=_new], a[target=_blank]").click(function(){
		openwin($(this).attr('href'));
		return false;
	});

	$('table.products-tab td a.new-window').hover(
		function(){ $(this).children('img').css('background-color','#7ae7b3'); },
		function(){ $(this).children('img').css('background-color',''); }
	);
});

var detect = navigator.userAgent.toLowerCase();
var os_ = navigator.platform.toLowerCase();
var browser,thestring;

if (checkIt('safari')) browser = "Safari"
else browser = "not Safari"

if ( os_ == 'macppc' || os_ == 'macintel' ) os = "Mac"
else os = "not Mac"

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function openwin(url) {
	window.open(url,'','status=no,scrollbars=yes,top=50,left=150,width=800,height=460,address=no,location=no,menubar=no,resizable=yes,titlebar=no,toolbar=no');
}