/*
 * BE BOX - TABS (FCUKED)
 * Copyright (c) 2008 - BELIEVE.cz (http://www.believe.cz/) 
 *
 */

$.fn.tabs = function(options) {
    // basic stuff
    var ON_CLASS = 'selected';
    var OFF_CLASS = 'tabs-hide';
    // options
    var on = options && options.on && (typeof options.on == 'number' && options.on > 0) ? options.on - 1 : 0;
    return this.each(function() {
        $(this).find('>div').not(':eq(' + on + ')').addClass(OFF_CLASS);
        $(this).find('>ul>li:eq(' + on + ')').addClass(ON_CLASS);
        var container = this;
        $(this).find('>ul>li>a').click(function() {
            if (!$(this.parentNode).is('.' + ON_CLASS)) {
                var re = /([_\-\w]+$)/i;
                var target = $('#' + re.exec(this.href)[1]);
                if (target.size() > 0) {
                    $(container).find('>div:visible').addClass(OFF_CLASS);
                    target.removeClass(OFF_CLASS);
                    $(container).find('>ul>li').removeClass(ON_CLASS);
                    $(this.parentNode).addClass(ON_CLASS);
                } else {
                    alert('There is no such container.');
                }
            }
            return false;
        });
    });
};


function makeContentTabs()
{
	var ix = 0;
	$(".contabs h2[@title]").each(function(){
		if(ix == 0) $(this).before("<ul class='texts'></ul>");
		newid = "s" + (ix + 1);
		var x = $(this).nextUntilInc("h2[@title]").wrapAll("<div class='fragment' id='" + newid + "'></div>");
		$(".contabs ul:eq(0)").append( "<li><a href='#" + newid + "'>" + $(this).attr('title') + "</a></li>");
		$(this).attr('title', '');		
		ix++;
	});
	$(".contabs").tabs();
}

$(document).ready(function() 
{
	$(".noscript").after('<input type="hidden" name="secret-name" value="' + $('#secret-number').text() + '" />').remove();
	makeContentTabs();

	// Init believeBox
	$.believeBox.groupNames = ['bebox'];
	$.believeBox.useHistory = false,
	// $.pdHijax.addController($.pdBox.showImageByHash);
	$('.tab').believeBox({minWidth: 540});	
});            

