$.fn.input = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			$(this).val("");
			$(this).addClass("focus");
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
			$(this).removeClass("focus");
		}
	});
};

(function($){

$.fn.placeholder = function(){

	return this.each(function(){

		var $this = $(this);
		
		$this.parents("form").attr("autocomplete","off");
		
		if($this.val() != "") {
			$this.prev().hide();
		}

		$this.keyup(function(){
			if($(this).val() == "")
				$(this).prev().show();
			else
				$(this).prev().hide();
		});
		$this.focusin(function(){
			if($(this).val() == "") {
				$(this).prev().addClass("focus").fadeTo(250,.4);
				$(this).addClass("focus");
			}
		});
		$this.focusout(function(){
			if($(this).val() == "") {
				$(this).prev().removeClass("focus").stop(true,true).css('opacity','1').show();
				$(this).removeClass("focus");
			}
		});
		$this.keypress(function(e){
			if (e.keyCode == '9') return;

			$(this).prev().hide();
		});

	});
};

})(jQuery);

$(document).ready(function(){
	$("a[rel='external']").click(function(){
		window.open(this.href);
		return false;
	});
	
	$('#chat-btn .btn').click(function(e){
		e.preventDefault();
	});
	
	$('#customers-images').cycle({
		fx:			'fade',
		timeout:	5000,
		speed:		1000,
		delay:		1000,
		backwards:	true
	});
	
	$('#drivers-images').cycle({
		fx:			'fade',
		timeout:	5000,
		speed:		1000,
		delay:		0,
		backwards:	true
	});
	
	// CLEAR INPUTS
	$('#footer-search input, #application textarea, #spot-rate textarea, #pod-request textarea').input();
	$('#application .placeholder :input').placeholder();
	$('#pod-request .placeholder :input').placeholder();
	
	// MAP TOOLTIPS
	$('#location-map li').mouseenter(function(){
		if($.browser.msie){
			$(this).children('div').css('display','block');
			$(this).css('z-index','2000');
		} else {
			$(this).children('div').fadeIn(250);
		}
	});
	
	$('#location-map li').mouseleave(function(){
		if($.browser.msie){
			$(this).children('div').css('display','none');
			$(this).css('z-index','1');
		} else {
			$(this).children('div').fadeOut(250);
		}
	});
	
	
	$('#location-map li a').fancybox({
		'overlayColor'	: '#000',
		'overlayOpacity': '0.5',
		'padding'		: 0,
		'margin'		: 0,
		'width'			: 523,
		'height'		: 390,
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'type'			: 'iframe'
	});
	
	
	// IE7 PSEUDO ELEMENT FIXES
	$('#footer-search button').mousedown(function(){
		$(this).addClass('active');
	});
	
	$('#footer-search button').mouseup(function(){
		$(this).removeClass();
	});
	
	
	// IE7 CSS SELECTOR FALLBACKS
	if($.browser.msie){
		$('#subnav-featured li:last-child').addClass('last');
		$('tbody tr:nth-child(2n)').addClass('even');
		$('#awards li:nth-child(3n) + li').addClass('break');
		$('tbody tr:last-child').addClass('last-row');
	}
	
	// APPLICATION TRACKING CODE
	$('a[href="https://intelliapp.driverapponline.com/c/superservice"]').each(function(){
		$(this).attr('onClick',"_gaq.push(['_trackEvent', 'Apply', 'Click', 'Apply Now']);");
	});
	
});
