window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);
jQuery(function($) {
	$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
		
		$('ul.gallery_demo').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Следующая');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
});


function so_init()
{
	if(!$('.forum').height())
	{
		$('.content').height(($('.edit-menu').height() + 44)>$('.content').height() ? ($('.edit-menu').height() + 44) : $('.content').height());
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for(var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ " filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}

function ShowBann (path, w, h)
{
	window.open(path,'ShowBann','width='+w+',height='+h+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top='+ Math.round((screen.height/2)-(h/2)) +',left=' + Math.round((screen.width/2)-(w/2)));
}

function key_up (el, flag)
{
	if(flag == 1)
	{
		new_auth_login = el.value;
		old_auth_login=el.value;
	}
	else if(flag == 2)
	{
		new_auth_passwd = el.value;
		old_auth_passwd = el.value;
	}
	else if(flag == 3)
	{
		new_new_eml = el.value;
		old_new_eml = el.value;
	}
}
function loose_focus (el, flag)
{
	if(flag == 1)
	{
		el.value = old_auth_login;
	}
	else if(flag == 2)
	{
		el.value = old_auth_passwd;
	}
	else if(flag == 3)
	{
		el.value = old_new_eml;
	}
}
function get_click (el, flag)
{
	if(flag == 1)
	{
		el.value = new_auth_login;
	}
	else if(flag == 2)
	{
		el.value = new_auth_passwd;
	}
	else if(flag == 3)
	{
		el.value = new_new_eml;
	}
}

function check_registration_form(f)
{
	if(f.user_login.value == '')
	{
		alert('Введите логин!');
		f.user_login.focus();
		return false;
	}
	else if(f.user_passwd.value == '')
	{
		alert('Введите пароль!');
		f.user_passwd.focus();
		return false;
	}
	else if(f.user_passwd_confirm.value == '')
	{
		alert('Подтвердите пароль!');
		f.user_passwd_confirm.focus();
		return false;
	}
	else if(f.user_passwd.value != f.user_passwd_confirm.value)
	{
		alert('Пароль и его подтверждение должны быть идентичны!');
		f.user_passwd.focus();
		return false;
	}
	else if(f.user_surname.value == '')
	{
		alert('Введите Фамилию!');
		f.user_surname.focus();
		return false;
	}
	else if(f.user_name.value == '')
	{
		alert('Введите Имя!');
		f.user_name.focus();
		return false;
	}
	else if(f.user_email.value == '')
	{
		alert('Введите E-mail!');
		f.user_email.focus();
		return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(f.user_email.value)))
	{
		alert('Введенный E-mail имеет некоректный формат!');
		f.user_email.focus();
		return false;
	}
	else if(f.code.value == '')
	{
		alert('Введите цифровой код, указанный на картинке!');
		f.code.focus();
		return false;
	}
	else
	{
		return true;
	}
	return false;
}
function check_add_news_form(f)
{
	if(f.news_name.value == '')
	{
		alert('Введите Заголовок!');
		f.news_name.focus();
		return false;
	}
	else
	{
		return true;
	}
	return false;
}