$(document).ready(function()
{
	// выравниваем нижни столбцы
	alignbottomColumns();

	// плавный ховер у кругляшек
	$('.vplay_big, .vplay').hover(
	    function(){
	        $(this).find('.vplayfull').stop().animate({opacity : 1}, 300);
	    },
	    function(){
	        $(this).find('.vplayfull').stop().animate({opacity : 0}, 300);
	    }
	);

	var bheight = 0;

	$(".bottom_blocks .inner_preview").each(function(i){
		if ($(this).height()>bheight)
			bheight = $(this).height();
	})

	$(".bottom_blocks .inner_preview").height(bheight);

	$('input[placeholder], textarea[placeholder]').placeholder();

	setTimeout("changeStr()",8000);
});

function alignbottomColumns()
{
	var max = 0;
	$('.bottom_menu .c_fifth').each(function(i){
		if (max<$(this).height())
			max = $(this).height();
	}).css('height',max);
}

function hideComment(id_comment)
{
	$.ajax({
		'url':'/ajax/hidecomment',
		'data':'id_comment='+id_comment,
		'type':'POST',
		'cache':false,
		'success':function(html){
			$("#c"+id_comment).addClass('hideComment').find('.adminhref:first').html('Восстановить').attr('href','javascript:restoreComment('+id_comment+')');;
		},
		'error':function(){
		}
	});
}

// Для удаления аватара пользователя
function deleteAvatar()
{
	$("#user_avatar").remove();
	$("#DbUser_delete_avatar").attr('value',1);
	$("#delete_avatar").remove();
	return false;
}

function restoreComment(id_comment)
{
	$.ajax({
		'url':'/ajax/restorecomment',
		'data':'id_comment='+id_comment,
		'type':'POST',
		'cache':false,
		'success':function(html){
			$("#c"+id_comment).removeClass('hideComment').find('.adminhref:first').html('Скрыть').attr('href','javascript:hideComment('+id_comment+')');
		},
		'error':function(){
		}
	});
}

function prepareNested(replyto,datecomment)
{
	$('#reply>span').html('ответ на комментарий от <i>'+datecomment+'</i>');
	$('#reply').show();
	var rpos = $('#reply').offset().top;
	$('body').scrollTop(rpos);
	replypost = replyto;
}

function undoReply()
{
	$('#reply').hide();
	replypost = 0;
}

function showDay(day)
{
	$("#tvprog th.active").removeClass('active');
	$("#day"+day).addClass('active');
	$("#tvprog tbody tr").hide();
	$("#tvprog tbody .day"+day).show();
}

function mvreload(n_video)
{
	jwplayer('main_video').load({'image': '/video/390/'+mainvideo[n_video][0],'file': '/video/'+mainvideo[n_video][1],'hd.file': '/video/'+mainvideo[n_video][2]});
}

function nextPopular(offset)
{
	$.ajax({'url':'ajax/popular','data':'offset='+offset,'type':'POST','cache':false,'success':function(html){jQuery(".pop_video").html(html)}});
}

var prjwidth = 600;
function nextProject()
{
	var current = $("#prj_select .active").index();
	var vis = 0;
	current++;

	if (current<projects_count)
	{
		$("#prj_select li:eq("+current+") a").click();
		vis = 80*current;
		if (vis>prjwidth) $("#prj_select").animate({left: (prjwidth-vis)});
	}
	else
	{
		$("#prj_select li:eq(0) a").click();
		$("#prj_select").animate({left: 0});
	}
	return false;
}

function prevProject()
{
	var current = $("#prj_select .active").index();
	var vis = 0;

	current--;

	vis = 80*current;
	if (current>=0)
	{
		$("#prj_select li:eq("+current+") a").click();
	}
	else
	{
		$("#prj_select li:eq("+(projects_count-1)+") a").click();
		vis = 80*(projects_count-1);
	}

		if (vis>prjwidth) $("#prj_select").animate({left: (prjwidth-vis)});
		else $("#prj_select").animate({left: 0});


	return false;
}

function setupProject(){
	var current = $("#prj_select .active").index();
	var vis = 80*current;
	if (vis>prjwidth) $("#prj_select").animate({left: (prjwidth-vis)});
}

function showProject(id)
{
	$("#special_bottom").css('backgroundImage','url(/content/project/'+id+'.jpg)');

	$("#prj_select .active").removeClass('active');
	$("#pp"+id).addClass('active');

	$("#special > .active").fadeOut().removeClass('active');
	$("#special"+id).fadeIn().addClass('active');

	/*$('#special_top').animate({
	    opacity: 0,
	  }, 600, function(){
		    $("#special_top").css('backgroundImage','url(/content/project/'+id+'.jpg)').css('opacity',1).css('backgroundColor',projects[id][3]);
			$("#project p").html(projects[id][1]);
			if(projects[id][2]!=''){
				$("#project h1").html(projects[id][4]);
				$("#project #videolink").html('Смотреть '+projects[id][2]).attr('href','/video/'+projects[id][5]);
				$(".header .vplayfull").show().attr('href','/video/'+projects[id][5]);
			}
			else
			{
				$("#project h1").html(projects[id][0]);
				$("#project #videolink").html('');
				$(".header .vplayfull").hide();
			}
	});
	*/
	active_project = id;

	return false;
}


function changeStr(){

	if ($("#dyn > div").size()>1)
		$("#dyn").css('top',7).find("div:eq(0)").remove();

	$.ajax({
		'url':'/ajax/advstr',
		'type':'POST',
		'cache':false,
		'success':function(html){
			$("#dyn").append(html);
			$(".ticker .lc").css("background-image",'url("/images/icon_adv.gif?'+Math.floor(Math.random()*1000000)+'")');
			$("#dyn").animate(
				{top: '-=30'},
				400
  			);
			setTimeout("changeStr()",8000);
		},
		'error':function(){
			$("#dyn").fadeIn('fast');
		}
	});
}

function recountMaxSize()
{
	if ($("#proj_preview_wrapper").height()<323)
	{
		diffheight = max_height-(mproj.find('.rc').height()+83);
		if (diffheight<0)
			max_height += -diffheight;
	}

	if ($("#big_preview_wrapper").height()<323)
	{
		diffheight = max_height-(mvideo.find('.rc').height()+83);
		if (diffheight<0)
			max_height += -diffheight;
	}

	mbody.css('height',max_height);
	mproj.css('height',max_height);
	mvideo.css('height',max_height);

	/*$('#fp_video_blogs').animate({height:'+=83'},300);
	max_height+=83;*/
}

// Функция для скрытия ссылки СЛЕДУЮЩИЕ 20
function checkShowmore(html)
{
	var cnt = 20;
	if ((html == '') || (($(".vlistrow").length)%cnt != 0 )) $('.show_more').hide();
	else $('.show_more').show();
}

// Функция для проверки версии флэша
function flashVersion()
{
     if (!navigator.f)
          {
          navigator.f = '0';
     }
     var plugin = 0;

     plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

     if (plugin)
          {
          var re = /(\d+)\.\d+/;
          var out = re.exec(plugin.description);
          if (out.length>1) navigator.f = parseInt(out[1]);
          }
     else
     if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 /*&& (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows XP")>=0)*/)
          {
          try {
               for (i = 3; i <= 11; i++) {
                    if (eval('new ActiveXObject("ShockwaveFlash.ShockwaveFlash.'+i+'")')) {
                         navigator.f = i;
                         }
                    }
               }
          catch(e) {}
          }
     else
          {
          navigator.f = '0';
          }

     return navigator.f;
} 
