
var bubbleMouseOver = new Object();

bubbleMouseOver = function(containerDivId, popupDivId, popupTextDivId, topImgId, bottomImgId, closeImgId, topLeftImgSrc, topRightImgSrc, topNoneImgSrc, bottomLeftImgSrc, bottomRightImgSrc, bottomNoneImgSrc) {
    if(!this.isFlashPlayerEnabled()){
		return;
    }
    
    this.containerDiv = document.getElementById(containerDivId);
    this.topImg = document.getElementById(topImgId);
    this.bottomImg = document.getElementById(bottomImgId);
    this.popupDiv = document.getElementById(popupDivId);
    this.popupTextDiv = document.getElementById(popupTextDivId);
    this.topLeftImgSrc = topLeftImgSrc;
    this.topRightImgSrc = topRightImgSrc;
    this.topNoneImgSrc = topNoneImgSrc;
    this.bottomLeftImgSrc = bottomLeftImgSrc;
    this.bottomRightImgSrc = bottomRightImgSrc;
    this.bottomNoneImgSrc = bottomNoneImgSrc;
    
    this.closeImg = document.getElementById(closeImgId);
    this.closeImg.onclick = function(){document.getElementById(popupDivId).style.display="none"; document.getElementById(closeImgId).style.display="none";};
    
    this.quandrant = 1;
    this.curContainerDivPos = this.findPos(this.containerDiv);
};

bubbleMouseOver.prototype.showPopup = function(x, y, showClose, closedCallback, contentCallback) {
    
    this.popupDiv.style.display="none";
    this.popupTextDiv.innerHTML="Loading...";
    
    if(closedCallback != null)
        this.closeImg.onclick = closedCallback;
    else
        this.closeImg.onclick = function(){document.getElementById(popupDivId).style.display="none"; document.getElementById(closeImgId).style.display="none";};

    if (x <= this.containerDiv.scrollWidth/2 && y <= this.containerDiv.scrollHeight/2) {
        this.quadrant=1;
        this.setTopLeftStyles();
    } else if (x > this.containerDiv.scrollWidth/2 && y <=this.containerDiv.scrollHeight/2) {
        this.quadrant=2;
        this.setTopRightStyles();
    } else if (x <= this.containerDiv.scrollWidth/2 && y > this.containerDiv.scrollHeight/2) {
        this.quadrant=3;
        this.setBottomLeftStyles();
    } else if (x > this.containerDiv.scrollWidth/2 && y > this.containerDiv.scrollHeight/2) {
        this.quadrant=4;
        this.setBottomRightStyles();
        
    }

    contentCallback(this.popupTextDiv);

    this.popupDiv.style.display="block";
    if(showClose == true)
        this.closeImg.style.display="block";
    else
        this.closeImg.style.display="none";
    
    if (this.quadrant==1) {
        this.setTopLeftPosition(x, y);
    } else if (this.quadrant==2) {
        this.setTopRightPosition(x, y);
    } else if (this.quadrant==3) {
        this.setBottomLeftPosition(x, y);
    } else if (this.quadrant==4) {
        this.setBottomRightPosition(x, y);
    }
};

bubbleMouseOver.prototype.dataLoaded = function() {
    if (this.quadrant==3 || this.quadrant==4) {
        var delta = this.popupTextDiv.offsetHeight - this.bottomImg.offsetHeight;
        this.top -= delta;
        this.setPosition(this.top,this.left);
    }
}; 

bubbleMouseOver.prototype.findPos = function (obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {"offsetLeft":curleft,"offsetTop":curtop};
};


bubbleMouseOver.prototype.hidePopup = function() {
    this.popupDiv.style.display="none";
    this.closeImg.style.display="none";
};

bubbleMouseOver.prototype.setTopLeftStyles = function() {
    this.setTopImg(this.topLeftImgSrc);
    this.setBottomImg(this.bottomNoneImgSrc);
};

bubbleMouseOver.prototype.setTopRightStyles = function() {
    this.setTopImg(this.topRightImgSrc);
    this.setBottomImg(this.bottomNoneImgSrc);

};

bubbleMouseOver.prototype.setBottomLeftStyles = function() {
    this.setTopImg(this.topNoneImgSrc);
    this.setBottomImg(this.bottomLeftImgSrc);

};

bubbleMouseOver.prototype.setBottomRightStyles = function() {
    this.setTopImg(this.topNoneImgSrc);
    this.setBottomImg(this.bottomRightImgSrc);
};


bubbleMouseOver.prototype.setTopLeftPosition = function(x, y) {
    //show below and to the right
    this.top = this.curContainerDivPos.offsetTop+ y;
    this.left = this.curContainerDivPos.offsetLeft + x;
    this.setPosition(this.top,this.left);
};

bubbleMouseOver.prototype.setTopRightPosition = function(x, y) {
    //show below and to the left
    this.top = this.curContainerDivPos.offsetTop + y;
    this.left = this.curContainerDivPos.offsetLeft + x - this.popupDiv.scrollWidth;
    this.setPosition(this.top,this.left);
};

bubbleMouseOver.prototype.setBottomLeftPosition = function(x, y) {
    //show above and to the right
    this.top = this.curContainerDivPos.offsetTop  + y - this.popupDiv.scrollHeight;
    this.left = this.curContainerDivPos.offsetLeft + x;
    this.setPosition(this.top,this.left);
};

bubbleMouseOver.prototype.setBottomRightPosition = function(x, y) {
    //show above and to the left
    this.top = this.curContainerDivPos.offsetTop  + y - this.popupDiv.scrollHeight;
    this.left = this.curContainerDivPos.offsetLeft + x - this.popupDiv.scrollWidth;
    this.setPosition(this.top,this.left);
};

bubbleMouseOver.prototype.setPosition = function(offsetTop, offsetLeft) {
    //show above and to the left
    this.popupDiv.style.top = offsetTop + "px";
    this.popupDiv.style.left = offsetLeft + "px";
    
    var offset = 5;
    if (this.quadrant==1 || this.quadrant==2)
        offset = 23;
    this.closeImg.style.top = offsetTop + offset + "px"
    this.closeImg.style.left = offsetLeft + 250 + "px"
};



bubbleMouseOver.prototype.setTopImg = function(img) {
    this.topImg.src=img;
};


bubbleMouseOver.prototype.setBottomImg = function(img) {
    this.bottomImg.src=img;
};


bubbleMouseOver.prototype.isFlashPlayerEnabled = function() {
	var enabled = true;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x) {
			enabled = true;
		}
		else{
			enabled = false;
		}
	}
	return enabled;
};

