﻿var ___urlPrefix = "";
if (window.location.href.indexOf("localhost") > -1)
{
	var ___startLoc = window.location.href.indexOf("/", window.location.href.indexOf("localhost"));
	var ___sub = window.location.href.substring(___startLoc);
	if (___sub.indexOf("/", 1) > -1)
	{
		___urlPrefix = ___sub.substring(0, ___sub.indexOf("/", 1));
	}
}

function stopEvent(e)
{
	if (!e) var e = window.event;

	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation)
	{
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}

$(document).ready(function()
{
    /*
    $("body").addClass("grass");
    if ($("body").hasClass("home"))
    {
    $("#page").css( 'background', 'background: transparent url(/images/grass/eco-home-background.jpg) no-repeat');
    }
    */

    $("body").addClass("bubbles");
    if ($("body").hasClass("home")) {
        $("#page").css('background', 'background: transparent url(/images/bubbles/eco-home-background.jpg) no-repeat');
    }

	$("a[@rel*=main]").lightBox();
	$("a[@rel*=custom]").lightBox();

	$("#searchTerms").keyup(
		function(event)
		{
			if (event.keyCode == 13)
			{
				stopEvent(event);
				window.location.href = ___urlPrefix + "/search?s=" + $(this).attr("value");
				return false;
			}
		}
	).focus(function()
	{
		if (this.value == this.defaultValue)
		{
			this.value = "";
		}
	}).blur(function()
	{
		if (this.value.length == 0)
		{
			this.value = this.defaultValue;
		}
	});

	$("form").attr("action", window.location);

	$("a.dealerlogin").attr("href", $("a.dealerlogin").attr("href") + window.location.href);
	$("a.dealerlogout").attr("href", $("a.dealerlogout").attr("href") + window.location.href);

	if ($("a.dealerlogin").text() == "Logout")
	{
		$("a.dealerlogin").removeClass("dealerlogin").addClass("dealerlogout");
	}

	$("div.main-nav li").each(function()
	{
		$(this).hover(function()
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		});
	});
});