function fixPNG_one(b){if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){var c;if(b.tagName=="IMG"){if(/\.png$/.test(b.src)){c=b.src;var a=b.clientWidth;var d=b.clientHeight;b.src=pix_src;b.width=a;b.height=d}}else{c=b.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);if(c){c=c[1];b.runtimeStyle.backgroundImage="none"}}if(c){b.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+c+"',sizingMethod='crop')"}}}function fixPNG_serch(b){if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){var c;if(b.tagName=="IMG"){if(/\.png$/.test(b.src)){c=b.src;var a=b.clientWidth;var d=b.clientHeight;b.src=pix_src;b.width=a;b.height=d}}else{c=b.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);if(c){c=c[1];b.runtimeStyle.backgroundImage="none"}}if(c){b.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+c+"',sizingMethod='scale')"}}}function fixPNG_ticket(a){if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){var b;if(a.tagName=="IMG"){if(/\.png$/.test(a.src)){b=a.src;a.src=pix_src}}else{b=a.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);if(b){b=b[1];a.runtimeStyle.backgroundImage="none"}}if(b){a.runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+b+"',sizingMethod='scale')"}}};

$.Translit = function(str,lg){
	
	LANG  = new Array();
	TRANS = new Array();
	
	LANG ['RU'] = "АБВГДЕЁ Ж ЗИЙКЛМНОПРСТУФХЦ Ч Ш Щ  ЬЫЪЭЮ Я абвгдеё ж зийклмнопрстуфхц ч ш щ  ьыъэю я ";
	TRANS['RU'] = "ABVGDEYOZHZIYKLMNOPRSTUFHTSCHSHSHH'Y'EYUYAabvgdeyozhziyklmnoprstufhtschshshh'y'eyuya";
	
	res = '';
	var j;
	
	for (var i=0; i<str.length; i++){
		if (str[i]==' ')	j = -1; else
							j = LANG[lg].indexOf(str[i]);
		
		if (j == -1) {
			res += str[i];
			continue;
		}
		
		do {
			res += TRANS[lg][j];
		} while (LANG[lg][++j]==' ');
	}
	
	return res;
}

jQuery.fn.toggleOutClick = function (obj){
	$(document).click(function(evt){
		obj.hide()
	})
	obj.click(function(evt){
		return false;
	})
}

var donkey6 = false

if($.browser.msie) {
	var donkey = true
	if($.browser.version < 7) {
		var donkey6 = true
	}
} else {
	var donkey = false
} 
// min-width ie6
if (donkey6){
	function min_width() {
		if($(document).width() < 940) {
			$("#wrap").width(940)
		} else {
			$("#wrap").width("auto")
		}
	}
	$(document).ready(function(){
		 min_width()
	})
	$(window).resize(function(){
		 min_width()
	})
}



// default table in #content
$(document).ready(function(){
	$("#content table").attr({"cellspacing":"0","cellpadding":"0"}).each(function(){
		if (!$(this).hasClass("normal-table")) {
			var i=0
			$(this).find("tr").each(function(){
				if (i ^= 1)	$(this).attr("class","bg")
			})
		}
	})
})

// top menu
is_menu_created = false
function create_top_menu () {
	if (is_menu_created) return false
	is_menu_created = true
	var links_w = 0
	$("#top-menu a").each(function(){
		links_w += $(this).width() - (0 - 20)
	}).after("<div class=\"right\"></div>").wrap("<div class=\"a\"></div>")
	var links_m = (900 - links_w) / ($("#top-menu a").length -1 )
	$("#top-menu li").css("margin-right", links_m).mouseover(function(){
		if (!$(this).hasClass("active")){
			$(this).toggleClass("active").find("a").attr("name","active")
			$(this).find(".a").attr("class","a-active")
			$(this).find(".right").attr("class","right-active")
		}
	}).mouseout(function(){
		if ($(this).find("a").attr("name") == "active"){
			$(this).toggleClass("active")
			$(this).find(".a-active").attr("class","a")
			$(this).find(".right-active").attr("class","right")
		}
	}).click(function(){
		location.href = $(this).find('a').attr('href');
	})
}
$(document).ready(function(){
	if (!is_menu_created) {
		create_top_menu ();
	}
})

// img to circle
var round_sized = new Array()
var round_html= new Array()
function generate_round_size(width){
	var Wd2 = width / 2;
	var W_2 = Wd2*Wd2;
	round_sized[width] = new Array()
	for (var i=0;i<width;i++) {
		tmp = i-Wd2;
		round_sized[width][i] = Math.round(Math.sqrt(W_2 - tmp*tmp)*2)
	}
}
$(document).ready(function(){
	$(".create-circle").each(function(){
		var src = $(this).attr("src")
		var size = $(this).width()
		if (!round_sized[size]) {
			generate_round_size(size)
			var avatar = '<div style="width:'+size+'px; height:'+size+'px;" class=\"circle\" >'
			var size_d2 = size >> 1
			for (var i=0;i<size_d2;i++) {
				if ((!round_sized[size][i]) || (i && round_sized[size][i] == round_sized[size][i-1])) continue;
				var v = size - round_sized[size][i]>>1 //min
				avatar += "<div style=\"background-image:url(###);background-position:-"+v+"px center; margin-left:"+v+"px; width:"+round_sized[size][i]+"px;height:"+(size-(i<<1))+"px;position:absolute;top:"+i+"px;left:0px\"></div>"
			}
			avatar += '</div>'
			round_html[size] = avatar;
		}
		$(this).after(round_html[size].replace(/###/g,src)).remove()
	})
})

// form-help

$(document).ready(function(){
	$("#main").after("<div id=\"help-popup\"></div>")
	$(".form-help").mouseover(function(){
		pop_pos($(this))
	}).mouseout(function(){
		$("#help-popup").toggle()
	})
})

// popup
$(document).ready(function(){
	var content = $("#popup .text")
	var _ROUND_SIZE = 8;
	
	function pop_resize(){
		var RSd2 = _ROUND_SIZE<<1;
		$("#popup .content").css("width","")
		$("#popup").attr('hide','0')
		$("#popup .p3, #popup .p8").css("width","")
		$("#popup .p4, #popup .p5").css("height","")
		var c_h = content.height() - 22 + RSd2
		var c_w = content.width() - 22
		$("#popup .content").width((c_w - (0 -30))).height((c_h - (0 -30)))
		$("#popup .p3, #popup .p8").width(c_w)
		$("#popup .p4, #popup .p5").height(c_h)
		var first = false;
		var last;
		$("#popup .text :first-child div").each(function(){
			if (!first) first = this;
			last = this;
		})
		if($(first).css('background-color')=='transparent' || $(first).css('background-color')=='rgba(0, 0, 0, 0)') first = $("#popup .text").children(":first");
		if($(last).css('background-color')=='transparent' || $(last).css('background-color')=='rgba(0, 0, 0, 0)') last = $("#popup .text").children(":first");
		if (!round_sized[RSd2]) 
			generate_round_size(RSd2);
		var s = '';
		for (var i=0;i<_ROUND_SIZE;i++) s += '<div></div>';
		$("#popup .text").append('<div class="round"></div>').prepend('<div class="round"></div><div class=\"cls\" onclick=\"$(document).click();\"></div>');
		width = 0;
		$("#popup .text").children(":first").each(function(){ 
			 $(this).html(s);
			 var i = 0
			 $(this).children().each(function(){
				  $(this).css('background-color',$(first).css('background-color'));
				 $(this).width(content.width()+round_sized[RSd2][width]-RSd2-donkey6*5);
				 $(this).css({"left":(_ROUND_SIZE - (round_sized[RSd2][width++]>>1))+'px',"top":i+'px'});
				 i++ 
			 }) 
		})
		$("#popup .text").children(":last").each(function(){ 
			 $(this).html(s);
			 var i = 0
			 $(this).children().each(function(){
				 $(this).css('background-color',$(last).css('background-color'));
				 $(this).width(content.width()+round_sized[RSd2][--width]-RSd2-donkey6*5);
				 $(this).css({"left":(_ROUND_SIZE - (round_sized[RSd2][width]>>1))+'px',"top":i+'px'});
				 i++
			 }) 
		})	
		$("#popup input, #popup a").click(function(){
			$("#popup").attr('hide','2')
		})
	}

	$(document).click(function(){
		val = $("#popup").attr('hide')
		if (val == '0'){	
			$("#popup").hide()
		} else {
			$("#popup").attr('hide', (val-1))
		}
	})

	$(".pop-button").each(function(){
	
		$(this).click (function(){
			content.html($(this).next().html())
			left =$(this).offset().left - 5 - (($(document).width() - 940)>>1)
			//pop_resize()
			$("#popup").css({"top":($(this).offset().top - 10),"left":left,"display":"block"})
			pop_resize()

			return false
		})
		
		$(this).parent().children('.right').click(function(){
			$(this).parent().children('.pop-button').click();
			return false;
		})
	
	})
	
	
	
	$("#popup").click(function(){
		return $("#popup").attr('hide')!='0';
	})

})

// world-web popup
$(document).ready(function(){
	var pop = $("#world-web-popup")
	var i = 0
	pop.find(".country").each(function(){
		if (i ^= 1) {
			$(this).addClass("background")
		}
	})
})

// cat submit

function submit_form(obj){
	$(obj).after("<input type='hidden' name='"+$(obj).attr('name')+"' value='"+$(obj).attr('value')+"'></input>").parents("form").submit()
}

function show_cap(){
	document.getElementById('popup_cap').style.display = "block";
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		document.getElementById('popup_cap').style.top = (document.body.scrollTop + screen.height/2 - 200) + 'px';
	}else{
		document.getElementById('popup_cap').style.top = (document.documentElement.scrollTop + screen.height/2 - 200) + 'px';
	}
}

function close_cap(){
	document.getElementById('popup_cap').style.display = "none";
}

$(document).ready(function(){

	$(document).click(function(){
		val = $("#popup_cap").attr('hide')
		if (val == '0'){	
			$("#popup_cap").hide()
		} else {
			$("#popup_cap").attr('hide', (val-1))
		}
	})
})

$(document).ready(function(){
	$('a').click(function(){
		var link = $(this).attr('href');
		if ($("#global-authorize").length && (link.search('myoffice.aquabionica.') == 7 || link.search('myoffice.aquabionica.') == 8)) {
			$("#global-authorize").attr("action", link).submit();
			return false;
		}
	})
})

