// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

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;

function individualArchivesOnLoad(commenter_name) {



    hideDocumentElement('trackbacks-info');



    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 writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) {

}



$(function() {
        
    $('.tab-box').each(function() {
            var el = $(this);
            el.find('span.title').click($.orTabBox.showTab)
                    .eq(0).trigger('click');   
    });

    $('.tab-box2').each(function() {
            var el = $(this);
            el.find('span.title2').click($.orTabBox2.showTab)
                    .eq(0).trigger('click');   
    });
});

//tab-box
$.orTabBox = {};

$.orTabBox.showTab = function() {
        var el = $(this);
        el.parent().find('span.title').removeClass('selected');
        el.addClass('selected');
        
        var pos = el.prevAll().length;
        el.closest('.tab-box').find('.content').hide().eq(pos).show();
        return false;
};

$.orTabBox2 = {};

$.orTabBox2.showTab = function() {
        var el = $(this);
        el.parent().find('span.title2').removeClass('selected');
        el.addClass('selected');
        
        var pos = el.prevAll().length;
        el.closest('.tab-box2').find('.content2').hide().eq(pos).show();
        return false;
}; 

//Tooltips Script

        var insertPoint;
        var iconLabel;
        var iconLabelTxt;
        
        function createIconLabel() {
                if (document.getElementById && document.createElement) {
                        insertPoint = document.getElementById('container');
                        iconLabel = document.createElement('SPAN');
                        iconLabelTxt = document.createElement('P');
                        
                        iconLabel.appendChild(iconLabelTxt);
                        insertPoint.appendChild(iconLabel);
                        iconLabel.className = "icon-label-hidden";
                }
        }
        
        
        function showIconLabel(obj) {
                if (document.getElementById && document.createElement) {
                        var imgList = obj.getElementsByTagName('IMG');
                        var imgAlt = imgList[0].getAttribute('ALT');
                        var txt = document.createTextNode(imgAlt);
                        
                        
                        //If the label already has text, change the text
                        if (iconLabelTxt.childNodes.length > 0) {
                                iconLabelTxt.firstChild.nodeValue = txt.nodeValue;
                        }
                        //Else, add a text node to the label
                        else {
                                iconLabelTxt.appendChild(txt);
                        }
                        
                        iconLabel.className = "icon-label";
                        
                        //Find the position of the icon
                        var posArray = new Array();
                        posArray = findPos(obj);
                        
                        posArray[0] = posArray[0] - iconLabel.offsetWidth + obj.offsetWidth;
                        posArray[1] = posArray[1] + obj.offsetHeight;
                        
                        //Position the icon label
                        iconLabel.style.left = "" + posArray[0] + "px";
                        iconLabel.style.top = "" + posArray[1] + "px";
                }
        }
        
        
        function hideIconLabel() {
                iconLabel.className = "icon-label-hidden";
        }
        
        
        function findPos(obj) {
                var curleft = curtop = 0;
                
                if (obj.offsetParent) {
                        do {
                                curleft += obj.offsetLeft;
                                curtop += obj.offsetTop;
                        }
                        while (obj = obj.offsetParent);
                }
                
                return [curleft,curtop];
        }

//Latest Features

	var featureList;
	var featureListArray;
	var featureNav;
		
	function createList() {
		//If the browser has the required functionality, move forward
		if (document.getElementById && document.createElement) {
			//Find the feature list
			featureList = document.getElementById('latest-feature-list');
			featureListArray = featureList.getElementsByTagName('LI');
			
			//If there is more than one feature, move forward
			if (featureListArray.length > 1) {
				//Hide everything but the first feature
				for (var i = 1; i < featureListArray.length; i++) {
					featureListArray[i].style.display = "none";
				}
						
				//Find the parent node of the feature list
				var listParent = featureList.parentNode;
						
				//Create the nav to switch between the features
				featureNav = document.createElement('DIV');
				featureNav.className = "latest-feature-nav";
						
				//Add nav items for each item in the feature list
				for (var i = 1; i <= featureListArray.length; i++) {
					var featureLink = document.createElement('A');
					var featureLinkText = document.createTextNode(i);
					
					if (i == 1) {
						//Set the first nav item to selected
						featureLink.className = "selected";
					}
					
					//Add the href to the current nav item
					featureLink.setAttribute('href', 'javascript:showLatestFeature('+i 
+');');
					
					featureLink.appendChild(featureLinkText);
					featureNav.appendChild(featureLink);
				}
				
				//Add the feature nav after the feature list
				listParent.appendChild(featureNav);
			}
		}
	}
			
			
	function showLatestFeature(num) {
		//Run through each latest feature and display the selected one
		for (var i = 0; i < featureListArray.length; i++) {
			if (i == (num - 1)) {
				featureListArray[i].style.display = "block";
			}
			else featureListArray[i].style.display = "none";
			
		}
		
		var featureLink = featureNav.firstChild;
		
		//Run through the feature nav and set the selected item's class to  
"selected"
		for (var i = 1; i <= featureListArray.length; i++) {
			if (i == num) {
				//Set the first nav item to selected
				featureLink.className = "selected";
			}
			else featureLink.className = "";
			
			featureLink = featureLink.nextSibling;
		}
	}	


// eBook List
var createeBookList = function() {
    var list = document.getElementById('ebook-list');
    var items = list.getElementsByTagName('li');
    var pageList = document.getElementById('ebook-pages');
    for(var i = 0; i < items.length; i++) {
        pageList.appendChild(createPage(i, items, pageList));
    }
   showeBook(0, items, pageList.childNodes);
};

var createPage = function(i, items, pageList) {
    var a = document.createElement('a');
    a.href = '#';
    a.innerHTML = '&bull;';
    a.onclick = function() { 
        showeBook(i, items, pageList.childNodes); 
        return false;
    };
    return a;
};

var showeBook = function(selected, items, pages) {
    for(var i = 0; i < items.length; i++) {
        items[i].style.display = 'none';
        pages[i].className = '';
    }
    items[selected].style.display = 'block';
    pages[selected].className = 'selected';
};
