
(function ($) {
  
  /**
   * Expands the region specific dealership locatons on hover
   */
  Drupal.behaviors.domainMenu = {
    attach: function (context, settings) {
      $('#block-menu-menu-domain-links li.expanded').hoverIntent(
      function() {
        $('ul.menu', $(this)).slideDown('fast');
      },
      function() {
        $('ul.menu', $(this)).slideUp('fast');
      });
      $('#block-menu-menu-domain-links--2 li.expanded').hoverIntent(
      function() {
        $('ul.menu', $(this)).fadeIn('fast');
      },
      function() {
        $('ul.menu', $(this)).fadeOut('fast');
      });
    }
  };
  
  // Drupal.chromeImageGalleryLoadImage = function (response) {
  //   $('div.chrome_image_gallery_main_image').html(response.data);
  // }
  
})(jQuery);;
/*
  This file is added to every page and can be a used as
  a home for some basic javascript 
*/

(function ($) {
  Drupal.behaviors.vehicleFilterCheckboxes = {
    attach: function (context, settings) {
      $(".vehicle-compare-checked", context).click(function() {
        if (!$(this).children(".checkbox").hasClass('disabled')) {
          $(this).children(".checkbox").toggleClass("checked");
        }
      });
      $(".filter-results-reset-link", context).click(function() {
        $(".checkbox").removeClass("checked");
      });
    }
  }
  
  Drupal.behaviors.anchorScroll = {
    attach: function (context, settings) {
      $(".scroll").click(function(event){
    		//prevent the default action for the click event
    		event.preventDefault();

    		//get the full url - like mysitecom/index.htm#home
    		var full_url = this.href;

    		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
    		var parts = full_url.split("#");
    		var trgt = parts[1];

    		//get the top offset of the target anchor
    		var target_offset = $("#"+trgt).offset();
    		// Set the target_top, minus a bit for padding
    		var target_top = target_offset.top - 50;

    		//goto that anchor by setting the body scroll top to anchor top
    		$('html, body').animate({scrollTop:target_top}, 500);
    		
    		return false;
    	});
    }
  }
  Drupal.behaviors.readMore = {
    attach: function (context, settings) {
      $('.read-more-link').click(function() {
        $(this).parent().siblings('.more-text').show();
        $(this).parent().hide();
        return false;
      });
      
      $('.read-full-review-link').click(function() {
        
        if ($(this).siblings('.full-body').css('display') == 'none') {
          $(this).siblings('.stripped-body').hide();
          $(this).siblings('.full-body').show();
          $(this).html('HIDE FULL REVIEW');
        } else {
          $(this).siblings('.stripped-body').show();
          $(this).siblings('.full-body').hide();
          $(this).html('SHOW FULL REVIEW');
        }
        
        return false;
      });
    }
  }
  /*
    Add the class 'simple-dialog' to open links in a dialog
    You also need to specify 'rev="<selector>"' where the <selector>
    is the unique id of the container to load from the linked page.
    Any additional jquery ui dialog options can be passed through
    the rel tag using the format:
       rel="<option_name1>:<value1>;<option_name2>:<value2>;"
    e.g. <a href="financing/purchasing-options" class="simple-dialog" 
          rel="width:900;resizable:false" 
          rev="content-area" title="Purchasing Options">Link</a>
    NOTE: This method doesn't not bring javascript files over from
    the target page. You will need to make sure your javascript is
    either inline in the html that's being loaded, or in the head tag
    of the page you are on.
    ALSO: Make sure the jquery ui.dialog library has been added to the page
  */
  Drupal.behaviors.simpleDialog = {
    attach: function (context, settings) {
      // Create a container div for the modal if one isn't there already
      if ($("#simple-dialog-container").length == 0) {
        $('body').append('<div id="simple-dialog-container" style="display:none;"></div>');
        try {
          $( "#simple-dialog-container", context).dialog({
            autoOpen: false,
            modal: true,
            position: ['center', 60]
          });
        }
        catch (err) {
          return;
        }
      }
      $('a.simple-dialog', context).click(function(event) {
        // prevent the navigation
        event.preventDefault();
        var url = this.href;
        var options = this.rel.split(';');
        var title = this.title;
        var selector = this.rev;
        var option = null;
        $('#simple-dialog-container').dialog('option', 'title', title);
        $('#simple-dialog-container').html('<div class="ajax-loader-white"></div>');
        $('#simple-dialog-container').dialog('option', 'height', 200);
        $('#simple-dialog-container').load(url + ' #' + selector, function() {
          for (var i in options) {
            if (options[i]) {
              option = options[i].split(':');
              $('#simple-dialog-container').dialog('option', option[0], option[1]);
            }
          }
          $('#simple-dialog-container').dialog('option', 'position', ['center', 60]);
          $('#simple-dialog-container').dialog('option', 'height', 'auto');
          Drupal.attachBehaviors($('#simple-dialog-container'));
        });
        $('#simple-dialog-container').dialog('open');
    		return false;
      });
    }
  }
  
  Drupal.behaviors.activeTrail = {
    attach: function (context, settings) {
      $('#sidebar-first');
    }
  }
})(jQuery);;
/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image want to use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked, checked,
checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

(function ($) {

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

/*
  Replace the window.onload event handler with
  our own drupal behavior so that it gets run on
  AJAX callbacks as well
*/
Drupal.behaviors.addCustomCheckboxes = {
  
  attach: function (context, settings) {
    if (!$('#content .view-models').hasClass('customCheckboxes-Processed')) {
      $('#content .view-models').addClass('customCheckboxes-Processed');
      Custom.init();
    }
    /*
      We need to disable the checkboxes if there is three already selected
    */
    $('.vehicle-compare-checked .checkbox', context).each(function() {
      var element = this.nextSibling;
      var nid = element.value;
      $(this).hover(
        function() {
          var count = 0;
          $('input.vehicle-compare-checkbox').each(function() {
    				if ($(this).attr('checked')) {
    					count++;
    				}
    			});
    			if (count >= 3 && !$(this).hasClass('checked')) {
    			  $(this).addClass('disabled');
            $('#vehicle-compare-checked-'+nid+' .tooltip-inner').html('You can only select 3 vehicles to compare at a time.  Deselect one of the other vehicles to compare this one');
    				$('#vehicle-compare-checked-'+nid+' .tooltip').fadeIn('slow');
  				}
        },
        function() {
          $('#vehicle-compare-checked-'+nid+' .tooltip').fadeOut('slow',function(){
            $('#vehicle-compare-checked-'+nid+' .tooltip-inner').html('');
          });
          $(this).removeClass('disabled');
        }
      )
    });
  }
  
}

/* No need to change anything after this */


document.write('<style type="text/css">input.vehicle-compare-checkbox { display: none; } select.vehicle-compare-checkbox { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "vehicle-compare-checkbox") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "vehicle-compare-checkbox") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
	  if (!$(this).hasClass('disabled')) {
		  element = this.nextSibling;
  		if(element.checked == true && element.type == "checkbox") {
  			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
  		} else if(element.checked == true && element.type == "radio") {
  			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
  		} else if(element.checked != true && element.type == "checkbox") {
  			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
  		} else {
  			this.style.backgroundPosition = "0 -" + radioHeight + "px";
  		}
  	}
	},
	check: function() {
	  if (!$(this).hasClass('disabled')) {
		  element = this.nextSibling;
  		nid = element.value;
  		if(element.checked == true && element.type == "checkbox") {
  			this.style.backgroundPosition = "0 0";
  			element.checked = false;
  		} else {
  			if(element.type == "checkbox") {
					this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
					element.checked = true;
  			} else {
  				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
  				group = this.nextSibling.name;
  				inputs = document.getElementsByTagName("input");
  				for(a = 0; a < inputs.length; a++) {
  					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
  						inputs[a].previousSibling.style.backgroundPosition = "0 0";
  					}
  				}
  				element.checked = true;
  			}
			
  		}
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "vehicle-compare-checkbox") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "vehicle-compare-checkbox") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "vehicle-compare-checkbox") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "vehicle-compare-checkbox") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
//window.onload = Custom.init;

})(jQuery);;
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);;
/**
 * jquery.numberformatter - Formatting/Parsing Numbers in jQuery
 * Written by Michael Abernethy (mike@abernethysoft.com)
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 1/26/08
 *
 * @author Michael Abernethy
 * @version 1.1.0
 *
 *
 * This plugin can be used to format numbers as text and parse text as Numbers
 * Because we live in an international world, we cannot assume that everyone
 * uses "," to divide thousands, and "." as a decimal point.
 *
 * The format() function will take the text within any selector by calling
 * text() or val() on them, getting the String, and applying the specified format to it.
 * It will return the jQuery object
 *
 * The parse() function will take the text within any selector by calling text()
 * or val() on them, turning the String into a Number, and returning these
 * values in a Number array.
 * It WILL BREAK the jQuery chain, and return an Array of Numbers.
 *
 * The syntax for the formatting is:
 * 0 = Digit
 * # = Digit, zero shows as absent
 * . = Decimal separator
 * - = Negative sign
 * , = Grouping Separator
 * % = Percent (multiplies the number by 100)
 * For example, a format of "#,###.00" and text of 4500.20 will
 * display as "4.500,20" with a locale of "de", and "4,500.20" with a locale of "us"
 *
 *
 * As of now, the only acceptable locales are 
 * United States -> "us"
 * Arab Emirates -> "ae"
 * Egypt -> "eg"
 * Israel -> "il"
 * Japan -> "jp"
 * South Korea -> "kr"
 * Thailand -> "th"
 * China -> "cn"
 * Hong Kong -> "hk"
 * Taiwan -> "tw"
 * Australia -> "au"
 * Canada -> "ca"
 * Great Britain -> "gb"
 * India -> "in"
 * Germany -> "de"
 * Vietnam -> "vn"
 * Spain -> "es"
 * Denmark -> "dk"
 * Austria -> "at"
 * Greece -> "gr"
 * Brazil -> "br"
 * Czech -> "cz"
 * France  -> "fr"
 * Finland -> "fi"
 * Russia -> "ru"
 * Sweden -> "se"
 * Switzerland -> "ch"
 * 
 * TODO
 * Separate positive and negative patterns separated by a ":" (e.g. use (#,###) for accounting)
 * More options may come in the future (currency)
 **/
     
 (function(jQuery) {

     function FormatData(dec, group, neg) {
       this.dec = dec;
       this.group = group;
       this.neg = neg;
     };

     function formatCodes(locale) {

         // default values
         var dec = ".";
         var group = ",";
         var neg = "-";

         if (locale == "us" ||
             locale == "ae" ||
             locale == "eg" ||
             locale == "il" ||
             locale == "jp" ||
             locale == "sk" ||
             locale == "th" ||
             locale == "cn" ||
             locale == "hk" ||
             locale == "tw" ||
             locale == "au" ||
             locale == "ca" ||
             locale == "gb" ||
             locale == "in"
            )
         {
              dec = ".";
              group = ",";
         }

         else if (locale == "de" ||
             locale == "vn" ||
             locale == "es" ||
             locale == "dk" ||
             locale == "at" ||
             locale == "gr" ||
             locale == "br"
            )
         {
              dec = ",";
              group = ".";
         }
         else if (locale == "cz" ||
              locale == "fr" ||
             locale == "fi" ||
             locale == "ru" ||
             locale == "se"
            )
         {
              group = " ";
              dec = ",";
         }
         else if (locale == "ch")
          {
              group = "'";
              dec = ".";
          }
     
        return new FormatData(dec, group, neg);

    };

 jQuery.formatNumber = function(number, options) {
     var options = jQuery.extend({},jQuery.fn.parse.defaults, options);
     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;
     
     var numString = new String(number);
     numString = numString.replace(".",dec).replace("-",neg);
     return numString;
 };

 jQuery.fn.parse = function(options) {

     var options = jQuery.extend({},jQuery.fn.parse.defaults, options);

     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;

     var valid = "1234567890.-";

     var array = [];
     this.each(function(){

         var text = new String(jQuery(this).text());
         if (jQuery(this).is(":input"))
            text = new String(jQuery(this).val());

         // now we need to convert it into a number
         text = text.replace(group,'').replace(dec,".").replace(neg,"-");
         var validText = "";
         var hasPercent = false;
         if (text.charAt(text.length-1)=="%")
             hasPercent = true;
         for (var i=0; i<text.length; i++)
         {
            if (valid.indexOf(text.charAt(i))>-1)
               validText = validText + text.charAt(i);
         }
         var number = new Number(validText);
         if (hasPercent)
         {
            number = number / 100;
            number = number.toFixed(validText.length-1);
         }
         array.push(number);
     });

     return array;
 };

 jQuery.fn.format = function(options) {

     var options = jQuery.extend({},jQuery.fn.format.defaults, options);
     
     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;
     
     var validFormat = "0#-,.";

     return this.each(function(){
         var text = new String(jQuery(this).text());
         if (jQuery(this).is(":input"))
            text = new String(jQuery(this).val());

         // strip all the invalid characters at the beginning and the end
         // of the format, and we'll stick them back on at the end
         // make a special case for the negative sign "-" though, so 
         // we can have formats like -$23.32
         var prefix = "";
         var negativeInFront = false;
         for (var i=0; i<options.format.length; i++)
         {
            if (validFormat.indexOf(options.format.charAt(i))==-1)
                prefix = prefix + options.format.charAt(i);
            else if (i==0 && options.format.charAt(i)=='-')
            {
               negativeInFront = true;
               continue;
            }
            else
                break;
         }
         var suffix = "";
         for (var i=options.format.length-1; i>=0; i--)
         {
            if (validFormat.indexOf(options.format.charAt(i))==-1)
                suffix = options.format.charAt(i) + suffix;
            else
                break;
         }

         options.format = options.format.substring(prefix.length);
         options.format = options.format.substring(0, options.format.length - suffix.length);


        // now we need to convert it into a number
        var number = new Number(text.replace(group,'').replace(dec,".").replace(neg,"-"));

        // special case for percentages
        if (suffix == "%")
           number = number * 100;

        var returnString = "";
        
        var decimalValue = number % 1;
        if (options.format.indexOf(".") > -1)
        {
           var decimalPortion = dec;
           var decimalFormat = options.format.substring(options.format.lastIndexOf(".")+1);
           var decimalString = new String(decimalValue.toFixed(decimalFormat.length));
           decimalString = decimalString.substring(decimalString.lastIndexOf(".")+1);
           for (var i=0; i<decimalFormat.length; i++)
           {
              if (decimalFormat.charAt(i) == '#' && decimalString.charAt(i) != '0')
              {
                 decimalPortion += decimalString.charAt(i);
                 break;
              }
              else if (decimalFormat.charAt(i) == "0")
              {
                 decimalPortion += decimalString.charAt(i);
              }
           }
           returnString += decimalPortion
        }
        else
           number = Math.round(number);
        
        var ones = Math.floor(number);
        if (number < 0)
            ones = Math.ceil(number);

        var onePortion = "";
        if (ones == 0)
        {
           onePortion = "0";
        }
        else
        {
           // find how many digits are in the group
           var onesFormat = "";
           if (options.format.indexOf(".") == -1)
              onesFormat = options.format;
           else
              onesFormat = options.format.substring(0, options.format.indexOf("."));
           var oneText = new String(ones);
           var groupLength = 9999;
           if (onesFormat.lastIndexOf(",") != -1)
               groupLength = onesFormat.length - onesFormat.lastIndexOf(",")-1;
           var groupCount = 0;
           for (var i=oneText.length-1; i>-1; i--)
           {
             onePortion = oneText.charAt(i) + onePortion;

             groupCount++;

             if (groupCount == groupLength && i!=0)
             {
                 onePortion = group + onePortion;
                 groupCount = 0;
             }

           }
        }

        returnString = onePortion + returnString;

        // handle special case where negative is in front of the invalid
        // characters
        if (number < 0 && negativeInFront && prefix.length > 0)
        {
           returnString = returnString.substring(1);
           prefix = neg + prefix;
        }

        returnString = prefix + returnString + suffix;

        if (jQuery(this).is(":input"))
           jQuery(this).val(returnString);
        else
           jQuery(this).text(returnString);

     });
 };

 jQuery.fn.parse.defaults = {
      locale: "us"
 };

 jQuery.fn.format.defaults = {
      format: "#,###.00",
      locale: "us"
 };


 })(jQuery);;

