// JavaScript Document
// чтение переменной из cookie
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function PrintTime()
{
	var t =  readCookie("set_generation_time");
	if (t)
	{
		document.write(parseInt(t*1000)/1000);
	}
	else
	{
		document.write('?');
	}
}

function PrintQueryCount()
{
	var cn = readCookie("set_query_count");
	if (cn)
	{
		document.write(cn);
	}
	else
	{
		document.write('?');
	}
}

function PrintGzip()
{
	var before = readCookie("page_size_before");
	var after = readCookie("page_size_after");
	var raz = (100 - Math.round(after/before*100));
	document.write(before + "&nbsp;/&nbsp;" + after + "&nbsp;-&nbsp;" + raz+ "%");
	//
}



// Для формы отправки комментарий
// JavaScript Document
/*Скрипт для работы с формой сообщения*/
b_help = "Жирный текст: [b]текст[/b]";
i_help = "Наклонный текст: [i]текст[/i]";
u_help = "Подчёркнутый текст: [u]текст[/u]";
q_help = "Цитата: [quote]текст[/quote]";
ul_help = "Ненумерованный список: [list]текст[/list]";
o_help = "Нумерованный список: [list=]текст[/list]";
p_help = "Вставить картинку: [img]http://image_url[/img]";
sup_help = "Текст в нижнем регистре: [sup]Текст[/sup]";
sub_help = "Текст в верхнем регистре: [sub]Текст[/sub]";
//w_promt = "Вставить ссылку: [url]http://url[/url] или [url=http://url]server[/url]";
eml_help = 'Вставить email: [email=ваш e-mail]текст[/email]';
cl_help = "";
enter_help = "Введите текст";
email_help = 'Введите ваш e-mail';
name_help = 'Введите ваше имя';
number_help = 'Введите количество строк в списке';
str_list_help = 'Введите строку списка';
quote_help = 'Введите имя цитируемого';
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[email]','[/email]');

function Help(help)
{
	// вывод подсказки для текущей кнопки
	document.message.help_line.value = eval(help + '_help');
}
// *******************************************************
// replacements for unsupported array functions (because arrayname.push(var)
// and arrayname.pop() are not implemented in IE until version 5.5)

function getarraysize(thearray) {
// replacement for arrayname.length property
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
// replacement for arrayname.push(value)
	thearraysize = getarraysize(thearray);
	thearray[thearraysize] = value;
}

function arraypop(thearray) {
// replacement for arrayname.pop()
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}
// ввод в textarea bbcode [b], [i], [u]
function code(theform, bbcode, prompttext)
{
	//var txtarea = document.message.message_text;
	inserttext = prompt(enter_help + "\n[" + bbcode + "]ваш текст[/" + bbcode + "]", prompttext);
	if ((inserttext != "") && (inserttext != null)) theform.message_text.value += "[" + bbcode + "]" + inserttext + "[/" + bbcode + "]"; 

    
}
// ввод 
function paramcode(theform, bbcode, prompttext)
{
    if (bbcode == 'email') ref = prompt(email_help, prompttext);
	else ref = prompt(quote_help, prompttext)
	if ((ref != '') && (ref != null))
	{
		if (bbcode == 'email') inserttext = prompt(name_help, ''); 
		else inserttext = prompt(enter_help, '');
		if ((inserttext != '') && (inserttext != null))
		{
			theform.message_text.value += '[' + bbcode + '=' + ref + ']' +  inserttext + '[/' + bbcode + ']'; 
		}
	}
	theform.message_text.focus();
	
}
function listcode(theform, bbcode, prompttext)
{
	// количество элементов в списке
	var num_list = eval(prompt(number_help, prompttext));
	if ((num_list != '') && (num_list != null))
	{
		var res_list = '';
		for (var i=1;i<=num_list;i++)
		{
			str_list = prompt(str_list_help + ' №' + (i), '');
			if ((str_list != '') && (str_list != null))
			{
				res_list += '[*]' + str_list + '\n';
			}
			
		}
		if ((res_list != '') && (res_list != null))
		{
			//res_list += '[' + bbcode + ']' + res_list + '[/' +  bbcode + ']';
			theform.message_text.value += '[' + bbcode + ']\n' + res_list + '[/' +  'list' + ']';
			theform.message_text.focus();
		}
	}
}
function test()
{
	alert('sdfdf');
}
function PreSubmit(theform)
{
	if (theform.message_text.value == '')
	alert('Поле сообщения не должно быть пустым');
	else
	theform.submit();
	
}


$(document).ready(function() {
	
	$("ul.gallery li").hover(function() { //On hover...
		
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		
		//Set a background image(thumbOver) on the &lt;a&gt; tag 
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Fade the image to 0
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		}); 
	} , function() { //on hover out...
		//Fade the image to 1 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

});


	
	