﻿/* readmorebox.js */

function ReadMoreBox(box, reviewArea, activationClickable, headerImage, partialReview, fullReview) {
    if (box != null && reviewArea != null && activationClickable != null && 
        headerImage != null && partialReview != null && fullReview != null) {
        this.box = box;
        this.reviewArea = reviewArea;
        this.activationClickable = activationClickable;
        this.headerImage = headerImage;
        this.partialReview = partialReview;
        this.fullReview = fullReview;
    }
}


ReadMoreBox.prototype.showPartialReview = function() {
    this.partialReview.style.display = 'inline';
}


ReadMoreBox.prototype.hidePartialReview = function() {
    this.partialReview.style.display = 'none';
}


ReadMoreBox.prototype.hideFullReview = function() {
    this.fullReview.style.display = 'none';
}


ReadMoreBox.prototype.showFullReview = function() {
    this.fullReview.style.display = 'inline';
}


ReadMoreBox.prototype.maximize = function(e) {
    if (this.box) {
        this.box.style.position = 'relative';
        this.box.style.width = '800px';
        this.box.style.height = '180px';
        this.box.style.background = 'white';
        this.box.style.zIndex = '100';


        this.headerImage.style.position = 'absolute';
        this.headerImage.style.top = '0px';
        this.headerImage.style.zIndex = '110';

        this.reviewArea.style.position = 'relative';
        this.reviewArea.style.top = this.headerImage.height + 'px';
        this.reviewArea.style.width = '810px';
        this.reviewArea.style.height = '130px';
        this.reviewArea.style.padding = '0 10px';
        this.reviewArea.style.overflow = 'auto';

        this.activationClickable.style.display = 'none';
        this.hidePartialReview();
        this.showFullReview();
    }
}


ReadMoreBox.prototype.init = function() {
    var self = this;
    if (self.activationClickable) {
        if (window.addEventListener) {
            this.activationClickable.addEventListener('click', function(event) { return self.maximize(event); }, true);
        }
        else { //(window.attachEvent)
            this.activationClickable.attachEvent('onclick', function(event) { return self.maximize(event); });
        }
    }
}


function createReadMoreBoxForQuotePage() {
    // only do this if page is fully loaded
    if (typeof $id != 'undefined') {
        var box = new ReadMoreBox(
		            document.getElementById('expandable'),
		            $id['reviewsSection'],
		            document.getElementById('readMore'),
		            document.getElementById('reviewHeaderPic'),
		            document.getElementById('partialReview'),
		            document.getElementById('fullReview')
		        );
        box.init();
        return box;
    }
    return null;
}







