
var myHeight;
function alertSize() {
  var myWidth = 0; 
  if( typeof( window.innerWidth ) == 'number' ) {

    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

}

var scrOfX = 0, scrOfY = 0;

function getScrollXY() {
  
  if( typeof( window.pageYOffset ) == 'number' ) {

    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {

    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function umbSpeechBubble(icon, header, message) {
    alertSize();
    getScrollXY();
	var speechBubble = document.getElementById("speechbubble");
	var speechBubbleShadow = document.getElementById("speechbubbleShadow");
	document.getElementById("speechHeader").innerHTML = header;
	document.getElementById("speechMessage").innerHTML = message;
	document.getElementById("speechIconSrc").src = 'images/speechBubble/' + icon + '.gif';
	
	      speechBubble.style.left = document.body.clientWidth - 264;
	speechBubbleShadow.style.left = document.body.clientWidth - 269;


	      speechBubble.style.top = scrOfY + myHeight - 110;
	speechBubbleShadow.style.top = scrOfY + myHeight - 111;
	      speechBubble.style.visibility = 'visible';
	speechBubbleShadow.style.visibility = 'visible';
	umbSpeechBubbleShow(0);
}

function umbSpeechBubbleShow(opacity) {
	document.getElementById("speechbubble").style.filter = 'Alpha(Opacity=' + opacity + ')';
	document.getElementById("speechbubbleShadow").style.filter = 'Alpha(Opacity=' + parseInt(opacity/2) + ')';		
	opacity = parseInt(opacity)+10;
	if (opacity < 101) 
		setTimeout("umbSpeechBubbleShow(" + opacity + ");", 50);
	else {
		setTimeout("umbSpeechBubbleHide(100);", 5000);
	}
}

function umbSpeechBubbleHide(opacity) {
	document.getElementById("speechbubble").style.filter = 'Alpha(Opacity=' + opacity + ')';
	document.getElementById("speechbubbleShadow").style.filter = 'Alpha(Opacity=' + parseInt(opacity/2) + ')';

	opacity = parseInt(opacity)-10;
	if (opacity > 1)
		setTimeout("umbSpeechBubbleHide(" + opacity + ");", 50);
	else {
		document.getElementById("speechbubble").style.visibility = 'hidden';
		document.getElementById("speechbubbleShadow").style.visibility = 'hidden'
	}
}

         
   function OnCompleteAdd(arg)
   {		           
        //alert(arg);
        if (arg)
        {	    
          
	       $('<div class="quick-alert">&nbsp;&nbsp;&nbsp;</div>')           
              .insertBefore($('#AddToCart'))           
              .fadeIn('slow')           
              .animate({opacity: 5.0}, 2000)           
              .fadeOut('fast', function() {           
                $(this).remove();
                $('#AddToCart').html('&lt;&lt; successfully added&nbsp;&nbsp;'); 
              }); 
              $('#topright-cartitems').fadeIn('slow');
           
           CMS.Presentation.WebServices.CartServices.GetCartItems(OnCompleteItems, OnTimeOut, OnError);
         }                
         else 
         {
            $('#AddToCart').html('&lt;&lt; unable to add&nbsp;&nbsp;');
         }    
    }
    
    function OnCompleteItems(arg)
    {			         
        if (arg > -1)
        {
            $('#topright-cartitems')
                .fadeIn('slow', function() {           
                $('#topright-cartitems').html('(' + arg + ') items in your cart');
            });
        }
        else
        {
            $('#topright-cartitems').html('unabled to find');
        }     
    }

    function OnTimeOut(arg)
    {
	    $('#AddToCart').html('&lt;&lt; unable to add&nbsp;&nbsp;');
    }

    function OnError(arg)
    {
	    $('#AddToCart').html('&lt;&lt; unable to add&nbsp;&nbsp;');
    }

