$(document).ready(function() {

    if ($.browser.msie && jQuery.browser.version == "6.0") var isIE6 = true;
    else var isIE6 = false;

    var currentModal;

    $("#testLi").bind("click", function(e) {
        $("#test").animate({ top: "1000px" }, 1000, "easeInOut");

    });

    $("#openTAF").bind("click", function(e) {
        launchModal($(this).attr("id"));
    });
    $("#openReg").bind("click", function(e) {
        launchModal($(this).attr("id"));
    });
    $(".modalClose").bind("click", function(e) { closeModal(); });


});
    //m - reference to modal that needs to be launched
    function launchModal(m) {
        var browserCenter = document.body.clientWidth / 2;

        //if(isIE6) var positionSettings = ['center','top'];
        var positionSettings = ['left', 'top'];


        $("." + m).css("display", "block")

        $("." + m).dialog({
            bgiframe: true,
            modal: true,
            position: positionSettings,
            dialogClass: m,
            width: 605,
            open: function(event, ui) {
                currentModal = $(this);
                var centerVal = browserCenter - ($(this).width() / 2);
                $(".ui-dialog").css("opacity", "0");
                $(".ui-dialog").css("marginTop", "100px");
                $(".ui-dialog").animate({ opacity: 1, marginLeft: centerVal + "px" }, 1000, "easeInOut", appendToForm);
                $(this).animate({ opacity: 1 }, 1000, "easeInOut");

            }
        });
    }

    //fixes .NET modal post back issue
    function appendToForm() {
        $(currentModal).parent().appendTo($("form:first"));
    }

    function closeModal() {

        $(".ui-dialog").animate({
            opacity: 0,
            marginLeft: (document.body.clientWidth - ($(".modalWrapper").width())) + "px"
        },
							1000,
							"easeInOut",
							destroyModal);
        $(currentModal).animate({ opacity: 0 }, 1000, "easeInOut");


    }

    function destroyModal() {
        $(currentModal).css("display", "none").dialog("destroy");
    }
	  
    function scAjaxEvent(evt, sVar, sEvalue){ //can take more than these 3 arguments
        s.events = evt;
        if(typeof(Locator) !== 'undefined'){
        	s.eVar1 = Locator.Config.AGNProduct;
        }
        if(typeof sVar!== 'undefined' && sVar!== null && sVar!== ''){ //track evar if passed in
        	s[sVar] = sEvalue;
        	if(arguments.length > 3){ //loop through remaining variables, passed in as key-value pairs
        		for(var i = 3, arg_len = arguments.length; i < arg_len; i++){
        			if(i%2 != 0){ //only set if i is an odd #, as evens store values
	        			var tmpCntr = i;
		        		s[arguments[i]] = arguments[tmpCntr+1];
	        		}
	        	}
        	}
        }
        void(s.t());
        //Clear variables
        s.events = "";  
        s[sVar] = "";
        if(arguments.length > 3){
        	for(var i = 3, arg_len = arguments.length; i < arg_len; i++){
    			if(i%2 != 0){ //only set if i is an odd #, as evens store values
	        		s[arguments[i]] = "";
        		}
        	}
        }
    }
    
    var scAjaxVariable = function(variable, value){
    	s[variable] = value;
    	void(s.t());
    };
    
    /*function SPOnError_handleErrors(msg,url,line){ //override sp error handler
    	if(typeof(console) !== 'undefined'){
    		console.log('message: ' + msg);
    		console.log('url: ' + url);
    		console.log('line: ' + line);
    	}
    }*/
    
    
