var menu_vis = $('#menu_lang').css('display') == 'none' ? false : true;
var sm = false;
var timer = false;
var setGender = false;
$(document).ready(function() {
   $('#lang_value').click(menu);
   $('#menu_lang').mouseout(closemenu);
   $('#menu_lang').mouseover(setmenu);
   $('html').keyup(debugSH).keyup(msgSH).keyup(pwdSH);
});
function menu() {
    $('#menu_lang').slideDown('slow');
//    $('#menu_lang').css('display','block');
    //sm = false;
    
}
function closemenu() {
    //if(sm)  $('#menu_lang').css('display','none');
    //if(sm)  $('#menu_lang').fadeOut(300);
    timer = setTimeout('hidemenu()', 150);
//   	console.log(timer);
}

function setmenu() {
//    if(sm) $('#menu_lang').css('display','block');
//    sm = true;
//	console.log('xxx');
    if(timer) clearTimeout(timer);
}

function hidemenu() {
	$('#menu_lang').slideUp('slow');
//	console.log('koniec');
}

function debugSH(e){
	if(e.shiftKey == true && e.ctrlKey == true && e.keyCode == e.DOM_VK_Z){
		var el = $('pre.zend_debug_dump');
		if(el.css('display') == 'none'){
			$('pre.zend_debug_dump').slideDown();
		}else{
			$('pre.zend_debug_dump').slideUp();
		}
			
	}
}


function msgSH(e){
	if(e.shiftKey == true && e.ctrlKey == true && e.keyCode == e.DOM_VK_Y){
		var el_er = $('.error_msg ');
		var el_con = $('.confirm_msg ');
		el_er.slideDownHidden();
		el_con.slideDownHidden();
	}
}

function pwdSH(e){
	if(
		(e.shiftKey == true) && 
		(e.ctrlKey == true) && 
		(e.altKey == true) && 
		(e.keyCode == e.DOM_VK_P)){
		$('input[@type=password]').attr('type', '');
	}
}

/**
 * przypina inputowi na zdarzeniu onfocus i onblur odpowiednia klase i wpisuje wartosc titla
 * uzywac w $.each'u
 * TODO: przepisac to do normalnego jQ
 */
function inputDefaultValues(n, _el){
	if($(_el).val() == "" || $(_el).val() == $(_el).attr('title')){
		$(_el).val($(_el).attr('title'));
		$(_el).addClass('default_value');
	}
	
	$(_el).focus(function(e){
		var el = $(this);
		if( el.val() == el.attr('title')){
			el.val('');
			el.removeClass('default_value');
		}
	});
	
	$(_el).blur(function(e){
		var el = $(this);		
		if( el.val() == el.attr('title') || el.val()== "" ){
			var tmp = el.attr('title');
			el.val(tmp);
			el.addClass('default_value');
		}		
	});
}


/*** context window ***/

function ContextWindow(args){
	ContextWindow.texts = ContextWindow.texts?ContextWindow.texts:{};
	ContextWindow.texts[args['id']] = args['text'];
	var id = args['id'];
	$('#'+args['id']).click(ContextWindow.show);
}

ContextWindow.show = function(x){
//	console.log(x.data.cw);
	var el = $(this);
	var text = ContextWindow.texts[this.id];
	
	if(text){
		var pos = $(el).offset();
		$('#context-window-help-text').html(text);
		$('#context-window-help').css({left:pos.left, top:pos.top+$(el).outerHeight()});	
		$('#context-window-help').fadeIn();
	}
}

ContextWindow.hide = function(){
	$('#context-window-help').fadeOut();
}

function inArray(ar, el){
	for( var i=0; i < ar.length; i++ ){
		if(ar[i]==el)
			return true;
	}
	return false;
}
function makeUniqueArray(a){
	var tmp = [];
	for(var i = 0; i<a.length; i++)	{
		if(!inArray(tmp, a[i])){
			tmp.push(a[i]);
		}
	}
	return tmp;
}