/* COMMON LEXUS DOM */


$(".ebrochure").click(function(e){
		$(".modalWindow")
			.load(this.href + ' #ebrochure-container', function(){
			modalShow();
			$('.modalWindow form').jqTransform();
			});
	return false;
});

/* Adds maxlength to text areas */
$(document).ready(function(){
	$('textarea[maxlength]').keyup(function(){
		var max = parseInt($(this).attr('maxlength'));
		if($(this).val().length > max){
			$(this).val($(this).val().substr(0, $(this).attr('maxlength')));
		}
	});
});

/* Adds tooltip functionality */
$(document).ready(function(){
	toolTip = {
		init: function () {
			$(".tooltip-div").livequery(function() {
				$(this).tooltip({
					relative: true,
					effect: 'toggle',
					position: 'center left',
					offset: [0, 12],
					delay: 30,
					tipClass: "tooltip-content"
				});
			});
			$(".tooltip-title").livequery(function() {
				$(this).tooltip({
					relative: true,
					effect: 'toggle',
					position: 'center left',
					offset: [0, 12],
					delay: 30,
					tipClass: "tooltip-content"
				});
			});	 
		}
	}
});

/* Adds ajax load dialog */
$(document).ready(function() {
	busyDialog = {
		init: function () {
	  		var el = $(document.createElement('div')).attr('id', 'superimposedLoading');
	  		//$(el).prepend("<div><img src='/lexus/images/loadinga.gif' alt='Loading...' /></div>");
	  		$(el).ajaxStart(function(){
	      		$(this).show();
	   		});
	  		$(el).ajaxStop(function(){
	      		$(this).hide();
	   		});
	  	$('body').prepend(el);
	 	}
	}
	busyDialog.init();
});
/* Adds nav dropdown */
$(document).ready(function() {

	function showArrow(arrow){
		$(arrow).find('.top-arrow').show();	
	}
	function hideArrow(arrow){
		$(arrow).find('.top-arrow').hide();	
	}

	function addMega(){
	
	    $(this)
			.addClass('hovering')
			.find('.nav-vehicle-group')
			.show();
		}

	function removeMega(){
		var method1 = 'easeInSine';
		var method2 = 'easeOutSine';
	    $(this)
			.removeClass('hovering')
			.find('.nav-vehicle-group')
			.hide();
		}

    var megaConfig = {
         interval: 0,
         sensitivity: 3,
         over: addMega,
         timeout: 100,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig)
  
});

/* Global search bar text */
$(document).ready(function() {

	$("#searchbox .queryString").val("Search");
	$("#searchbox .queryString")
	.focus(function() {
		if($(this).val() == "Search"){
			$(this).val("");
		}	
	})
	.blur(function() {
		if($(this).val() == ""){
			$(this).val("Search");
		}				
	});
});


