window.addEvent("domready", function() {

    new SmoothScroll({ "links": $$(".scroll") });
    new AlphaPng();
    var addthis_pub = "";

    $$(".volatile").each(function(el) {
        $(el).addEvent("focus", function() {
            if (this.getValue() == this.getProperty("title")) {
                this.value = "";
            }
        });
    });


    // Office Types Tooltips

    var Tips1 = new Tips($$('.facilities a'), {
        showDelay: 400,
        hideDelay: 400,
        offsets: { x: 20, y: 0 }
    });

    // Hide button's with JS for non JS browsers
    if($("sortButton")){
        $("sortButton").style.display = 'none';
    }


    $$("a[rel*='external']").each(function(a) {
        $(a).setProperty("target", "_blank");
    });

    $$(".homephoto ul").each(function(el) { new Ticker(el, { "interval": 7000 }) });


    $$(".iCal").each(function(el) {
        el.setStyle("display", "block");
        var fieldID = el.id.substr(5);
        var myCal = new MooCal(fieldID);
        el.addEvent("click", function(e) {
            var event = new Event(e).stop();
            $$(".calendar").each(function(el2) {
                el2.style.display = 'none';
            });
            var x = event.page.x - 235;
            var y = event.page.y - 220;
            myCal.show(x, y);
        });
    });

    if ($("sortby")) {
        $("sortby").addEvent("change", function(e) {
            $("sortby").form.submit();
        });
    }

    if ($("DealerEventForm")) {
        $("LengthOfEvent").addEvent("change", function(e) {
            var action = $("LengthOfEvent").form.getProperty('action')
            $("LengthOfEvent").form.setProperty('action', action + '&AddDate=true#EventDetails');
            $("LengthOfEvent").form.submit();
        });

        if ($("eventotherlocation")) {

            toggleOtherLocation(false)

            if ($("eventotherlocation").checked) {
                toggleOtherLocation(true)
            }
        }

        $$(".locationselector").each(function(el) {
            el.addEvent("click", function(e) {
                if ($("eventotherlocation").checked) {
                    toggleOtherLocation(true)
                }
                else {
                    toggleOtherLocation(false)
                }
            });
        });
    }

    if ($("customLink")) {
        var customLink = new Fx.Slide("customContent", { "duration": 1200, "transition": Fx.Transitions.Expo.easeOut });
        customLink.hide();
        $("customLink").addEvent("click", function(e) {
            new Event(e).stop();
            customLink.toggle();

			if (customLink.open) {
				$("customLink").setText('View More Options')
			} else if (!customLink.open) {
				$("customLink").setText('View Less Options')
			}

        });
    }


    new Accordion($$("#faqs li h2"), $$("#faqs div"));


    $$(".socialize").addEvent("click", function(e) {
        new Event(e).stop();
        addthis_url = location.href;
        addthis_title = document.title;
        addthis_click(this);
    });
    
    
    if ($("DealerEventForm")) {

		var errors = $$(".fielderror");
		
		if (errors[0])
		{
			var elid = errors[0].getProperty('id');
			
			if (elid) {
				var myFx = new Fx.Scroll(window).toElement(elid);
			}
		}


    }

});

function toggleOtherLocation(boolShow) {

	if (boolShow)
	{
		$("OtherLocation").setStyle('display', 'block')
		$$(".otherlocation").setStyle('display', 'block')
	}
	else
	{
		$("OtherLocation").setStyle('display', 'none')
		$$(".otherlocation").setStyle('display', 'none')
	}


}

