﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="common.js" />
/// <reference path="Library/jquery-1.4.2.min.js" />

var tierneyBrothers = function() {
    var pub = {};

    pub.alert = function(message, callback) {
        common.alert(message, callback);
    };

    pub.displayError = function(message, callback) {
        common.displayError(message, callback);
    };

    pub.ajaxRequestFailed = function(error) {
        common.ajaxRequestFailed(error);
    };

    pub.fixModal = function() {
        if ($("body.ie7").size() > 0) {
            var $simpleModal = $(".simplemodal-container");
            $simpleModal.height("auto");
            var newHeight = $simpleModal.height();
            $simpleModal.css("top", parseInt($simpleModal.css("top")) - (newHeight / 2));
        }
    };

    pub.setup = function() {
        $(".viewLocationAction").click(function(e) {
            e.preventDefault();
            ProjectorPoint.Web.WebServices.DefaultService.RenderLocationMapControl($(this).attr("data-locationId"), function(result) {
                $(result).modal({ overlayClose: true });
                tierneyBrothers.fixModal();
            }, tierneyBrothers.ajaxRequestFailed);
        });

        $("a:external").attr("target", "_blank");

        $("#mainNav .navItem").hoverIntent(
			{ over: function() {
			    var $this = $(this);
			    $this.addClass("hover").siblings().removeClass("hover");
			    $this.find(".subNav").show("slide", { direction: "left" }, 250);
			}
			, timeout: 100
			, out: function() {
			    var $this = $(this);
			    $this.removeClass("hover");
			    $this.find(".subNav").hide("slide", { direction: "left" }, 250);
			}
			});

        var $searchBox = $("#userInfo .search .searchBox");

        $searchBox.val($searchBox.attr("data-defaultValue"));

        $searchBox.focus(function() {
            var $this = $(this);
            if ($searchBox.val() == $this.attr("data-defaultValue")) {
                $this.val("");
            }
        });

        $searchBox.blur(function() {
            var $this = $(this);
            if ($this.val() == "") {
                $this.val($this.attr("data-defaultValue"));
            }
        });

        $("#userInfo .search a.searchButton").click(function(event) {
            event.preventDefault();
            window.location = "/SiteSearch.aspx?Query=" + $("#header #userInfo .searchBox").val();
        });

        $("#footer .left, #footer .center, #footer .right").equalHeight();
        $("#main .columnLeft, #main .columnRight").equalHeight();
    };

    return pub;
} ();

$(document).ready(function() {
	tierneyBrothers.setup();
});
