// JavaScript Document
Cufon.replace("#blue-footer #footer-blue-wrap .colomn-2 div");
Cufon.replace("#blue-footer #footer-blue-wrap .colomn-3 div");
if (!is_IE6() && !is_IE8())
{
	Cufon.replace("#body #footer-menu ul.red li a");
	Cufon.replace("#body #footer-menu ul.yellow li a");
	Cufon.replace(".colomns h1");
	//Cufon.replace(".colomns h2");
}

//if (typeof console == "undefined" || typeof console.log == "undefined") var console = { log: function() {} };


$(document).ready(function(){
	$("#blue-header li a").mouseover(munuMouseOver)		   
	$("#blue-header li a").mouseout(munuMouseOut)
	$("#blue-footer li a").mouseover(munuBottomMouseOver)
	$("#blue-footer li a").mouseout(munuBottomMouseOut)
	
	//
	//$("p img.w-b-border").removeClass('w-b-border').addClass('w-b-border-left');
	//$("p img.w-b-border").removeClass('w-b-border');
	//
	
	$("img.w-b-border-left, img.w-b-border").each(function(){
		if (this.complete)
			w_b_border_each.call(this);
		else
			$(this).load(w_b_border_each);
	});
	
	if ('\v'=='v') w_b_border() 
	//if (navigator.userAgent.indexOf('Opera') != -1 ) w_b_border() /*opera*/
	
	// unwrap non-left borders from paragraphs
	
	// mail.ru counter
	var a = ';r=' + escape(document.referrer);
	a += ';j=' + navigator.javaEnabled();
	a += ';s=' + screen.width + '*' + screen.height;
	a += ';d=' + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth);
	var js = 13;
	$('#footer-blue-wrap table:eq(0) tr:eq(0) td:eq(1)').html('<a href="http://top.mail.ru/jump?from=464338" target="_top">' + '<img src="http://d5.c1.b7.a0.top.mail.ru/counter?id=464338;t=56;js=' + js + a + ';rand=' + Math.random() + '" alt="Рейтинг@Mail.ru" border="0" ' + 'height="31" width="88"><\/a>');
	
	if($('#content-inner-left-menu').length)
	{
		$(".imgWrapper").each( function(){  
											var ne = $(this).next();
											if(ne.length)
											{
												if(ne[0].tagName == 'BR')
													ne.remove();
											}
										}); 
	}

	
})

function munuMouseOver()
{
	var img = $("img",this);
	img.data("src",img.attr("src"));
	img.attr("src",$(this).attr("rel"));
	$("#blue-header .comment").html($(this).attr("title"));
	Cufon.replace(".menu .comment");
}
function munuMouseOut()
{
	var img = $("img",this);
	img.attr("src",img.data("src"));
	$("#blue-header .comment").html("");
}
function munuBottomMouseOver()
{
	var img = $("img",this);
	img.data("src",img.attr("src"));
	img.attr("src",$(this).attr("rel"));
	$("#blue-footer .comment").html($(this).attr("title"));
	Cufon.replace(".menu .comment");
}
function munuBottomMouseOut()
{
	var img = $("img",this);
	img.attr("src",img.data("src"));
	$("#blue-footer .comment").html("");
}

function w_b_border()
{	
	$(".w-b-border").each(w_b_border_each);
	$(".w-b-border-left").each(w_b_border_each);
}


function w_b_border_each()
{
	$this = $(this);
	if ($this.data("ready") != 1)
	{
		//$this.css("margin-right","0px");
		$this.css("margin-right","0px").css("border","none");
		
		var idd = $this.attr('idd');
		var lang = $this.attr('lang');
		var $wrap = $this;
		if (idd && lang)
		{
			
			//process galka
			if(!$(this).attr('longdesc'))
			{
				if ($('#body .index-page').length == 0) {
					if ($this.parent('a').length == 0)
						$wrap = $this.wrap('<a/>').parent('a');
					else
						$wrap = $this.parent('a');
					
					$wrap.removeAttr('target').attr('href', 'javascript:;').click(function(){ ImageInfo(idd, lang); });
				}
				else
					$wrap = $this;
			}
			
			$this.css('float', 'none');
		}
		
	/*
		if ( $this.attr("class") == "w-b-border")
		{
			$wrap.wrap( $("<div/>").attr("class","align_center") );
			$wrap.wrap( $("<div/>").attr("class","align_center_to_left") );
			$wrap.wrap( $("<div/>").attr("class","align_center_to_right") );
		}
		$wrap.wrap($("<div/>").attr("class",$this.attr("class")+"-3").css("height",$this.attr("height")+4+"px").css("width",$this.width()+4+"px"));
		$wrap.wrap($("<div/>").attr("class",$this.attr("class")+"-2").css("height",$this.attr("height")+2+"px").css("width",$this.width()+2+"px"));
	*/
	
		//var brdr = $('<table cellspacing="0" cellpadding="0" align="' + ($this.hasClass('w-b-border-left') ? 'left' : 'center') + '" border="0"><tr><td colspan="3"><img height="3" alt="" width="1" border="0" src="/img/0.gif" /></td></tr><tr><td><img height="1" alt="" width="3" border="0" src="/img/0.gif" /></td><td><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><img height="12" alt="" width="11" border="0" src="/img/picborder/left_top.gif" /></td><td background="/img/picborder/bg_top.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td><img height="12" alt="" width="11" border="0" src="/img/picborder/right_top.gif" /></td></tr><tr><td background="/img/picborder/bg_left.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td class="img_td"></td><td background="/img/picborder/bg_right.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td></tr><tr><td><img height="12" alt="" width="11" border="0" src="/img/picborder/left_bot.gif" /></td><td background="/img/picborder/bg_bot.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td><img height="12" alt="" width="11" border="0" src="/img/picborder/right_bot.gif" /></td></tr></tbody></table></td><td><img height="1" alt="" width="3" border="0" src="/img/0.gif" /></td></tr><tr><td colspan="3"><img height="3" alt="" width="1" border="0" src="/img/0.gif" /></td></tr></table>').insertAfter($wrap);
		var align = '';
		if ($wrap.next('img').length > 0)
			var align = 'align="left"';
		else if ($this.hasClass('w-b-border-left') || $this.attr('align') == 'left')
			align = 'align="left"';
		else if ($this.hasClass('w-b-border') || $this.attr('align') == 'center')
		{
			var prev_tag = $this.prev();
			if (prev_tag.length == 1)
				prev_tag = prev_tag.get(0);
			if (typeof prev_tag.tagName != undefined)
				prev_tag = prev_tag.tagName;
			if (prev_tag != 'TABLE' && prev_tag != 'IMG')
				align = 'align="center"';
		}
		
		if($(this).attr('align')=='right')
		{
			align = '';
			$this.attr('align','')
		}
		
		var brdr = $('<table cellspacing="0" cellpadding="0" ' + align + ' border="0" class="imgWrapper"><tr><td colspan="3"><img height="3" alt="" width="1" border="0" src="/img/0.gif" /></td></tr><tr><td><img height="1" alt="" width="3" border="0" src="/img/0.gif" /></td><td><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><img height="12" alt="" width="11" border="0" src="/img/picborder/left_top.gif" /></td><td background="/img/picborder/bg_top.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td><img height="12" alt="" width="11" border="0" src="/img/picborder/right_top.gif" /></td></tr><tr><td background="/img/picborder/bg_left.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td class="img_td"></td><td background="/img/picborder/bg_right.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td></tr><tr><td><img height="12" alt="" width="11" border="0" src="/img/picborder/left_bot.gif" /></td><td background="/img/picborder/bg_bot.gif"><img height="1" alt="" width="1" border="0" src="/img/0.gif" /></td><td><img height="12" alt="" width="11" border="0" src="/img/picborder/right_bot.gif" /></td></tr></tbody></table></td><td><img height="1" alt="" width="3" border="0" src="/img/0.gif" /></td></tr><tr><td colspan="3"><img height="3" alt="" width="1" border="0" src="/img/0.gif" /></td></tr></table>').insertAfter($wrap);
		
		$('.img_td', brdr).append($wrap);
		
	}
	$this.data("ready",1);
}

function is_IE6(){
if($.browser.msie && $.browser.version<=6) return true;
return false;
}

function is_IE8(){
if($.browser.msie && $.browser.version==8) return true;
return false;
}

//function ImageInfo(idd, lang, ImWidth, ImHeight)
function ImageInfo(idd, lang, ImWidth, ImHeight)
{
	if (typeof(ImWidth) != 'number')
		ImWidth = 400;
	if (typeof(ImHeight) != 'number')
		ImHeight = 600;
	
	ImWidth = parseInt(ImWidth)+34;
	ImHeight = parseInt(ImHeight)+200;
	
	if ( ImWidth < 450 ) {ImWidth = 450;}
	if ( ImHeight > 500 ) {ImHeight=500;}
	
	window.open("/" + lang + "/picture/?id=" + idd + "&lang=" + lang,"ShowImage","scrollbars=yes,width="+(ImWidth + 16)+",height="+ImHeight+",resizable=no,location=no,menubar=no,status=no,toolbar=no");
	//alert ("Будет выводиться большая картинка");
}

/*
$(document).ready(function() {
	$('.content-right table').each(function() {
		var parentTag = $(this).parent().get(0).tagName;
		if ($(this).attr('align')!='left' && parentTag!="TD" && $(this).width() < 200) {
			$(this).attr("style", "margin-right: -60px; float:left");
			$(this).after("<div style='clear:both'></div>");
		}
	}); 
});
*/
