function submitform(thisform)
{
    document.forms[thisform].submit();
}

function openHref(link,w) {
    if(w==0) {
        window.location = link;
    } else {
        window.open(link, "_blank");
    }
}


function ddMenu() {
            
    $('#lmenu ul').hide();
    $('#lmenu ul:eq(0)').show(function(){
		$('#lmenu ul:eq(0) li a').css("font-weight","bold");;
	});
	 
    $('#lmenu li a').click(function() {
        
        var checkElement = $(this).next();
                
        if((checkElement.is('ul')) && (checkElement.is(':visible')) && (checkElement.attr('class')!='opened')) { //becsukás   
            //checkElement.slideUp('slow');
            slideToggle(checkElement);
            return false;
            
        }
        
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { //lenyitás
		
			//alert(checkElement.is(':visible'));
            
            $('#lmenu ul:visible').slideUp('slow');
			
            //checkElement.slideDown('slow');
            slideToggle(checkElement);
            
            /*$('#menu ul:visible').hide('fast', function() {
                $('#menu ul').fadeOut(10);
            });
            checkElement.show('slow', function() {
                checkElement.fadeIn(500);
            });*/
            
            return false;
            
        }
		/*
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			$('#lmenu ul:visible').slideUp('slow');
			slideToggle(checkElement);
			//return false;
		}
        */
    });
    
}

function slideToggle(el, bShow){
    var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
    
    if( arguments.length == 1 ) bShow = !visible;
    
    // if the current visiblilty is the same as the requested state, cancel
    if( bShow == visible ) return false;
    
    // get the original height
    if( !height ){
        // get original height
        height = $el.show().height();
        // update the height
        $el.data("originalHeight", height);
        // if the element was hidden, hide it again
        if( !visible ) $el.hide().css({height: 0});
    }
    
    // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
    if( bShow ){
        $el.show().animate({height: height}, {duration: 'slow'});
    } else {
        $el.animate({height: 0}, {duration: 'slow', complete:function (){
                $el.hide();
            }
        });
    }
}


$(document).ready(function() {
	
    ddMenu();
    
    /*$('#bal_kep').height($('#bal_kep').find("img").height());*/
    
    $('.u').each(function(){
        
        var name = $(this).html();
        
        $(this).addClass('underlined');
        
        $(this).html('<span class="underline">' + name + '</span>');
        
    });
    
    $('.button').each(function(){
        
        var name = $(this).html();
        
        var actions = $(this).attr('title');
        
        $(this).attr('title', name);
        
        $(this).addClass('.butt');
        
        $(this).html('<div class="butt"><div class="buttleft"></div><a ' + actions + '>' + name + '</a><div class="buttright"></div></div>');
        
    });
        
    $('.butt').hover(function(){
        $(this).find("a")
            .css("background", "0 0 repeat-x transparent url('../images/buttma.png')")
            .css("color", "#027862");
        $(this).find(".buttleft").css("background", "0 0 repeat-x transparent url('../images/buttla.png')");
        $(this).find(".buttright").css("background", "0 0 repeat-x transparent url('../images/buttra.png')");
    },
    function(){
        $(this).find("a")
            .css("background", "0 0 repeat-x transparent url('../images/buttm.png')")
            .css("color", "#fff");
        $(this).find(".buttleft").css("background", "0 0 repeat-x transparent url('../images/buttl.png')");
        $(this).find(".buttright").css("background", "0 0 repeat-x transparent url('../images/buttr.png')");
    });
    
    
    $('.vissza').click(function () { 
                
        window.location = 'javascript:history.back()'; 
         
    });
    
    if ($('#msgbox_form').exists()) {
        $('#login_overlay').fadeTo('fast','0.7');
        center('#msgbox_form');
        $('body').css('overflow', 'hidden');
        $('#msgbox_form').fadeTo('fast','1');
    }
    
    $('#msgbox_close').click(function(){
        $('#msgbox_form').css('display','none');
        $('#login_overlay').css('display','none');
        $('body').css('overflow', 'auto');
    });
    
    
    /* aktiv menü */
    $('#lmenu li').each(function(){
        
        if($(this).attr('class')=='opened') {
            
            var checkElement = $(this).find('a').next();
            
            checkElement.slideDown('slow');
            
            return false;
            
        }
    
    });
    //alert ($("#frefi").width());
});

function center(div) {
    $(div).css("position","absolute");
    $(div).css("top", ( $(window).height() - $(div).height() ) / 2+$(window).scrollTop() + "px");
    $(div).css("left", ( $(window).width() - $(div).width() ) / 2+$(window).scrollLeft() + "px");
    return false;
}


(function($) {

	$.fn.defaulttext = function(settings) {
		
		settings = jQuery.extend({
			text: 'Írj be valamit'
		},settings);
        
        if ($(this).attr('value') == '') {
            $(this).attr('value', settings.text);
        }
        
        $(this).focus(function(e){
            if ($(this).attr('value') == settings.text) {
                $(this).attr('value', '');
            }
        });
        
        $(this).blur(function(e){
            if ($(this).attr('value') == '') {
                $(this).attr('value', settings.text);
            }
        });
	};
    
    $.fn.exists = function() {
        
        return $(this).length>0;
        
    };
    
    $.fn.mailto = function() {
    	return this.each(function(){
    		var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
    		$(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
    	});
    };
    
})(jQuery);
