function TabSet(parentId)
{
    //-------------------------------------------------------------------------
    /*
    ** Constructor code
    */
    this.tabs = new Array();
    this.parentElement = document.getElementById(parentId);
    this.tabSet = document.createElement('ul');
    this.tabSet.className = 'tabs';
    this.parentElement.appendChild(this.tabSet);
    this.activeIndex = null;
    this.usePlaceholder = false;
    //-------------------------------------------------------------------------
    /*
    ** Add a tab to the tabset
    **
    ** @param tabName - Name of tab
    ** @param contentId - Id of element to show/hide on click of tab
    ** @param active - Make this tab active immediately
    */
    this.addTab = function(tabName, contentId, active)
    {
        var tab = document.createElement('li');
        tab.innerHTML = tabName;
        tab.contentBodyElementId = contentId;
        tab.tabSet = this;
        tab.index = this.tabs.length;
        tab.classExtra = contentId;
        this.tabSet.appendChild(tab);
        this.tabs.push(tab);
        if(active)
        {
            tab.className = 'tab active ' + tab.classExtra;
        }
        else
        {
            tab.className = 'tab inactive ' + tab.classExtra;
        }
        tab.onclick = function()
        {
            var tabSet = tab.tabSet;
            for(i = 0; i < tabSet.tabs.length; i++)
            {

                var contentBody = document.getElementById(tabSet.tabs[i].contentBodyElementId);
                if(tab != tabSet.tabs[i] && tabSet.tabs[i].className != 'tab placeholder')
                {
                    tabSet.tabs[i].className = 'tab inactive ' + tabSet.tabs[i].classExtra;
                    //contentBody.hide();
                    contentBody.style.display = 'none';
                }
                else if (tabSet.tabs[i].className != 'tab placeholder')
                {
                    tabSet.tabs[i].className = 'tab active ' + tabSet.tabs[i].classExtra;
                    //contentBody.show();
                    contentBody.style.display = '';
                }
            }
            if(tabSet.activeIndex != null)
            {
                tabSet.orderTabs(tab.index);
            }
        }
    }

    this.activateTab = function(tabName)
    {
        var index = 0;
        for(i = 0; i < this.tabs.length; i++)
        {
            var contentBody = document.getElementById(this.tabs[i].contentBodyElementId);
            if(this.tabs[i].innerHTML == tabName)
            {
                this.tabs[i].className = 'tab active ' + this.tabs[i].classExtra;
                contentBody.style.display = '';
                index = i;
            }
            else
            {
                this.tabs[i].className = 'tab inactive '  + this.tabs[i].classExtra;
                contentBody.style.display = 'none';
            }

        }
        if(this.activeIndex != null)
        {
            this.orderTabs(index);
        }
    }

    this.setActiveIndex = function(activeIndex)
    {
        this.activeIndex = activeIndex;
        var index = 0;
        for(i = 0; i < this.tabs.length; i++)
        {
            if(this.tabs[i].className == 'tab active ' + this.tabs[i].classExtra)
            {
                index = i;
                break;
            }
        }
        this.orderTabs(index);
    }

    this.orderTabs = function(startIndex)
    {
        if(this.activeIndex != null)
        {
            for(i = 0; i < this.tabs.length; i++)
            {
                this.tabSet.removeChild(this.tabs[i]);
            }
            if (this.usePlaceholder) {
                for(i = 0; i < this.tabs.length; i++) {
                    if (this.tabs[i].className == 'tab placeholder') {
                        this.tabs.splice(i, 1);
                    }
                }
            }
            var index = this.activeIndex + startIndex >= this.tabs.length ? this.activeIndex + startIndex - this.tabs.length : this.activeIndex + startIndex;
            if (this.usePlaceholder) {
                var placeholder = document.createElement('li');
                placeholder.className = 'tab placeholder';
                var placeholderIndex = index + 1 >= this.tabs.length + 1 ? 0 : index + 1;
                this.tabs.splice(placeholderIndex, 0, placeholder);
            }
            for(i = 0; i < this.tabs.length; i++)
            {
                this.tabSet.appendChild(this.tabs[index]);
                index = index + 1 >= this.tabs.length ? 0 : index + 1;
            }
        }
    }
}

function setCookie (name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
	(path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
	document.cookie = curCookie;
}

function getCookie (name) {
	var prefix = name + '=';
	var c = document.cookie;
	var nullstring = '';
	var cookieStartIndex = c.indexOf(prefix);
	if (cookieStartIndex == -1)
		return nullstring;
	var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = c.length;
	return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
	if (getCookie(name))
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	now = now.toGMTString();
	if (f.author != undefined)
		setCookie('mtcmtauth', f.author.value, now, '/', '', '');
	if (f.email != undefined)
		setCookie('mtcmtmail', f.email.value, now, '/', '', '');
	if (f.url != undefined)
		setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
	deleteCookie('mtcmtmail', '/', '');
	deleteCookie('mtcmthome', '/', '');
	deleteCookie('mtcmtauth', '/', '');
	f.email.value = '';
	f.author.value = '';
	f.url.value = '';
}

function hideDocumentElement(id) {
	var el = document.getElementById(id);
	if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
	var el = document.getElementById(id);
	if (el) el.style.display = 'block';
}

function showAnonymousForm() {
	showDocumentElement('comments-form');
}

var commenter_name;
var commenter_blog_ids;
var is_preview;
var mtcmtmail;
var mtcmtauth;
var mtcmthome;

var commenter_name;

function individualArchivesOnLoad(commenter_name) {
    hideDocumentElement('comments-open');
    if (commenter_name) {
        hideDocumentElement('name-email');
        showDocumentElement('comments-open-text');
        showDocumentElement('comments-open-footer');
    } else {
        hideDocumentElement('comments-open-data');
        hideDocumentElement('comments-open-text');
        hideDocumentElement('comments-open-footer');
    }

    var mtcmtauth;
    var mtcmthome;
    if (document.comments_form) {
        if (!commenter_name && (document.comments_form.email != undefined) &&
            (mtcmtmail = getCookie("mtcmtmail")))
            document.comments_form.email.value = mtcmtmail;
        if (!commenter_name && (document.comments_form.author != undefined) &&
            (mtcmtauth = getCookie("mtcmtauth")))
            document.comments_form.author.value = mtcmtauth;
        if (document.comments_form.url != undefined && 
            (mtcmthome = getCookie("mtcmthome")))
            document.comments_form.url.value = mtcmthome;
        if (document.comments_form["bakecookie"]) {
            if (mtcmtauth || mtcmthome) {
                document.comments_form.bakecookie.checked = true;
            } else {
                document.comments_form.bakecookie.checked = false;
            }
        }
    }
}

function fbs_click()
{
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function mtShow(id) {
    var el = (typeof id == "string") ? document.getElementById(id) : id;
    if (el) el.style.display = 'block';
}
function mtSetCommentParentID() {
    var checkbox = document.getElementById('comment-reply');
    var parent_id_field = document.getElementById('comment-parent-id');
    if (!checkbox || !parent_id_field) return;
    var pid = 0;
    if (checkbox.checked == true)
        pid = checkbox.value;
    parent_id_field.value = pid;
}
function mtReplyCommentOnClick(parent_id, author) {
    mtShow('comment-form-reply');
    if (author == '')
       author = 'Anonymous';
    var checkbox = document.getElementById('comment-reply');
    var label = document.getElementById('comment-reply-label');
    var text = document.getElementById('commentinputtext');
    // Populate label with new values
    var reply_text = 'Replying to <a href="#comment-'+ parent_id +'" onclick="location.href=this.href; return false">comment from '+ author +'</a>';
    label.innerHTML = reply_text;
    checkbox.value = parent_id; 
    checkbox.checked = true;
    text.focus();
    mtSetCommentParentID();
}

function socialInsert(sButton, sParent, sSrc) {
    switch(sButton) {
        case 'retweetShare':
            var s = document.createElement('iframe');
            s.setAttribute('scrolling', 'no');
            s.setAttribute('width', '90');
            s.setAttribute('height', '20');
            s.frameborder = 0;
            s.setAttribute('src', sSrc);
            break;
        case 'facebookShare':
            var s = document.createElement('script');
            s.setAttribute('async', 'true');
            s.setAttribute('type', 'text/javascript');
            s.setAttribute('src', 'http://static.ak.fbcdn.net/connect.php/js/FB.Share');
            break;
        case 'facebookLike':
            var s = document.createElement('iframe');
            s.setAttribute('scrolling', 'no');
            s.setAttribute('width', '90');
            s.setAttribute('height', '21');
            s.frameborder = 0;
            s.setAttribute('allowTransparency', 'true');
            s.setAttribute('style', 'border:none; overflow:hidden; width:90px; height:21px');
            s.setAttribute('src', sSrc);
            break;
        case 'diggShare':
            var s = document.createElement('script');
            s.setAttribute('async', 'true');
            s.setAttribute('src', 'http://widgets.digg.com/buttons.js');
            break;
    }

    var sName = sButton + '-' + sParent;
    document.getElementById(sName).appendChild(s);
}


window.onload=function(){individualArchivesOnLoad(commenter_name)};