function analytics()
{
	if (!gaId) return null;
	gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	loadScript(gaJsHost + "google-analytics.com/ga.js", alalyticsLoaded);
}
function alalyticsLoaded()
{
	if (!gaId) return null;
	var pageTracker = _gat._getTracker(gaId);
	pageTracker._setDomainName(BASE_URL.replace(/^http:\/\//, '').replace(/\/.*$/, ''));
	pageTracker._trackPageview();
}
function animateCars()
{
	var startPos = hum.isIE() && !hum.isIE8() ? 0 : 9;
	var slideIncrement = 1;
	var itemWidth = 0;
	function scrollLeft()
	{
		remainingPixels = firstItem.offsetLeft - startPos + itemWidth;
	    if (remainingPixels > 0)
	    {
			if (remainingPixels == startPixels)
			{
				newLastItem = firstItem.cloneNode(true);
		        /*newLastItem.style['marginLeft'] = '3px';
				newLastItem.style['marginRight'] = '0';*/
		        cars.appendChild(newLastItem);
			}
			var increment = remainingPixels >= slideIncrement ? slideIncrement : remainingPixels;
			firstItem.style['marginLeft'] = (firstItem.offsetLeft - slideIncrement - startPos) + 'px';
			
	    }
		else
		{
	        cars.removeChild(firstItem);
			firstItem = cars.getElementsByTagName('img').item(0);
			itemWidth = firstItem.width;
			startPixels = firstItem.offsetLeft - startPos + itemWidth;
        	remainingPixels = startPixels;
			//firstItem.style['marginLeft'] = '0';
			//firstItem.style['marginRight'] = '1px';
			//jQuery('img', cars).slice(-1).fadeIn(200);
			//jQuery('img', cars).slice(-1).css('display', 'block');
		}
	}
	var newLastItem;
	var cars = document.getElementById('cars');
	var firstItem = cars.getElementsByTagName('img').item(0);
	itemWidth = firstItem.width;
	var startPixels = firstItem.offsetLeft - startPos + itemWidth;
	var remainingPixels = startPixels;
	/*var img = firstItem.getElementsByTagName('img').item(0);*/
	/* jQuery(firstItem).fadeOut(150, scrollLeft);*/
	/*img = cars.getElementsByTagName('img').item(3);
	img.style['display'] = 'block';*/
	setInterval(scrollLeft, 35);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function externalLinks() 
{ 
    var anchors = document.getElementsByTagName('a'); 
    for (var i = 0; i < anchors.length; ++i)
    { 
        var anchor = anchors[i]; 
        if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
        {
            anchor.target = '_blank';
        }
    }
}
function isIE6()
{
	return jQuery.browser.msie && jQuery.browser.version == 6;
}
function isIE7()
{
	return jQuery.browser.msie && jQuery.browser.version == 7;
}
function isIE()
{
	return isIE6() || isIE7();
}
function loadScript(url, aFunction)
{
	var e = document.createElement("script");
	e.onreadystatechange = function () 
	{
    	if ((this.readyState == 'completed' || this.readyState == 'loaded') && !this.loadScriptDone) 
    	{
        	this.loadScriptDone = true;
        	aFunction();
       	}
    }
    e.onload = aFunction;
	e.type = "text/javascript";
	e.src = url;
	document.getElementsByTagName("head")[0].appendChild(e);
	return e;
}
function submissionCheck()
{
    var message = 'Please fill in this box';
    this.fieldsValid = true;
    jQuery('form textarea.warning')
            .removeClass('warning')
            .focus(null)
        ;
    jQuery('form input.warning')
            .removeClass('warning')
            .focus(null)
        ;
    jQuery('li.required input:not([type="password"])[value="'+message+'"], li.required textarea[value="'+message+'"]')
            .attr('value', '')
            .focus(function(){
                if (this.value == message) this.value = '';
                this.className = '';
              })
            .each(function(){
                this.form.fieldsValid = false;
              })
        ;
    jQuery('li.required input:not([type="password"])[value=""], li.required textarea[value=""], li.required textarea[value=" "]')
            .addClass('warning')
            .attr('value', message)
            .focus(function(){
                if (this.value == message) this.value = '';
                this.className = '';
               })
            .each(function(){this.form.fieldsValid = false;})
        ;
     jQuery('li.required input[type="password"][value=""]')
            .addClass('warning')
            .focus(function(){
                this.className = '';
               })
            .each(function(){this.form.fieldsValid = false;})
        ;

    return (jQuery('.warning').length == 0);
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function reCaptcha()
{
    if (!reCaptchaKey) return null;
    loadScript(document.location.protocol + '//api.recaptcha.net/js/recaptcha_ajax.js', reCaptchaLoaded);
}
function reCaptchaLoaded()
{
    
}
jQuery(document).ready(function(){
        //if (jQuery.browser.mozilla) mozFormFix();
        jQuery('form').submit(function (){return submissionCheck();});
		externalLinks();
		analytics();
		if (document.getElementById('cars') && !isIE6())
		{
			setTimeout(animateCars, 2000);
		}
   }
);
