﻿
var widthC = 435;
var heightC = 230; //form is 450, but needed to -220 to clear banner 


//uses this to add the scrolled down value to the calculated top in the centerPopup function below.
//in theory adding the top scrolled value and the left scrolled values to a page element
// top postion and the left position as calculated by the winHeight and the wnWidth values allows that element if
// acting as a pop up to always be centered, left and top, within the browser window based on where the user is.
//I like this. 

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //this method of return allows for 2 values to be returned
    //js usally only allows one value unless return is an array (but usually not named so difficult to ascertain values
    //or a seemingly better methos which works here is to create an object
    //  the calling function decs scrOfX, scrOfY but uses
    //the called function var; like this
    //object: =
    // var whre = getScrollXY();
    //return used as this:
    //something =  whre.scrOfX);
    //something =  whre.scrOfY);
    //mine is not to reason why, mine is to use and fly.
    return { scrOfX: scrOfX, scrOfY: scrOfY };
}


//centering popup
function callitpos() {
    var scrOfY;
    var scrOfX;
    var whre = getScrollXY();
    //alert(whre.scrOfY + "=top  " + whre.scrOfX + "  =left")
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = heightC;    //$j("#callit2").height();
    var popupWidth = widthC;        //$j("#callit2").width();
    //centering
    $("#callit2").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2 + whre.scrOfY,
        "left": windowWidth / 2 - popupWidth / 2 + whre.scrOfX

    });
    //only need force for IE6

       $("#backgroundPopup").css({
        "height": windowHeight
    });

}


$(document).ready(function() {

    $("#con2").hide();

    $("#contact2").click(function() {
        callitpos();
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");

        $('#callit2').fadeIn('slow');
        $('#rightpinner').css({ visibility: 'hidden' });

        $(function() {
            $('#callit2').con2({});
        });

    });



    $("#contact3").click(function() {
        callitpos();
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");

        $('#callit2').fadeIn('slow');
        $('#block1').css({ visibility: 'hidden' });
        $('#block2').css({ visibility: 'hidden' });
        $('#block3').css({ visibility: 'hidden' });
        $('#rightpinner').css({ visibility: 'hidden' });
        $('.rightpinner').css({ visibility: 'hidden' });

        $(function() {
            $('#callit2').con2({});
        });

    });

    $(window).resize(function() {

        callitpos();
        // resizeOverlay();

    });

    //  resizeOverlay();

 //   callitpos();



});


