function centralLineSet() {
    var largestHeightTop = $("#main-left").height();
    largestHeightTop = (largestHeightTop < $("#main-right").height()) ? $("#main-right").height() : largestHeightTop;
    $("#main-divide").height(largestHeightTop);
}

/** FORM SCRIPTS 
*
*
*/

function submitForm() {
    var formDetails = {
        name: $.trim($('#name').val()),
        surname: $.trim($('#surname').val()),
        enquiry: $('#enquiry').val(),
        email: $.trim($('#email').val()),
        confirm: $.trim($('#emailConfirm').val()),
        telephone: $.trim($('#tel').val()),
        service: $('#service').val(),
        serviceLevel: $('#serviceLevel').val()
    }


    // validate form details object.
    if (ValidateForm(formDetails)) {
        SubmitXmlSchemaLoad();
        SubmitContactXml(formDetails);
        if (submitSuccess) {
            EmptyFormShowAlert();
        }
    }
}

function ValidateForm(formDetails) {
    var success = true;

    $('#alert li').remove();
    $('#appointment-form input').css('border-color', '#E2E2E2');

    if (formDetails.name == '') {
        $('#alert').append('<li>Please enter a name</li>').css('visibility', 'visible');
        $('#name').css('border-color', '#ff6666');
        success = false;
    }
    if (formDetails.email == '' && formDetails.telephone == '') {
        $('#alert').append('<li>Please enter an email or telephone number</li>').css('visibility', 'visible');
        $('#email').css('border-color', '#ff6666');
        $('#tel').css('border-color', '#ff6666');
        success = false;
    }

    if (formDetails.email != '' && formDetails.email != formDetails.confirm) {
        $('#alert').append('<li>Email and Confirmation do not match</li>').css('visibility', 'visible');
        $('#email').css('border-color', '#ff6666');
        $('#emailConfirm').css('border-color', '#ff6666');
        success = false;
    }
    return success;
}

function EmptyFormShowAlert() {
    $('#name').val('');
    $('#surname').val('');
    $('#email').val('');
    $('#emailConfirm').val('');
    $('#tel').val('');
    $('#enquiry').val('');
    $('#service').val('');
    $('#serviceLevel').val('');
    $('#serviceLevel').css('display', 'none');
    $('#appointment-form input').css('border-color', '#E2E2E2');
    $('#alert').remove('li');
    $('#alert').append('<li>Thank you for your enquiry, we will be in contact as soon.</li>');
    $('#alert').css('visibility', 'visible');
}
function ajaxCall(async, methodType, url, data, successCallback, errorCallback) {
    $.ajax({
        async: async,
        type: methodType,
        contentType: "application/json; charset=utf-8",
        url: url,
        data: data,
        dataType: "json",
        error: errorCallback,
        success: successCallback
    });
}

function ajaxXmlCall(async, methodType, url, data, successCallback, errorCallback) {
    $.ajax({
        async: async,
        type: methodType,
        contentType: "text/xml; charset=utf-8",
        url: url,
        data: data,
        dataType: "xml",
        error: errorCallback,
        success: successCallback
    });
}
jQuery.fn.toXML = function () {
    var toXML = function (node) {
        var out = '';
        var attributes = '';
        var content = '';
        out += '<' + node.nodeName;
        if (node.childNodes) {
            for (var i = 0; i < node.childNodes.length; i++) {
                switch (node.childNodes[i].nodeType) {
                    case 1:     // ELEMENT_NODE
                        content += toXML(node.childNodes[i]);
                        break;
                    case 2:     // ATTRIBUTE_NODE
                        attributes += ' ' + node.childNodes[i].nodeName + '="'
                              + node.childNodes[i].nodeValue + '"';
                        break;
                    case 3:     // TEXT_NODE
                    case 4:     // CDATA_SECTION_NODE
                    case 5:     // ENTITY_REFERENCE_NODE
                    case 6:     // ENTITY_NODE
                    case 7:     // PROCESSING_INSTRUCTION_NODE
                    case 8:     // COMMENT_NODE
                    case 9:     // DOCUMENT_NODE
                    case 10:    // DOCUMENT_TYPE_NODE
                    case 11:    // DOCUMENT_FRAGMENT_NODE
                    case 12:    // NOTATION_NODE
                        content += node.childNodes[i].nodeValue;
                        break;
                }
            }
        }
        out += attributes;
        if (content.length > 0) {
            out += '>' + content;
            out += '</' + node.tagName + '>';
        }
        else {
            out += '/>';
        }
        return out;
    }
    var out = '';
    if (this.length > 0) {
        if (typeof XMLSerializer == 'function' ||
        typeof XMLSerializer == 'object') {
            var xs = new XMLSerializer();
            this.each(function () { out += xs.serializeToString(this); });
        }
        else if (this[0].xml !== undefined) {
            this.each(function () { out += this.xml; });
        }
        else {
            if (this.length > 0) {
                this.each(function () { out += toXML(this); });
            }
        }
    }
    return out;
};

//// Contact xml

var ContactSubmitXml;
var submitSuccess = false;

function SubmitXmlSchemaLoad() {
    ajaxXmlCall(false, "GET", "/FormMail.aspx?G=1", null, OnContactSubmitXmlSchemaLoaded, OnContactSubmitXmlSchemaLoadError);
}

function OnContactSubmitXmlSchemaLoaded(result) {
    ContactSubmitXml = result;
    console.debug(ContactSubmitXml);
}

function OnContactSubmitXmlSchemaLoadError(result) {
    alert('Contact schema load error: ' + result.innerHTML);
}


function SubmitContactXml(formDetails) {
    if (ContactSubmitXml != null) {
        ContactSubmitXml.documentElement.childNodes[0].textContent = formDetails.name;
        ContactSubmitXml.documentElement.childNodes[1].textContent = formDetails.surname;
        ContactSubmitXml.documentElement.childNodes[2].textContent = formDetails.enquiry;
        ContactSubmitXml.documentElement.childNodes[3].textContent = formDetails.email;
        ContactSubmitXml.documentElement.childNodes[4].textContent = formDetails.telephone;
        ContactSubmitXml.documentElement.childNodes[5].textContent = formDetails.service;
        ContactSubmitXml.documentElement.childNodes[6].textContent = formDetails.serviceLevel;
        ajaxXmlCall(false, "POST", "/FormMail.aspx?P=1", $(ContactSubmitXml).toXML(), OnContactSubmitXmlLoaded, OnContactSubmitXmlLoadedError);
    }
    else {
        alert('Contact schema not loaded yet');
    }
}

function OnContactSubmitXmlLoaded(result) { if (result.firstChild.textContent == "True") submitSuccess = true; }

function OnContactSubmitXmlLoadedError() { alert('Contact Submit error: ' + result.innerHTML); }

/* END FORM SCRIPTS */

   
   var hoverConfig = {
    interval: 125,
    sensitivity: 4,
    over: addHover,
    timeout: 125,
    out: removeHover
};

function addHover() { if (!$(this).hasClass('selected')) $(this).animate({ opacity: 1.0 }, 500) }
function removeHover() { if (!$(this).hasClass('selected')) $(this).animate({ opacity: 0.4 }, 500); }

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function (e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);

/*
* jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
* http://benalman.com/projects/jquery-bbq-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function ($, p) { var i, m = Array.prototype.slice, r = decodeURIComponent, a = $.param, c, l, v, b = $.bbq = $.bbq || {}, q, u, j, e = $.event.special, d = "hashchange", A = "querystring", D = "fragment", y = "elemUrlAttr", g = "location", k = "href", t = "src", x = /^.*\?|#.*$/g, w = /^.*\#/, h, C = {}; function E(F) { return typeof F === "string" } function B(G) { var F = m.call(arguments, 1); return function () { return G.apply(this, F.concat(m.call(arguments))) } } function n(F) { return F.replace(/^[^#]*#?(.*)$/, "$1") } function o(F) { return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/, "$1") } function f(H, M, F, I, G) { var O, L, K, N, J; if (I !== i) { K = F.match(H ? /^([^#]*)\#?(.*)$/ : /^([^#?]*)\??([^#]*)(#?.*)/); J = K[3] || ""; if (G === 2 && E(I)) { L = I.replace(H ? w : x, "") } else { N = l(K[2]); I = E(I) ? l[H ? D : A](I) : I; L = G === 2 ? I : G === 1 ? $.extend({}, I, N) : $.extend({}, N, I); L = a(L); if (H) { L = L.replace(h, r) } } O = K[1] + (H ? "#" : L || !K[1] ? "?" : "") + L + J } else { O = M(F !== i ? F : p[g][k]) } return O } a[A] = B(f, 0, o); a[D] = c = B(f, 1, n); c.noEscape = function (G) { G = G || ""; var F = $.map(G.split(""), encodeURIComponent); h = new RegExp(F.join("|"), "g") }; c.noEscape(",/"); $.deparam = l = function (I, F) { var H = {}, G = { "true": !0, "false": !1, "null": null }; $.each(I.replace(/\+/g, " ").split("&"), function (L, Q) { var K = Q.split("="), P = r(K[0]), J, O = H, M = 0, R = P.split("]["), N = R.length - 1; if (/\[/.test(R[0]) && /\]$/.test(R[N])) { R[N] = R[N].replace(/\]$/, ""); R = R.shift().split("[").concat(R); N = R.length - 1 } else { N = 0 } if (K.length === 2) { J = r(K[1]); if (F) { J = J && !isNaN(J) ? +J : J === "undefined" ? i : G[J] !== i ? G[J] : J } if (N) { for (; M <= N; M++) { P = R[M] === "" ? O.length : R[M]; O = O[P] = M < N ? O[P] || (R[M + 1] && isNaN(R[M + 1]) ? {} : []) : J } } else { if ($.isArray(H[P])) { H[P].push(J) } else { if (H[P] !== i) { H[P] = [H[P], J] } else { H[P] = J } } } } else { if (P) { H[P] = F ? i : "" } } }); return H }; function z(H, F, G) { if (F === i || typeof F === "boolean") { G = F; F = a[H ? D : A]() } else { F = E(F) ? F.replace(H ? w : x, "") : F } return l(F, G) } l[A] = B(z, 0); l[D] = v = B(z, 1); $[y] || ($[y] = function (F) { return $.extend(C, F) })({ a: k, base: k, iframe: t, img: t, input: t, form: "action", link: k, script: t }); j = $[y]; function s(I, G, H, F) { if (!E(H) && typeof H !== "object") { F = H; H = G; G = i } return this.each(function () { var L = $(this), J = G || j()[(this.nodeName || "").toLowerCase()] || "", K = J && L.attr(J) || ""; L.attr(J, a[I](K, H, F)) }) } $.fn[A] = B(s, A); $.fn[D] = B(s, D); b.pushState = q = function (I, F) { if (E(I) && /^#/.test(I) && F === i) { F = 2 } var H = I !== i, G = c(p[g][k], H ? I : {}, H ? F : 2); p[g][k] = G + (/#/.test(G) ? "" : "#") }; b.getState = u = function (F, G) { return F === i || typeof F === "boolean" ? v(F) : v(G)[F] }; b.removeState = function (F) { var G = {}; if (F !== i) { G = u(); $.each($.isArray(F) ? F : arguments, function (I, H) { delete G[H] }) } q(G, 2) }; e[d] = $.extend(e[d], { add: function (F) { var H; function G(J) { var I = J[D] = c(); J.getState = function (K, L) { return K === i || typeof K === "boolean" ? l(I, K) : l(I, L)[K] }; H.apply(this, arguments) } if ($.isFunction(F)) { H = F; return G } else { H = F.handler; F.handler = G } } }) })(jQuery, this);
/*
* jQuery hashchange event - v1.2 - 2/11/2010
* http://benalman.com/projects/jquery-hashchange-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function ($, i, b) { var j, k = $.event.special, c = "location", d = "hashchange", l = "href", f = $.browser, g = document.documentMode, h = f.msie && (g === b || g < 8), e = "on" + d in i && !h; function a(m) { m = m || i[c][l]; return m.replace(/^[^#]*#?(.*)$/, "$1") } $[d + "Delay"] = 100; k[d] = $.extend(k[d], { setup: function () { if (e) { return false } $(j.start) }, teardown: function () { if (e) { return false } $(j.stop) } }); j = (function () { var m = {}, r, n, o, q; function p() { o = q = function (s) { return s }; if (h) { n = $('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow; q = function () { return a(n.document[c][l]) }; o = function (u, s) { if (u !== s) { var t = n.document; t.open().close(); t[c].hash = "#" + u } }; o(a()) } } m.start = function () { if (r) { return } var t = a(); o || p(); (function s() { var v = a(), u = q(t); if (v !== t) { o(t = v, u); $(i).trigger(d) } else { if (u !== t) { i[c][l] = i[c][l].replace(/#.*/, "") + "#" + u } } r = setTimeout(s, $[d + "Delay"]) })() }; m.stop = function () { if (!n) { r && clearTimeout(r); r = 0 } }; return m })() })(jQuery, this);
/**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  *
* @author Alexander Farkas
* v. 1.02
*/
(function ($) {
    $.extend($.fx.step, { backgroundPosition: function (fx) {
        if (fx.state === 0 && typeof fx.end == 'string') {
            var start = $.curCSS(fx.elem, 'backgroundPosition'); start = toArray(start); fx.start = [start[0], start[2]];
            var end = toArray(fx.end); fx.end = [end[0], end[2]]; fx.unit = [end[1], end[3]];
        }
        var nowPosX = []; nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0]; nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1]; fx.elem.style.backgroundPosition = nowPosX[0] + ' ' + nowPosX[1];
        function toArray(strg) { strg = strg.replace(/left|top/g, '0px'); strg = strg.replace(/right|bottom/g, '100%'); strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2"); var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/); return [parseFloat(res[1], 10), res[2], parseFloat(res[3], 10), res[4]]; } 
    }
    });
})(jQuery);

