//---------------------------------------------------------------------------------//
function addNewToAddressDiv() {
   var toEmailsDiv = document.getElementById("toEmails");
   var children = toEmailsDiv.getElementsByTagName('DIV');
   var totalDivsInToEmail = 7;
   var position = (children.length / totalDivsInToEmail) + 1;
   var url = "index.php?_spAction=newToEmailDiv&position=" + position + "&showHTML=0";

   XMLHTTP.xmlHttpObj = XMLHTTP.getXMLHTTPObject(addNewToAddressDivHandler);
   XMLHTTP.xmlHttpObj.open("POST", url, true);
   XMLHTTP.xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   XMLHTTP.xmlHttpObj.send(null);
}

//=====================================================//
function addNewToAddressDivHandler() {
   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") {
      var responseText = XMLHTTP.xmlHttpObj.responseText;

      var toEmailsDiv = document.getElementById("toEmails");
      var toEmailDiv = document.createElement("DIV");
      toEmailDiv.innerHTML = responseText;
      toEmailsDiv.appendChild(toEmailDiv);
   }
}


//=====================================================//
UtilWindow = new Object();

UtilWindow.openWindow = function (url, width, height) {
   var left = (screen.width-width)/2;
   var top  = (screen.height-height)/2;

   var params = "height=" + height + ",width=" + width + ",scrollbars=yes," +
                "resizable=yes" + ",left=" + left + ",top=" + top;
   var a = window.open(url,"", params);
}

//=====================================================//
$(function() {
    //return;
    var current = 0;
    var total = $('#quotesContainer .quote').hide().length;

    $('#quotesContainer').hover(function() {
        $('#quotesContainer .quote:eq(' + current + ')').stop();
    },
    function() {
        showAnimation(false);
    });

    function showAnimation(resetTop) {    
        if (resetTop == undefined) {
            resetTop = true;
        }
        var containerHeight = $('#quotesContainer').height();
        var height = $('#quotesContainer .quote:eq(' + current + ')').height();
        var top = height + 2;
        var secsPerScreen = 5000; //*** for the height of container normally 120px
        var duration = (height / containerHeight) * secsPerScreen;
    
        $('#quotesContainer .quote:eq(' + current + ')')
        .show();
        
        if (resetTop) {
            $('#quotesContainer .quote:eq(' + current + ')')
            .css('top', containerHeight + 'px')
        }
        
        $('#quotesContainer .quote:eq(' + current + ')')
        .animate(
            {
            top: '-' + top + 'px'
            }, 
            duration,
            function() {
                current++;
                if (current > total - 1) {
                   current = 0;
                }
                showAnimation();
            }
        );
    }
    
    showAnimation();
    
});






