// Document on load
$(document).ready(function(){
	$('.submenuItems').hide();

	var lastShown = null;
	$('.menuItem').bind("mouseenter",function()
		{
		var sub = this.id.replace('menu_', 'sub_');
		if(lastShown == sub)
			{
			return;
			}

		if(lastShown != null)
			{
			$('#'+lastShown).hide();
			lastShown = null;
			}

		$('#'+sub).css('top',$(this).height() + $(this).position().top);
		$('#'+sub).css('left', $(this).position().left);
		$('#'+sub).show(300);
		lastShown = sub;
	    });

	activateTabs();
    
    
    // Some ajax setup
    $.ajaxSetup({
        error:function(x,e)
            {
            if(x.status==0){
            alert('You are offline!!\n Please Check Your Network.');
            }else if(x.status==404){
            alert('Requested URL not found.');
            }else if(x.status==500){
            alert('Internel Server Error.');
            }else if(e=='parsererror'){
            alert('Error.\nParsing JSON Request failed.');
            }else if(e=='timeout'){
            alert('Request Time out.');
            }else {
            alert('Unknow Error.\n'+x.responseText);
            }
            
            if(hideLoader)
                hideLoader();
            }
        });      
	});

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function activateTabs()
	{
	$('.tabs .tab a').click(function(){
		var className = $(this).parent().attr('class');
		className = className.replace("tab", "").replace("active", "").trim();
		$('.tabs .tab').removeClass('active');
		$(this).parent().addClass('active');

		$('.tabContent').hide();
		$('.tabContent.' + className).show();
		return false;
	});
	// Zobrazi sa iba prva zalozka
	$('.tabContent').hide();
	$('.tabs .tab:first a').click();

	// skryju sa rozbalovacie polozky
	$('.objectInfo').hide();
	$('.objectName a').click(function(){
		var img = $(this).parent().find('img');
		if($(this).parent().next().is(':visible'))
			img.attr('src', img.attr('src').replace('minus.gif', 'plus.gif'));
		else
			img.attr('src', img.attr('src').replace('plus.gif', 'minus.gif'));

		$(this).parent().next().slideToggle();

		return false;
	});
	$('.objectName a:first').click();
	$('.openWindow').click(function(){
		window.open(this.href);
		return false;
	});
	}


/**
 *
 * @access public
 * @return void
 **/
function showBText(txt)
	{
	if($('#textInfoBox').length == 0)
		{
		$('body').append("<div id=\"textInfoBox\"></div>");
		}

	$('#textInfoBox').css({'position':'absolute', 'top' : '0px', 'left': '0px', 'background': 'white', 'padding': '5px'});
	$('#textInfoBox').html(txt + "<br />" + $('#textInfoBox').html());
	}
