var PressQuote = {

    bubbleElement: null,
    bubbleContent: null,
    bubbleRight: null,
    bubbleRepeat: null,
    
    initialise: function()
    {
        $$('.homepagePress a').each(function(quoteLink){

            quoteLink.observe('click', function(e){
                e.stop();
            });

            quoteLink.observe('mouseover', function(e){
                this.showQuote(quoteLink, e);
            }.bind(this));

            quoteLink.observe('mouseout', function(e){
                this.hideQuote(quoteLink);
            }.bind(this));

        }.bind(this));

        this.bubbleElement = $$('.bubble')[0];
        this.bubbleContent = this.bubbleElement.down('.bubbleContent');
        this.bubbleRight = this.bubbleElement.down('.bubbleRight');
        this.bubbleRepeat = this.bubbleElement.down('.bubbleRepeat');
    },

    showBubble: function(content, width)
    {
        this.bubbleContent.update(content);

        this.bubbleRight.setStyle({left:(width-20)+'px'});
        this.bubbleRepeat.setStyle({width:(width-82)+'px'});
        this.bubbleContent.setStyle({width:(width-40)+'px'});


        this.bubbleElement.show();
    },

    showQuote: function(linkElement)
    {
        var quoteHTML = linkElement.down('.homepagePressQuote').innerHTML;

        var width = parseInt(linkElement.getParam('width'));
        var left = parseInt(linkElement.getParam('left'));

        this.showBubble(quoteHTML, width);

        this.bubbleElement.setStyle({
            left: (linkElement.cumulativeOffset().left - $(linkElement.parentNode).cumulativeOffset().left + left) + 'px',
            top: (linkElement.getOffsetParent().positionedOffset().top - (Utils.isIE() ? 100 : 80)) + 'px'
        });
    },

    hideQuote: function(element)
    {
        this.bubbleElement.hide();
    }
    
};

document.observe('dom:loaded', function(){
    PressQuote.initialise();
});
