$.fn.nextUntilInc = function(expr) 
{
    var match = [];
	match.push(this.get(0));
    // We need to figure out which elements to push onto the array
    this.each(function(){
        // Traverse through the sibling nodes
        for( var i = this.nextSibling; i; i = i.nextSibling ) {
            // Make sure that we're only dealing with elements
            if ( i.nodeType != 1 ) continue;

            // If we find a match then we need to stop
            if ( jQuery.filter( expr, [i] ).r.length ) break;

            // Otherwise, add it on to the stack
            match.push( i );
        }
    });
    return this.pushStack( match, arguments );
};

function makeContentTabs()
{
	var ix = 0;
	$(".contabs h2[@title]").each(function(){
		if(ix == 0) $(this).before("<ul class='anchors'></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="nejsemrob" value="' + $('#secret-number').text() + '" />').remove();
	makeContentTabs();

	// Init pdBox
	$.pdBox.groupNames = ['pripojene'];
	$.pdBox.useHistory = false,
	// $.pdHijax.addController($.pdBox.showImageByHash);
	$('.thickbox').pdBox({minWidth: 540});	

	
});            
