// start: cookie plugin
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
// end cookie plugin

// start: delay extension
(function($) {
    $.fn.delay = function(time, callback) {
        // Empty function:
        jQuery.fx.step.delay = function(){};
        // Return meaningless animation, (will be added to queue)
        return this.animate({delay:1}, time, callback);
    }
})(jQuery);
// end: delay extension

// Start: errorMessage extension
jQuery.fn.errorMessage = function(options)
{
	var inputId = $(this).attr("id"); 
    var defaults = {
        containerId: inputId,
        messageTop: "This field cannot be left blank",
        messageMain: "Please provide a value and resubmit the form",
        formElement: "true",
        specialCase: "false"

    };
    var options = jQuery.extend(defaults, options);



    if (options.formElement == "true") {
        // add focus to the form element
        if (options.specialCase == "false") {
            var output = "<div id='error_"+options.containerId+"' class='errorCont'>";
            output += "<span class='top'></span>";
            output += "<p class='bold'>"+options.messageTop+"</p>";
            output += "<p>"+options.messageMain+"</p>";
            output += "</div>";
            output += "<div class='errorClear'></div>";

        // append the output AFTER the form element
        $("#"+options.containerId).after(output);
            $("#" + options.containerId).addClass("errorFocus");
        }
        //Special Case for Request a Brochure, Schedule a Test Drive, Request a Quote
        else {
            var inputId2 = $(this).attr("class");
            var classes = inputId2.split(" ");
            if(classes.length==1){
                var output = "<div id='error_"+options.containerId+"' class='errorCont'>";
                output += "<span class='top'></span>";
                output += "<p class='bold'>"+options.messageTop+"</p>";
                output += "<p>"+options.messageMain+"</p>";
                output += "</div>";
                output += "<div class='errorClear'></div>";

                // append the output AFTER the form element
                $("#"+options.containerId).after(output);
                $("#" + inputId2).addClass("errorFocus");
            }else{
                $("#" + classes[0]).addClass("errorFocus");
                $("#" + classes[1]).addClass("errorFocus");
                var output = "<div id='error_"+options.containerId+"' class='errorCont'>";
                output += "<span class='top'></span>";
                output += "<p class='bold'>This fields cannot be left blank</p>";
                output += "<p>Please enter a state and a zip code</p>";
                output += "</div>";
                output += "<div class='errorClear'></div>";

                // append the output AFTER the form element
                $("#"+options.containerId).after(output);


            }

        }
    }

};
// end: errorMessage extension

// start: jCarouselLite extension
(function($) {
	var sinceLast = 0;
	var heroTimer = 3000;
	var heroHover = false;
	var timingArray = new Array();
	var curAdj = 1;
	var externallyPaused = false;
	$.fn.jCarouselLite = function(o) {
		o = $.extend({
			btnPrev: null,
			btnNext: null,
			btnGo: null,
			mouseWheel: false,
			auto: 200,

			speed: 200,
			easing: null,

			vertical: false,
			circular: true,
			visible: 1,
			start: 0,
			scroll: 1,

			beforeStart: null,
			afterEnd: null
		}, o || {});

		return this.each(function() {						   // Returns the element collection. Chainable.

			var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
			var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

			if(o.circular) {
				ul.prepend(tLi.slice(tl-v-1+1).clone())
				  .append(tLi.slice(0,v).clone());
				o.start += v;
			}

			var li = $("li", ul), itemLength = li.size(), curr = o.start;
			div.css("visibility", "visible");

			//find the proper current item
			$('.rotator li .podFade').fadeOut(0);
			$('.rotator li:nth-child('+(curr + curAdj)+') .podFade').fadeIn(0);

			li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
			ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
			div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

			var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
			var ulSize = liSize * itemLength;				   // size of full ul(total length, not just for the visible items)
			var divSize = liSize * v;						   // size of entire div(total length for just the visible items)

			li.css({width: li.width(), height: li.height()});
			ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

			div.css(sizeCss, divSize+"px");					 // Width of the DIV. length of visible images

			li.each(function(){
				if ($(this).find('.pod282').length > 0) timingArray.push(7000);
				else  timingArray.push(4000);
			});

			//CUSTOM hover toggle to disable slide
			$("#flash_content950").hover(function() {
				sinceLast = 0;
				heroHover = true;
				$('.monitor').html('over');
			}, function() {
					if(!externallyPaused){
						heroHover = false;
						sinceLast = timingArray[curr] - 2000;
						$('.monitor').html('off');
					} else {
						sinceLast = 0;
						heroHover = true;
						$('.monitor').html('over');
					}

				});

			if(o.btnPrev)
				$(o.btnPrev).click(function() {
					return go(curr-o.scroll);
				});

			if(o.btnNext)
				$(o.btnNext).click(function() {
					return go(curr+o.scroll);
				});

			if(o.btnGo)
				$.each(o.btnGo, function(i, val) {
					$(val).click(function() {
						return go(o.circular ? o.visible+i : i);
					});
				});

			if(o.mouseWheel && div.mousewheel)
				div.mousewheel(function(e, d) {
					return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
				});

			if(o.auto)
				setInterval(function() {
					sinceLast+=500;
					if (heroHover == true) sinceLast = 0;
					if (sinceLast >= timingArray[curr]) {
						go(curr+o.scroll);
						sinceLast = 0;
					}
				}, o.auto+o.speed);

			   $(document)
			     .bind('pauseRotator', function() {
							externallyPaused = true;
			      			sinceLast = 0;
							heroHover = true;
							$('.monitor').html('over');
			     })
			     .bind('resumeRotator', function() {
			       			heroHover = false;
							sinceLast = timingArray[curr] - 2000;
							$('.monitor').html('off');
							externallyPaused = false;
			     });


			function vis() {
				return li.slice(curr).slice(0,v);
			};

			function go(to) {
				if(!running) {
					$('.rotator li:nth-child('+(curr + curAdj)+') .podFade').fadeOut(o.speed);
					if(o.beforeStart)
						o.beforeStart.call(this, vis());

					if(o.circular) {			// If circular we are in first or last, then goto the other end
						if(to<=o.start-v-1) {		   // If first, then goto last
							ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
							// If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
							curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
						} else if(to>=itemLength-v+1) { // If last, then goto first
							ul.css(animCss, -( (v) * liSize ) + "px" );
							// If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
							curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
						} else curr = to;
					} else {					// If non-circular and to points to first or last, we just return.
						if(to<0 || to>itemLength-v) return;
						else curr = to;
					}						   // If neither overrides it, the curr will still be "to" and we can proceed.

					running = true;

					ul.animate(
						animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
						function() {
							if(o.afterEnd)
								o.afterEnd.call(this, vis());
							running = false;
						}
					);
					// Disable buttons when the carousel reaches the last/first, and enable when not
					if(!o.circular) {
						$(o.btnPrev + "," + o.btnNext).removeClass("disabled");
						$( (curr-o.scroll<0 && o.btnPrev)
							||
						   (curr+o.scroll > itemLength-v && o.btnNext)
							||
						   []
						 ).addClass("disabled");
					}
					$('.rotator li:nth-child('+(curr + curAdj)+') .podFade').fadeIn(o.speed);

				}
				return false;
			};
		});
	};

    function css(el, prop) {
        return parseInt($.css(el[0], prop)) || 0;
    };
    function width(el) {
       // return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight'); // THIS IS CAUSING ISSUES IN IE7
		return 950; //im not sure why its causing IE7 issues... but this is the hardcoded width and this works.
    };
    function height(el) {
        return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
    };

})(jQuery);
// end: jCarouselLite extension

// start: png Fix extension
(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: '/content/images/site/global/ie6/blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});

		//fix input with png-source
		jQuery(this).find("input[src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});

	}

	return jQuery;

};

})(jQuery);
// end: png Fix extension

/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


