// Copyright 2008 Google Inc.
// All Rights Reserved.

function getElementsByClass(searchClass, node, tag) {

    var classElements = new Array();
    if (node == null)
            node = document;
    if (tag == null)
            tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
            if (pattern.test(els[i].className)) {
                    classElements[j] = els[i];
                    j++;
            }
    }
    return classElements;
}

var current_feature = ''

// Toggles feature preview 
function showfeature(feature) {
    current_feature = feature
    featurethumb = document.getElementById(feature);
    featurepreview = document.getElementById(feature + '-preview');

    oldthumb = getElementsByClass('selected');
    if (oldthumb[0]) {
        oldthumb[0].className = '';
    }
    oldprev = getElementsByClass('visible');
    if (oldprev[0]) {
        oldprev[0].className = 'preview';
    }
    featurethumb.className = 'selected';
    featurepreview.className = 'visible preview';
}

// Displays the feature indicated by #feature= or onebox by default
function show_selected_feature() {
    var s = '#feature=([^#&]*)';
    var regex = new RegExp(s);
    var results = regex.exec(window.location.href);
    if (results != null) {
        showfeature(results[1]);
    } else {
		if(document.getElementById('overview')) {
			showfeature('overview');
		} else {
			showfeature('box');
		}
    }
}
