
jQuery = jQuery;

function switchTab()
{    
    if( jQuery(this).attr("id") == jQuery(document).currentJSTab )
        return; // do nothing
    jQuery("#" + document.currentJSTab + "Content").hide();
    jQuery("#" + document.currentJSTab).removeClass("jsTabSelected");
    document.currentJSTab = jQuery(this).attr("id");
    jQuery("#" + document.currentJSTab).addClass("jsTabSelected");
    jQuery("#" + document.currentJSTab + "Content").show();
	if (document.currentJSTab == "hoursTab") {
		mapLocator.loadMap();
	}
}

jQuery(document).ready(function (){
    jQuery(".jsTab").each(tabBuilder); 
    jQuery(".jsTab:first").addClass("jsTabSelected");
    jQuery( ".jsTab" ).bind( "click", switchTab );
    document.currentJSTab = jQuery(".jsTab:first").attr('id');
    jQuery("#" + document.currentJSTab + "Content").show();
	
	// Get rid of the original text on the "calculate button"
	jQuery("#paymentCalculatorButton").val('');
	jQuery("#paymentCalculatorButton").hover(function() {
		jQuery(this).css({'background-position' : '-141px 0px'});
	} , function() {
		jQuery(this).css({'background-position' : '0px 0px'});
	});
});

function quickSearch(){
	var postParameters="cellName=searchWidget1&pageName=HomePage";
	jQuery.ajax({
              type: "POST",
              dataType: "html",
              async: "false",
              data: postParameters,
              url: "widget_wrapper.do?actionMapping=quick_search.do",
              success: function(data) {
                    jQuery("#quicksearchWidgetContent").html("");
                    jQuery("#quicksearchWidgetContent").append(data);
              },
              error: function() {
		           //Do nothing
              }
        });	
}

function tabBuilder(){
    // if this is the dealer editable tab w/o text, then don't show.
    if(!jQuery(this).text())
    {
        jQuery(this).addClass("hidden");
        return;
    }
    // create the 'new' elements
    var tabRightEdge = jQuery("<div>");
    var tabText = jQuery("<div>");
    var tabLeftEdge = jQuery("<div>");
    // stylize
    tabLeftEdge.addClass("tabLeftEdge");
    tabText.addClass("tabText");
    tabRightEdge.addClass("tabRightEdge");
    jQuery(this).addClass("clearfix");
        
    tabText.text(jQuery(this).text());
    jQuery(this).text("")
    jQuery(this).append(tabLeftEdge);
    jQuery(this).append(tabText);
    jQuery(this).append(tabRightEdge);
}

