$(window).load(function(){
	if($.browser.msie && $.browser.version < 7)$('img[@src$=.png]').ifixpng();
});
//--------------------------------------------
function change(w)
{
 var w=document.getElementById('garmon'+w);

 if(w.style.display=="block") {w.style.display="none";} else {w.style.display="block";}
}
//--------------------------------------------
function initArray() {
  this.length = initArray.arguments.length;
  for (var i = 0; i < this.length; i++) { this[i+1] = initArray.arguments[i]; }
}
//--------------------------------------------
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
//--------------------------------------------
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
//--------------------------------------------
var pW=new Array(),pL=new Array(),pT=new Array(),pS=new Array();
function box_big(n) {
 var nA=document.getElementById(n),
 	 nB=document.getElementById(n+'B'),
 	 nBody=document.getElementById('body'),
 	nD=document.getElementById(n+'D');

 if (!pS[n]) pS[n]=0;

 if (pS[n]==0) {

  pW[n]=nA.style.width;
  pT[n]=nA.style.top;
  pL[n]=nA.style.left;
  dragObj.zIndex=nA.style.zIndex;

  nA.style.width = '100%';
  nA.style.height = '100%';
  nA.style.top = '0px';
  nA.style.left = '0px';
//  nA.style.position = 'fixed';
  nBody.style.overflow = 'hidden';
  nA.style.zIndex  = '100';

  pS[n]=1;

 } else {

  nA.style.width = pW[n];
  nA.style.height = 'auto';
  nA.style.top = pT[n];
  nA.style.left = pL[n];
//  nA.style.position = 'absolute';
  nA.style.zIndex  = dragObj.zIndex;
  nBody.style.overflow = 'auto';

  pS[n]=0;
 }
}
//-------box_roll-----------------------------
function box_roll(n){
  var nA=document.getElementById(n),nC=document.getElementById(n+'C');
  if(nC.style.display=="none"){nC.style.display="block";nA.style.zIndex=dragObj.zIndex;}else{nC.style.display="none";}
}
//-------box_del------------------------------
function box_del(n) {
 var nA=document.getElementById(n);
 if(nA.style.display=="none"){nA.style.display="block";nA.style.zIndex=dragObj.zIndex;}else{nA.style.display="none";}
}
//-------box_upd------------------------------
function box_upd() {
  URL='upd_boxes.php?lang='+lang;
  for (var i = 1; i <= b_n.length; i++) {
    var nA=document.getElementById(b_n[i]);

    URL +=''
          +'&l'+i+'='+parseInt(nA.style.left)
          +'&t'+i+'='+parseInt(nA.style.top)
          +'&w'+i+'='+parseInt(nA.style.width)
          +'&h'+i+'='+nA.clientHeight
          +'&v'+i+'='+nA.style.display
          +'';
  }
  if(confirm(URL))Load('box');
}
//-------box_body_load------------------------
var PAR='';
function box_body_load(f,p){
 if(content==f&&PAR==p){ 	return false;
 }else{
  document.getElementById('big_img').style.display='none';
  URL = 'box_body.php?file_name='+f+'&lang='+lang+'&cover='+cover+'&login='+login+'&nic='+nic+'&user_id='+user_id+p;
  PAR = p;
  content=f;
  a_hist();
  Load('body');
 }
}
//-------open_img-----------------------------
var hiddenImg = null;
var timerID = '';
function open_img(n) {
    hiddenImg = new Image();
    hiddenImg.src = n;
    wait_img();
}
//-------init_img-----------------------------
function init_img() {
 var nA=document.getElementById('big_img'),
 	nB=document.getElementById('big_imgB'),
 	nD=document.getElementById('big_imgD'),
 	nC=document.getElementById('big_imgC');

	myImage.src = hiddenImg.src;

	var p=posCenter(hiddenImg.width+20,hiddenImg.height+36);


  nA.style.top     = p.top+"px";
  nA.style.left    = p.left+"px";
  nA.style.width   = hiddenImg.width+20;
  nA.style.zIndex  = dragObj.zIndex;

  nB.style.width   = hiddenImg.width-16*2-3;
  nD.style.width   = hiddenImg.width;

  $('#big_img').hide().fadeIn(500);
}
//-------wait_img-----------------------------
function wait_img() {
	if (hiddenImg.complete) {clearTimeout(timerID);init_img();} else {timerID=setTimeout("wait_img()", 100);}
}
//-------send_message-------------------------
function send_message(file,form) {
	var p='&msg_txt='+form.msg_txt.value+'&nic='+form.nic.value+'&img='+form.img.value+'&user_id='+form.user_id.value+'&add_dsk=1';
	box_body_load(file,p);
}
//-------lang_change--------------------------
function lang_change(l) {
	if (l==lang) return;
	var d = content.indexOf('.');
	if (content.substring(d, content.length)=='.php') {document.location='../?content='+content+'&lang='+l+'&lang_upd='+l+'&cover='+cover+'&cover_upd='+cover+'&'+rates_url;return;}
	var d = content.indexOf('_');
	if(d>-1){
		if(l=='ru') {content = content.substring(0,d) + content.substring(d+3, content.length);} else {content = content.substring(0,d+1) + l + content.substring(d+3, content.length);}
	}else{
		if(l=='ru') {} else {d = content.indexOf('.'); content = content.substring(0,d) +'_'+ l + content.substring(d, content.length);}
	}
	document.location='../?content='+content+'&lang_upd='+l+'&cover_upd='+cover;
}
//-------a_hist-------------------------------
var hist=new Array();
var h_con=new Array();
i_hist=0;

function a_hist() {
	i_hist++;
//	confirm(URL+', '+content);
	hist[i_hist]=URL;
	h_con[i_hist]=content;
	if(i_hist>1){document.getElementById('back').style.display='block';document.getElementById('back2').style.display='block';}
}
//-------o_hist-------------------------------
function o_hist(o) {
	if(o==0){if(i_hist>0){i_hist--;document.getElementById('next').style.display='block';document.getElementById('next2').style.display='block';};if(i_hist==1){document.getElementById('back').style.display='none';document.getElementById('back2').style.display='none';}}
	if(o==1){if(i_hist<hist.length){i_hist++;document.getElementById('back').style.display='block';document.getElementById('back2').style.display='block';};if(i_hist==hist.length-1){document.getElementById('next').style.display='none';document.getElementById('next2').style.display='none';}}
	if(hist[i_hist]){URL=hist[i_hist];content=h_con[i_hist];Load('body');}
}
//-------coverCheck---------------------------
function coverCheck(form) {
	var check='';
	for (var i = 0; i < form.cover.length; i++) {
		if (form.cover[i].checked=='1'){check=form.cover[i].value;}
	}
	return check;
}
//-------send_reg-----------------------------
function send_reg(file,form) {
	var p='&fam='+form.fam.value+'&ima='+form.ima.value+'&otc='+form.otc.value+'&nic='+form.nic.value+'&pas='+form.pas.value+'&eml='+form.eml.value+'&phn='+form.phn.value+'&cover='+coverCheck(form)+'&add=1';
	box_body_load(file,p);
}
//-------send_log-----------------------------
function send_log(file,form) {
	var p='&nic='+form.nic.value+'&pas='+form.pas.value;
	box_body_load(file,p);
	box_del(b_n[2]);
}
//-------check_img----------------------------
function check_img(){    var form = document.getElementById('rf');
    var n = form.file_btn.value.replace(/^([^\\\/]*(\\|\/))*/,"");
	if(!/\.jpg|\.png|\.gif/i.test(n)){alert('Не правильный формат файла, выберите другой!\n[*.jpg, *.png, *.gif]\nИмя файла должно быть без пробелов на английском языке\nРазрешено использование символов[.][_][-][A-Za-z]\n\nПример:[Image_1.jpg]');return;}
}
//-----------zoom_posCenter----------
	function posCenter(w,h){		w=parseInt(w);
		h=parseInt(h);
		var l=($(window).width()-w)/2+$(window).scrollLeft();
		var t=($(window).height()-h)/2+$(window).scrollTop();
		l=(l<0)?0:l;
		t=(t<0)?0:t;
	  	return {left:l,top:t};
    }
