
//document.onclick = function(){alert('hello')};
//var Opacity = 0;

//ContactCard class
function ContactCard(Element, Card)
{
    this.Card = Card;
    this.Opacity = 0;
    var d = new YAHOO.util.DD(this.Card);
    this.Element = Element;
    
    this.Element.onclick = function(e){OpenCard(e, Card)};
    
    var cardcontents = Card.getElementsByTagName("span");
    
    
    
    for(i=0; i<cardcontents.length; i++)
    {
        if(cardcontents[i].className=="contactclose")
        {
            cardcontents[i].onclick = function(e){CloseCard(e, Card)};
        }
    }
}

function OpenCard(e, Card)
{
    this.Opacity = 0;
    ChangeOpacity(this.Opacity, Card);
    Card.style.display='block';
    
    var X = getMousePosition(e, "X") - 109;
    var Y = getMousePosition(e, "Y") - 70;
    
    
    
    Card.style.left = X+"px";
    Card.style.top = Y+"px";
    
    IncreaseCardOpacity(this.Opacity, Card);
}

function CloseCard(e, Card)
{
    this.Opacity = 100;
    ChangeOpacity(Opacity, Card);
    
    DecreaseCardOpacity(this.Opacity, Card);
}


function getMousePosition(e, Axis) 
{
	var _x;
	var _y;
	
	if (e==null) 
	{
		_x = event.clientX + document.body.scrollLeft;
		_y = event.clientY + document.body.scrollTop;
	}
	else
	{
		_x = e.pageX;
		_y = e.pageY;
	}
	
	if(Axis.toLowerCase()=="x") return _x;
	if(Axis.toLowerCase()=="y") return _y;
	return true;
}


function ChangeOpacity(newOpacity, Card) 
{
    /* helper function to deal specifically with images and the cross-browser differences in opacity handling */
    var obj=Card;
    if (obj.style) 
    {
	    if (obj.style.MozOpacity!=null) 
	    {  
		    /* Mozilla's pre-CSS3 proprietary rule */
		    obj.style.MozOpacity = (newOpacity/100) - .001;
	    } 
	    else if (obj.style.opacity!=null) 
	    {
		    /* CSS3 compatible */
		    obj.style.opacity = (newOpacity/100) - .001;
		    
	    } 
	    else if (obj.style.filter!=null) 
	    {
		    /* IE's proprietary filter */
		    obj.style.zoom = 1;
		    obj.style.filter = "alpha(opacity="+newOpacity+")";
		    //alert(obj.style.filter);
	    }
	    
    }
}

function DecreaseCardOpacity(Opacity, Card)
{
    ChangeOpacity(Opacity, Card);
    
    if(Opacity>0)
    {
        Opacity -= 10;
        setTimeout(function(){DecreaseCardOpacity(Opacity, Card)}, 30);
    }
    else
    {
        Card.style.display='';
    }
}

function IncreaseCardOpacity(Opacity, Card)
{
    ChangeOpacity(Opacity, Card);
    
    if(Opacity<100)
    {
        Opacity += 10;
        setTimeout(function(){IncreaseCardOpacity(Opacity, Card)}, 30);
    }
}


