$(document).ready( function (){  $('.hd').hide(); $('.hd2').hide(); } );
function doLoad (u, b, f, a, q) {
arr = new Array(0,1,2,3);
arr[0] = new Array(0,1,2);
arr[1] = new Array(0,1,2);
arr[2] = new Array(0,1,2);
arr[3] = new Array(0,1,2);
arr[0][0] = 'html';
arr[0][1] = true;
arr[0][2] = 'get';
arr[1][0] = 'json';
arr[1][1] = true;
arr[1][2] = 'get';
arr[2][0] = 'html';
arr[2][1] = false;
arr[2][2] = 'post';
arr[3][0] = 'json';
arr[3][1] = false;
arr[3][2] = 'post';
var img0;
if(f != ''){
	var ff = document.getElementById(f);
	if(f.indexOf('=') == -1) var sd = $("form").serialize();
	else var sd = f;
}

$.ajax({
    url: u,
    dataType : arr[a][0],
	data : sd,
	cache : arr[a][1],
	type : arr[a][2],
	beforeSend: p,// до отправки
    success:  s//после отправки
});

function p()
{// до отправки
	if(q == 0){}
	if(q == 1){
		if ( $('#a_1').length == 0 ){
			$('body').append('<div class="a_2" id="a_2"></div><div class="a_l" id="a_3"></div><div class="a_3" id="a_1"></div><div class="a_1" id="a_4"></div><div id="a_5"></div>');
		}
		if($('#a_1').width() < 30){
			$('#a_2').fadeTo(0, 0).css({left:"0px",top:"0px",height:$(document).height()+'px',width:"100%"}).fadeTo(222, 0.77);
		}
	}
	if(q == 2){
		$('#top_menu_box').remove();
	}
}

function s(data){
	
	if(q == 0){
		$("#"+b).html(data);
	}
	if(q == 2){ 
		var offset = $('#top_menu').offset();
		$('body').append('<div style="background-color:#EFEFEF;padding:18px;" id="top_menu_box"></div>');
		$('#top_menu_box').css({ position : "absolute", left : offset.left + "px", top : (offset.top + 32) + "px"} ).width($('#top_menu').width() - 36);
		$('#top_menu_box').html(data); 
	}
	if(q == 1){
$('#a_3').html(data);
var tp = ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) + ((getWindowHeight() - $('#a_3 div:first-child').height()) / 2))
var lft = ((window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0)+((getWindowWidth() - $('#a_3 div:first-child').width()) / 2))
		if($('#a_1').width() < 30){
			$('#a_1').fadeTo(0, 0).html(''+data+'').css({ left: lft+"px", top: tp+"px", height: ($('#a_3 div:first-child').height() + 4), width: ($('#a_3 div:first-child').width() + 4)}).fadeTo(222, 1,function(){$('#a_2').attr({ onClick: "javascript:hide_foto()" })});
			$('#a_3 div:first-child').remove();
		}else{
			var p = 0;
			$('#bbb').animate({ height: ($('#a_3 div:first-child').height() - 0), width: ($('#a_3 div:first-child').width() - 0), top: tp, left: lft },222);
			if(p==0){ p=1;$('#bbb').animate({ height: ($('#a_3 div:first-child').height() + 4),width: ($('#a_3 div:first-child').width() + 4), top: tp, left: lft },333,function(){$('#a_1').html(data);$('#bbb').fadeTo(2222, 1,function(){$('#a_2').attr({ onClick: "javascript:hide_foto()" })})})}}
		}
	}
}
function remove_menu_box(){ $('#top_menu_box').remove() }
function hide_foto(){
$('#a_1').html('').fadeTo(222, 0, function(){$('#a_1').remove()});
$('#a_2').html('').fadeTo(222, 0, function(){$('#a_2').remove()}).removeAttr('onClick');
}
function hide_box(){
$('#body_hide').fadeTo(222, 0,function(){$('#body_hide').remove();$('#aj_box').remove()});
$('#aj_box').fadeTo(222, 0)
}
function send(f)
{
var str = f.options[f.selectedIndex].value;
eval(str);
} 
function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&document.documentElement.clientHeight) {
      windowHeight=document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}
function getWindowWidth() {
  var windowWidth=0;
  if (typeof(window.innerWidth)=='number') {
    windowWidth=window.innerWidth;
  }
  else {
    if (document.documentElement&&document.documentElement.clientWidth) {
      windowWidth=document.documentElement.clientWidth;
    }
    else {
      if (document.body&&document.body.clientWidth) {
        windowWidth=document.body.clientWidth;
      }
    }
  }
  return windowWidth;
}
function addTag(num){
	var v = $('#tags').val();
	v = v.replace(','+num+',', "");
	v = v+','+num+',';
	v = v.replace(",,", ",");
	$('#tags').val(v);
	}
