/*global-block-begin*/


barrique.module.comment.HasCommentsDomain.prototype.onHrefBuilder = function(builder) {
    builder.addFragment('highlight', this.name_);
}


/*global-block-end*/
/*function-begin (getHeadHtml21) */
function getHeadHtml21() {
    var html = '';
    html += '\n\n\n\n';
    return html;
}
/*function-end (getHeadHtml21) */
/*function-begin (getBodyHtml21) */
function getBodyHtml21() {
    var html = '';
    html += '\n';
    return html;
}
/*function-end (getBodyHtml21) */
/*global-block-begin*/


barrique.base.artifact.domain.RootDomain.prototype.getHref = function() {
	return this.href_ ? this.href_ : barrique.contextPath;
}


/*global-block-end*/
/*function-begin (getHeadHtml1v) */
function getHeadHtml1v() {
    var html = '';
    html += '\n\n\n\n';
    return html;
}
/*function-end (getHeadHtml1v) */
/*function-begin (getBodyHtml1v) */
function getBodyHtml1v() {
    var html = '';
    html += '\n';
    return html;
}
/*function-end (getBodyHtml1v) */
/*global-block-begin*/


function openSearchDialog(contextArtifact) {
    var relationPath = contextArtifact ? contextArtifact.getRelationPath() : null,
        path = relationPath ? relationPath.getPath() : null;
    windowManager.openModalWindow(barrique.contextPath+'/sx/ArtifactHtmlPage?class=barrique.base.artifact.Artifact'+
            '&view=search-dialog'+(path ? '&path='+path : ''), 'SearchDialogWindow');
}


/*global-block-end*/
/*function-begin (getHeadHtml2n) */
function getHeadHtml2n() {
    var html = '';
    html += '\n\n\n\n';
    return html;
}
/*function-end (getHeadHtml2n) */
/*function-begin (getBodyHtml2n) */
function getBodyHtml2n() {
    var html = '';
    html += '\n';
    return html;
}
/*function-end (getBodyHtml2n) */
/*global-block-begin*/


barrique.module.docs.HasDocumentPart.prototype.onHrefBuilder = function(builder) {
    builder.addParameter('view', 'slides');
    builder.addFragment(null, this.name_);
}

function replaceRelativeUrls(value, attribute, prefix) {
    var current = window.location.pathname;
    if (current[current.length-1] != '/') { current += '/'; }
    //if (prefix == current) { return value; }
    
    var pattern = attribute+'="',
        buffer = value,
        i = 0;
    while ((i = buffer.indexOf(pattern, i)) > 0) {
        var e = buffer.indexOf('"', i+pattern.length);
        if (e >= 0) { 
            var url = buffer.substring(i+pattern.length, e),
                replacement = null;
            if (url[0] == '/') {
                replacement = barrique.contextPath+url;
            } else if (url.indexOf(':') < 0) {
                replacement = prefix+url;
            }
            if (replacement) {
                buffer = buffer.substring(0, i+pattern.length)+replacement+buffer.substring(e, buffer.length);
                i = e-url.length+replacement.length;
            } else {
                i = e;
            }
        } else {
            i += i+pattern.length;
        }
    }
    return buffer;
}

barrique.module.docs.text.Paragraph.prototype.getContentValue = function(edit) {
    var value = this.getContent() != null ? this.getContent().getValue() : '',
        relationPath = this.getRelationPath();
    if (relationPath) {
        var prefix = edit ? window.location.pathname : relationPath.getHref(relationPath.getSegments().length-2);
        if (prefix[prefix.length-1] != '/') { prefix += '/'; }
        value = replaceRelativeUrls(value, 'href', prefix);
        value = replaceRelativeUrls(value, 'src', prefix);
    }
    
    return value;
}

barrique.module.docs.HasDocumentPart.prototype.getDefaultPresentationHints = function() {
    return ' context ';
}
barrique.module.docs.MultiPartDocument.prototype.getDefaultPresentationHints = function() {
    return ' context featured ';
}
barrique.module.docs.MultiPartDocument.prototype.prunedPartCount_ = 0;
barrique.module.docs.MultiPartDocument.prototype.setPrunedPartCount = function(prunedPartCount) {
    this.prunedPartCount_ = prunedPartCount;
}
barrique.module.docs.MultiPartDocument.prototype.getPrunedPartCount = function(prunedPartCount) {
    return this.prunedPartCount_;
}
barrique.module.docs.MultiPartDocument.prototype.getLastModifiedCompound = function() {
    var lastModified = this.getLastModified();
    var parts = this.getParts();
    for (var i = 0; i < parts.length; i++) {
        var part = parts[i].getTarget();
        if (lastModified < part.getLastModified()) {
            lastModified = part.getLastModified();
        }
    }
    return lastModified;
}
barrique.module.docs.MultiPartDocument.prototype.getLastModifiedCompoundJavaClass = function() {
    return 'java.util.Date';
}


/*global-block-end*/
/*function-begin (getHeadHtml1j) */
function getHeadHtml1j() {
    var html = '';
    html += '\n\n\n\n';
    return html;
}
/*function-end (getHeadHtml1j) */
/*function-begin (getBodyHtml1j) */
function getBodyHtml1j() {
    var html = '';
    html += '\n';
    return html;
}
/*function-end (getBodyHtml1j) */
/*global-block-begin*/


barrique.module.attachment.HasAttachment.prototype.getDefaultPresentationHints = function() {
    return ' context ';
}


/*global-block-end*/
/*function-begin (getHeadHtml31) */
function getHeadHtml31() {
    var html = '';
    html += '\n\n\n\n';
    return html;
}
/*function-end (getHeadHtml31) */
/*function-begin (getBodyHtml31) */
function getBodyHtml31() {
    var html = '';
    html += '\n';
    return html;
}
/*function-end (getBodyHtml31) */
