function disappear() {
 $('.disappear').animate({

        opacity: 0

      }, 2500 );
}


function checkmenu() {
var arr = ['20%','20%','20%','20%','19%'];
$('div.itemmenu').each(function(i) {
$(this).css('width',arr[i]);
});
}


function openphoto(url) {
$('#mainmessage').css({'display':'inline', 'z-index': '30'});

	  	  $('#mainmessage').html('<div id="mainmessage1" ><a href="javascript:;" onclick="closephoto()" class="link1" style="float: right">закрыть</a><br /><img src="'+url+'" onload="getmiddle('+"'"+'#mainmessage1'+"'"+');"  /></div>');

	  getmiddle('#mainmessage1');


}



function setCookie(name, value, days) {
	  if (days) {
	  var date = new Date();
	  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
	  var expires = "; expires=" + date.toGMTString()
  } else var expires = "";
	  document.cookie = name + "=" + value + expires + "; path=/"
	}

function delete_cookie (cookie_name)
{
	var cookie_date = new Date ();
	cookie_date.setTime (cookie_date.getTime() - 1);
	document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}




function getmiddle(object) {
$(object).css({'width' : 'auto', 'height': 'auto','overflow' : 'hidden'});

	var width= $(object).width()/2;

	var height= $(object).height()/2;

	var widthScreen = $(window).width()/2;
        var heightScreen = $(window).height()/2;



	$(object).css({'left' : widthScreen-width})
	   $(object).css({'top' : heightScreen-height})

if (height > heightScreen) {
$(object).css({'top' : 2, 'height':  $(window).height() , 'overflow' : 'scroll'})

}

var widthmain= $(object).width()+60;
$('#mainmessage').css({'width': widthmain });

}


window.onresize= resize;
function resize() {
getmiddle('#mainmessage1');

getmiddle('#letterform');
}


function closephoto() {

$('#mainmessage').html('');

}



function browser()
{
    var ua = navigator.userAgent;

    if (ua.search(/MSIE/) > 0) return 'Internet Explorer';
    if (ua.search(/Firefox/) > 0) return 'Firefox';
    if (ua.search(/Opera/) > 0) return 'Opera';
    if (ua.search(/Chrome/) > 0) return 'Google Chrome';
    if (ua.search(/Safari/) > 0) return 'Safari';

}



function ajaxload(url,arr,id) {

var maincolor = getCookie('maincolor');


$.ajax({
type: "POST",
cache: false,
url: url,
data: arr,
beforeSend: function() {
if(id=='#mainmessage') {
$(id).html('<div id="mainmessage1" style="border:0" ><img src="/images/tm/wait.gif" /></div>');
getmiddle('#mainmessage1');
}
else {
$(id).html('<img src="/images/tm/wait.gif" />');
}
},
success: function(msg){
if(id=='#mainmessage') {
$(id).html('<div id="mainmessage1" ><a href="javascript:;" onclick="closephoto()"  style="float: right;" class="link1">закрыть</a><br />'+msg+'</div>');
getmiddle('#mainmessage1');
}
else{
$(id).html(msg);}
}
});


}


function ajaxform(url,idform,id) {

var maincolor = getCookie('maincolor');

var options = {
  type: "POST",
  url: url,
 beforeSend: function() {
if(id=='#mainmessage') {
$(id).html('<div id="mainmessage1"  style="border:0" ><img src="/images/tm/wait.gif" /></div>');
getmiddle('#mainmessage1');
}
else {
$(id).html('<img src="/images/tm/wait.gif" />');
}
},
success: function(msg){
if(id=='#mainmessage') {
$(id).html('<div id="mainmessage1"  ><a href="javascript:;" onclick="closephoto()"   style="float: right;" class="link1">закрыть</a><br />'+msg+'</div>');
getmiddle('#mainmessage1');
}
else{
$(id).html(msg);}
}

	};
	$("#"+idform).ajaxSubmit(options);

}






function uploadfile(id,url,idresult) {
new AjaxUpload(id, {
 action: url,
  name: 'myfile',
  autoSubmit: true,
  responseType: false,
   onSubmit: function(file, extension) {
$(idresult).html('<img src="/images/tm/wait.gif" />');

},
  onComplete: function(file, response) {
$(idresult).html(response);
}
});


}




function checkimg(img,val)
{
var width = $(img).width();
var height = $(img).height();
if (width > height) {$(img).css({'width': val });
}
else {$(img).css({'height': val, 'width' : 'auto' });
}



}


function displayterms(id) {

$('#displayterms').css("display","none");


var terms = $('#'+id).html();



$('#blockterms').html(terms+'<br /><br />');

}

var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();


