
$(document).ready(function(){
	//////Раздел НОВОСТИ Определение высоты UL для закладок Фото\Видео	
    if ($.browser.msie && $.browser.version <= 8 || $.browser.safari) 
		{
		var tallest = 0;
		var thisHeight = $('.lenta LI').height();
		$('.lenta LI').each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
				}
			});
		$('.lenta').height(tallest);
		if ($.browser.safari) $('.lenta LI').height(tallest+90);
	}
	
	/////////Бегущая строка новостей
	$("ul#ticker01").liScroll({travelocity: 0.03});
	////////Главная навигация HOVER
	var class_arr = ['head', 'city', 'people', 'money', 'sport', 'power', 'incident', 'newspaper'];
	for (var i = 0; i < class_arr.length; i++) {
			$(".menu ."+class_arr[i]).menuhover(class_arr[i]);
 		}
	
	/*
	$(".menu .head").menuhover('head');
	$(".menu .city").menuhover('city');
	$(".menu .people").menuhover('people');
	$(".menu .money").menuhover('money');
	$(".menu .sport").menuhover('sport');
	$(".menu .power").menuhover('power');
	$(".menu .incident").menuhover('incident');
	$(".menu .newspaper").menuhover('newspaper');
	*/
	/*
	for (var i = 0; i < class_arr.length; i++) {
			$(".menu ."+class_arr[i]).click(function () {document.location.href=''+link_arr[i]+'';});
 		}
		
	$(".menu .head").click(function () {document.location.href=link_head;});
	$(".menu .city").click(function () {document.location.href=link_city;});
	$(".menu .people").click(function () {document.location.href='http://www.[DOMAIN]';});
	$(".menu .money").click(function () {document.location.href='http://www.[DOMAIN]';});
	$(".menu .sport").click(function () {document.location.href='http://www.[DOMAIN]';});
	$(".menu .power").click(function () {document.location.href='http://www.[DOMAIN]';});
	$(".menu .incident").click(function () {document.location.href='http://www.[DOMAIN]';});
	$(".menu .newspaper").click(function () {document.location.href='http://www.[DOMAIN]';});
	*/
	
	/////////Раскрытие списка SMS-новостей
	$("#down_btn").click(function () {
      $("#ticker_menu").toggle("slide", { direction: "up" }, 1000);
    });

	
	////////////////Карат сайта TOP
	var show_map = false;
	$('.map').click(function (){
		if (!show_map) {
			$('#map, .map_corner').fadeIn();
			show_map = true;
		}
		else if(show_map) {
			$('#map, .map_corner').fadeOut();
			show_map = false;
		}
	});
	
	$('.close').click(function (){
		$('#map, .map_corner').fadeOut();
	});
	
});
////////////////////////////////////////////////////////////////////////////////////

//Menu getURL
jQuery.fn.menuhover = function(o) {
	$(this).hover(function() {
		$(this).css('background', 'url(/img/newdesign/default/btn/'+o+'_btn_hover.gif) repeat-x top');
		$(this).css('padding-top', '10px');
		$(this).css('height', '21px');
			}, function() {
			$(this).css('background', 'url(/img/newdesign/default/btn/'+o+'_btn.gif) repeat-x top');
			$(this).css('padding-top', '9px');
			$(this).css('height', '22px');
	});
	
};
//////////////////////////////////////////////////////////////////////////////////////////////

//Главная новостей
jQuery.fn.top_hover = function (i, domain) {
$(this).hover(function () {
		var val_input = $('#news_'+i).val();
		var val_input_name = $('#news_'+i+'_zag').val();
		switch (i) {
			case 1:
				$('#news11').attr('class', 'selected');
				$('#news21').attr('class', '');
				$('#news31').attr('class', 'non_border');
			break;
			case 2:
				$('#news11').attr('class', '');
				$('#news21').attr('class', 'selected');
				$('#news31').attr('class', 'non_border');
			break;
			case 3:
				$('#news11').attr('class', '');
				$('#news21').attr('class', '');
				$('#news31').attr('class', 'selected non_border');
			break;
		}
		$('.news_photo IMG').attr('src', '/img/articles/'+val_input+'.jpg');
		$('.news_photo IMG').attr('alt', val_input_name);
		$('.news_photo IMG').attr('title', val_input_name);
		$('.news_photo A').attr('href', 'http://news.'+domain+'/view/'+val_input+'.html');	
	});
}
/////////////////////////////////////////////////////////////////////////////////////////////

//Высота элементов
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
        tallest = thisHeight;
        }
    });
    group.height(tallest);
}
////////////////////////////////////////////////////////////////////////////////////////////
//Закладки

$.fn.bookmark = function (this_elemet, right_bookmark, left_bookmark, right_button, left_button, IEfix) {
$(this_elemet+' .'+left_button).hide();
$('.nextv, .prevv').hide();
$(this_elemet+' .'+left_bookmark).click(function () {
     	$(this_elemet+' .'+right_button).fadeTo(300, 0.3, function () {
       		$(this_elemet+' .'+left_button).fadeTo(300, 1);
       		$(this_elemet+' .'+right_button).hide();
			$(this_elemet+' .'+left_button).show();
			$('.next, .prev').hide();
			$('.nextv, .prevv').show();
     	});
	
		if (IEfix) {
			if ($.browser.msie && $.browser.version <= 8 ) 
			{
				var tallest = 0;
				var thisHeight = $('.'+right_button+' LI').height();
				$('.'+right_button+' LI').each(function() {
					thisHeight = $(this).height();
					if(thisHeight > tallest) {
						tallest = thisHeight;
					}
				});
				$(right_button,this).height(tallest);
			}
		}
		
		$(this_elemet+' .'+left_bookmark).attr('class', left_bookmark+' selected');
		$(this_elemet+' .'+right_bookmark).attr('class', right_bookmark+' unselected');
    return false;
	
});

	$(this_elemet+' .'+right_bookmark).click(function () {
     	$(this_elemet+' .'+left_button).fadeTo(300, 0.3, function () {
       		$(this_elemet+' .'+right_button).fadeTo(300, 1);
       		$('.nextv, .prevv').hide();
			$('.next, .prev').show();
			$(this_elemet+' .'+right_button).show();
			$(this_elemet+' .'+left_button).hide();
     	});
	 $(this_elemet+' .'+left_bookmark).attr('class', left_bookmark+' unselected');
	 $(this_elemet+' .'+right_bookmark).attr('class', right_bookmark+' selected');	
     return false;
    });
}
//////////////////////////////////////////////////////////////////////////////

//Проверка ширины у фотографий при прочтении новости\статьи
$.fn.photo_wi = function (el, safari) {
	
	if (safari) var wi_new = safari;
	else wi_new = this.width();
	
	if($(el+' .photodescr').is(':visible')) if ($.browser.msie) $(el+' .photodescr').css('filter','progid:DXImageTransform.Microsoft.Alpha(opacity=80)');
	else $(el+' .photodescr').css('opacity','0.8');
	
	if(wi_new < 360) {
		var new_wi = (360 - wi_new)/2;
		$(el).width(wi_new);
		$(el).css('left', new_wi+'px');
		if ($(el+' .descr').is(':visible') && $(el+' .photodescr').is(':visible')) {
			var new_hi = $(el+' .descr').height();
			$(el+' .photodescr').css('bottom', new_hi+6+'px');
		}
		
	} else if (wi_new >= 360 && $(el+' .descr').is(':visible') && $(el+' .photodescr').is(':visible')) {
		var new_hi = $(el+' .descr').height();
		$(el+' .photodescr').css('bottom', new_hi+6+'px');
	}
}

////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function () {			
			//Оценить статью\новость//////////////////////////////////////////////////
			var num_bal=$("#ball_result").text();
			if (eval(num_bal)>=0) {
				$("#ball_result").css('background-color', '#14B100');
				if (eval(num_bal)>0) $("#ball_result").text('+'+num_bal);
			} else $("#ball_result").css('background-color', '#DB3018');
			
			$('#send_res').css('display', 'none');
			
			var options = { 
  				target: "#ball_result",
    			beforeSubmit: showRequest, // функция, вызываемая перед передачей 
    			success: showResponse, // функция, вызываемая при получении ответа
    			timeout: 3000 // тайм-аут
  			};
			$('#plus').submit(function() { 
    			$(this).ajaxSubmit(options); 
    			return false;
  			});
			$('#minus').submit(function() { 
    			$(this).ajaxSubmit(options); 
    			return false;
  			});
			
			function showRequest() { 
    			$('#send_res').css('display', 'block');
				return true;
			}
			
			function showResponse(responseText, statusText)  {
				if (responseText>=0) $("#ball_result").css('background-color', '#14B100');
				else $("#ball_result").css('background-color', '#DB3018');
				$('#send_res').css('display', 'none');
    		}
			//////////////////////////////////////////////////////////////////////////////
			
			//Скрыть каммент////////////////////////////////////////////
			var hide_arr = ['#c210598'];
			function hidecamment(elmn) {
				$(elmn+' .view').click(function () {
					$(this).css('display', 'none');
					$(elmn+' .no_view').css('display', 'block');
				});
			}
			for (var i = 0; i < hide_arr.length; i++) {
				hidecamment(hide_arr[i]);
 			}
			//////////////////////////////////////////////////////////////
			
			//Цитировать///////////////////////////////////////////////////
			$.fn.quote_message = function() {
				function getSelectedText(){
					if(window.getSelection){
						return window.getSelection().toString();
					}
					else if(document.getSelection){
						return document.getSelection();
					}
					else if(document.selection){
						return document.selection.createRange().text;
					}
				}
				$('.quote_cl').append(' <button onfocus="this.blur();" class="bquote" title="Выделите нужный текст и кликните">&nbsp;</button>');
				$('.bquote').click(function() {
					if (getSelectedText()) {
						$('textarea[name="text_form"]').val($('textarea[name="text_form"]').val() + '[quote]' + getSelectedText() + '[/quote]' + '\r\n\r\n').focus();
					} else {
						alert('Вы не выделили текст.');
					}
					return false;
				});
			}
			//////////////////////////////////////////////////////////////////
			
			/*
		$(document).keypress(function(e){
			if ((e.ctrlKey == true) && (e.keyCode == 13)) {
				var selection = window.getSelection();
				alert(selection);
			}
		});
		*/

});

//Оценить каммент///////////////////////////////////////////////////
$.fn.showhide = function (elmn) {	
	$(elmn+' .rat').toggle(
		function() {$(elmn+' .rating').css('display', 'block')},
		function() {$(elmn+' .rating').css('display', 'none')}
		);
			
	var options = { 
  		target: elmn+" .res",
    	beforeSubmit: showRequest, // функция, вызываемая перед передачей 
    	success: showResponse, // функция, вызываемая при получении ответа
    	timeout: 3000 // тайм-аут
  	};
	$(elmn+' .send_plus').submit(function() { 
    	$(this).ajaxSubmit(options); 
    	return false;
  	});
	$(elmn+' .send_minus').submit(function() { 
    	$(this).ajaxSubmit(options); 
    	return false;
  	});
			
	function showRequest() { 
    	$(elmn+' .rating').css('display', 'none');
		$(elmn+' .links .send_res').css('display', 'block');
		return true;
	}
			
	function showResponse(responseText, statusText)  {
		if (responseText==0) {
			$(elmn+" .res").attr('class', 'good res').text('('+responseText+')');
		} else if (responseText>0) {
			$(elmn+" .res").attr('class', 'good res').text('(+'+responseText+')');
		} else {
			$(elmn+" .res").attr('class', 'bad res').text('('+responseText+')');
		}
		$(elmn+' .links .send_res').css('display', 'none');
    }			
}
///////////////////////////////////////////////////////////////////////

//Пожаловатся модератору
$.fn.complaint = function (elmn) {
	var options = { 
  		target: elmn+" .res_complaint",
    	beforeSubmit: showRequest, // функция, вызываемая перед передачей 
    	success: showResponse, // функция, вызываемая при получении ответа
    	timeout: 3000 // тайм-аут
  	};
	$(elmn+' .send_complaint').submit(function() { 
    	$(this).ajaxSubmit(options); 
    	return false;
  	});
			
	function showRequest() { 
    	//$(elmn+' .rating').css('display', 'none');
		//$(elmn+' .links .send_res').css('display', 'block');
		return true;
	}
			
	function showResponse(responseText, statusText)  {
		$(elmn+' .complaint').append(' <span class="bad">(Отправлена)</span>');
    }
}

$.fn.send_message = function (el) {
		$(el+' .complaint').click(function () {
		$(el+' .send_complaint').submit();
	});
}
//////////////////////////////////////////////////////////////////////

//bbcode editor
/*
mySettings = {	
			onShiftEnter:  	{keepDefault:false, replaceWith:'<br />\n'},
			onCtrlEnter:  	{keepDefault:false, openWith:'\n<p>', closeWith:'</p>'},
			onTab:    		{keepDefault:false, replaceWith:'    '},
			markupSet:  [ 	
				{name:'', key:'B', openWith:'[b]', closeWith:'[/b]' },
				{name:'', key:'I', openWith:'[i]', closeWith:'[/i]'  },
				{name:'', key:'S', openWith:'[u]', closeWith:'[/u]' },
				{name:'', key:'U', openWith:'[s]', closeWith:'[/s]' },
				//{separator:'---------------' },
				//{name:'Picture', key:'P', replaceWith:'<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />' },
				{name:'', key:'L', openWith:'[a="[![Link:!:http://]!]"(!( title="[![Title]!]")!)]', closeWith:'[/a]', placeHolder:'Ваш текст для ссылки...' }
				//{separator:'---------------' },
				//{name:'Clean', className:'clean', replaceWith:function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") } },		
				//{name:'Preview', className:'preview',  call:'preview'}
			]/*,
			beforeInsert:function() {
				alert("A markup is going to be inserted");

			},
			afterInsert:function(h) {
				text = "The result is now:\n";
				text+= $(h.textarea).val();
				alert(text);
				}
			*/
/*
		}
*/
///////////////////////////////////////////////////////////////////////////////////////////

//bbcode parser
$.fn.bbcode_parser = function () {
	var el = $(this);
	//Цитаты [QUOTE]
	//\[QUOT="([^|]+)\s\|\s([^"\]]+)"\]([^\[\QUOT\]]+)
	var reg_q = /\[QUOT="([^|]+)\s\|\s([^"\]]+)"\]([^\[]+)\[\/QUOT\]/ig;
	var tex_q = $(this).html();
	while ((ahref_q = reg_q.exec(tex_q)) != null)
	{
		ahref_q[3].replace(RegExp("\/", "ig"), "\\/");
		//alert(ahref_q[3]);
		var reg_ex_q = RegExp('\\[QUOT="([^|]+)\\s\\|\\s([^"\\]]+)"\\]('+ahref_q[3]+')\\[\\/QUOT\\]', 'ig');
  		el.html(el.html().replace(reg_ex_q, '<div class="in_quote"><span><b>'+ahref_q[1]+'</b> '+ahref_q[2]+'</span>'+ahref_q[3]+'</div>'));
	}
	//////////////////////////////////////
	
	var bbcode = ['\\[b\\]', '\\[\\/b\\]', '\\[i\\]', '\\[\\/i\\]', '\\[u\\]', '\\[\\/u\\]', '\\[s\\]', '\\[\\/s\\]'];
	var tags = ['<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<s>', '</s>'];
	
	for (var i=0; i < bbcode.length; i++)
	{
		el.html(el.html().replace(RegExp(bbcode[i], 'ig'), tags[i]));
	}
	
	//Ссылки [a=""][/a]
	var reg = /\[a=\"(\S+)\"\]([^\[\]]*)\[\/a\]/ig;
	var tex = $(this).html();
	while ((ahref = reg.exec(tex)) != null)
	{	
		var reg_ex = RegExp('\\[a=\\"\\S+\\"\\]('+ahref[2]+')?\\[\\/a\\]', 'ig');
  		el.html(el.html().replace(reg_ex, '<a href="'+ahref[1]+'">'+ahref[2]+'</a>'));
	}
	//////////////////////////////////////
}

function  OpenPageArticles(page, idarticles, domain, menu, width, height)
{
	var url = "http://www."+domain+"/"+page+".html?articles="+idarticles;
	var param = "no";
	if(menu) param = "yes";
	winpage = window.open(url, "blog", "status=no,toolbar=no,scrollbars=yes,menubar="+param+",resizable=yes,width="+width+",height="+height+" ");
}


		