// JavaScript Document
(function($){
	$.fn.clearinput = function() {  
		this.each(function() {
			$(this).attr('title', $(this).attr('value'));
			$(this).focus(function() {
					if($(this).attr('value') == $(this).attr('title')) {
						$(this).attr('value', '');
					}
				}).blur(function() {
					if($(this).attr('value') == "") {
						$(this).attr('value', $(this).attr('title'));
					}
				});
			$('textarea', this).focus(function() {
					if($(this).html() == $(this).attr('title')) {
						$(this).html('');
					}
				}).blur(function() {
					if($(this).html() == "") {
						$(this).html($(this).attr('title'));
					}
				});
		});
	};  
})(jQuery); 

$(document).ready(function() {
						   
	// google analytics
	$('a[rel="external"]').click(function() {
		// remove "http://" or "https://" from the URL
		var href = $(this).attr('href').replace(/https?:\/\//,'');
		// track the URL under the "outgoing" page namespace in GA
		pageTracker._trackPageview('/outgoing/' + href);
	});
							  
	$('input[name*="signup"]').click(function() {
		pageTracker._trackPageview('/sign-up/thankyou/');
	});
							  
	$('input[name="update"]').click(function() {
		pageTracker._trackPageview('/shopping-bag/update/');
	});
							  
	$('input[name="checkout"]').click(function() {
		pageTracker._trackPageview('/shopping-bag/checkout/');
	});
							  
	// models
	$('#models a').lightBox({
		imageBtnClose: '/workspace/images/lightbox-btn-close.gif',
		imageBtnNext: '/workspace/images/lightbox-btn-next.gif',
		imageBtnPrev: '/workspace/images/lightbox-btn-prev.gif',
		imageLoading: '/workspace/images/lightbox-ico-loading.gif'
	});
	
	// fb 
	setTimeout("$('#fb').animate({width: 'toggle'}, 2000);", 2000);
  	
	// shopping bag
	$('#zip').css('display', 'none');
	$('#promo-code').css('display', 'none');
	
	$('#country').change(function(){
		if($('#country').val()=='United States') {
				// show the relating hidden field.
				$('#zip').css('display', 'inline');
			} else {
				// hide the relating hidden field.
				$('#zip').css('display', 'none');
			}
	});
	
	$('#promo').click(function(){
		// show the relating hidden field.
		$('#promo-code').css('display', 'inline');
	});
	
	$('#zip').clearinput();
	$('#promo-code').clearinput();
});
