function showShadow()
{
	//var shadowHeight=$("#wrap").height();
	//$("#shadow").height(shadowHeight).show();
	$('#shadow').show();
	return false;
}

function change_hide(state)
{
    /*
	var objects = document.getElementsByTagName('object');
	for(var i=0; i<objects.length; i++)
    {
       objects[i].style.display=state;
        if(state == 'none')
           objects[i].style.visibility ='hidden';//objects[i].style.display=state;
        else
            objects[i].style.visibility ='visible';
       
    }
    */
    $('object').each(function () {if(this.id != play_tag) $(this).css('display',state);});
        
	var objects = document.getElementsByTagName('SELECT');
	for(var i=0; i<objects.length; i++) objects[i].style.display=state;
	var objects = document.getElementsByTagName('embed');
	
	for(var i=0; i<objects.length; i++) 
	{
		if(objects[i].style.zIndex == 1) continue;
		if(state == 'none')
            objects[i].style.visibility ='hidden';
		else
			objects[i].style.visibility ='visible';
        }
}

function hideThisPopup()
{
	if(lastPopup)
    {	
        jQuery.hotkeys.remove('esc'); 
         hidePopup (lastPopup);
    }
	lastPopup = 0;
	return false;
}

function hidePopup (current)
{
	change_hide('');
	$('#'+ current).hide();
	$("#shadow").hide();
	$doc('frm').innerHTML = '';
	lastPopup = 0;
	$('body').removeClass('popup-show');
	return false;
}

var lastPopup=0;
function showPopup(current,which)
{
	//window.scrollTo(0,0);
	jQuery.hotkeys.add('esc', function () {hideThisPopup();});
	lastPopup = current;
	change_hide('none');
	showShadow();
	$('#'+ current)
		.css('margin-top', -Math.floor($('#'+ current).height() / 2) +'px')
		.show();
	$('body').addClass('popup-show');
	return false;
}

function form(name, param, calledform)
{
	if(typeof 		param =='undefined') param = 0;

	x_form(name, 	param, calledform, show_statica);
	return false;
}

function key_down(obj)
{
	switch(event.keyCode)
	{
	case 13:
	{
		while(obj.parentNode)
		{
			obj = obj.parentNode;
			if(obj.tagName == 'FORM')
			{	
				if(obj.onsubmit) obj.onsubmit();
				else obj.submit();
				break;
			}
		}
		break;
	}
	case 27:
	{
		hideThisPopup();break;
	}
	}
}


function Txtkey_down(obj)
{
	switch(event.keyCode)
	{
		case 13:
		{
			if(event.ctrlKey == true)
			{
				while(obj.parentNode)
				{
					obj = obj.parentNode;
					if(obj.tagName == 'FORM')
					{
///						alert(obj.onsubmit);						break;
						if(obj.onsubmit) obj.onsubmit();
						//else {obj.submit();}
						break;
					}
				}
			}
			break;
		}
	}
}


function send_worker()
{
	id  	= $doc('wrk_id').value;
	name  	= $doc('wrk_name').value;
	em		= $doc('wrk_email').value;
	text	= $doc('wrk_text').value;

	if(empty(name)||empty(em)|| empty(text))
	{
		alert('вы заполнили не все поля, письмо не было отправлено');
		return false;
	}
	
	if(!check_email(em))
	{
		alert('Неправильно указан e-mail ' + em)
		return false;
	}
	
	
	x_wrk_send(id, name, em, text, show_statica)
	return false;
}

function shshsh(k,p1,p2,p3,p4)
{
	var sliderPopup = $("#new-photos-bubble");
	switch(k)
	{
		case 1:
			sliderPopup.hide()
			if (p3) {
				sliderPopup.find("h5").show().text(p3);
			} else {
				sliderPopup.find("h5").hide();
			}
			sliderPopup.find("p").text(p4);
			sliderPopup
				.css("top", (p1 * 112 - 112 - sliderPopup.height() + 10) +"px")
				.css("left", (p2 * 77 - 50) +"px")
			sliderPopup.show();
		break;
		case 0:
			sliderPopup.hide();
			break;
		case 2:
			sliderPopup.show();
			break;
	}
}


function message_sned()
{
	mem_id	= $doc('mem_id').value;
	text	= $doc('send_text').value;
	
	if(empty(text))
	{
		alert('Вы не написали сообщение');
		return false;
	}

	x_message_send(mem_id, text, show_statica);
	return hideThisPopup();
}

var cls_lst = {};
function check_all(cls_name)
{
	newState = !(cls_lst[cls_name] || false);
	cls_lst[cls_name] = newState;
	$('.'+cls_name).attr('checked', !newState );
	return false;
}


function mail_send()
{
	name  	= $doc('wrk_name').value;
	em		= $doc('wrk_email').value;
	text	= $doc('wrk_text').value;

	if(empty(name)||empty(em)|| empty(text))
	{
		active($doc('wrk_name'));
		alert('вы заполнили не все поля, письмо не было отправлено');
		return false;
	}
	
	if(!check_email(em))
	{
		alert('Неправильно указан e-mail ' + em)
		return false;
	}
	
	
	x_send_mail(name, em, text, show_statica)

	return false;
}