$(document).ready(function(){
	/*01.9.2011*/
	var itemLengthLeft = $('.left_news .items_wrap .item').length;
	var itemLengthRight = $('.right_news .items_wrap .item').length;
	itemLengt = itemLengthLeft;
	if(itemLengthLeft < itemLengthRight){itemLengt = itemLengthRight}
	for(i=0; i<itemLengt; i++){
		var h1 = $('.left_news .items_wrap .item:eq('+i+')').height();
		var h2 = $('.right_news .items_wrap .item:eq('+i+')').height();
		h = h1;
		if(h1 < h2){h = h2};
		$('.left_news .items_wrap .item:eq('+i+')').height(h);
		$('.right_news .items_wrap .item:eq('+i+')').height(h);
	}
	/*01.9.2011*/
	
	
	
	$('.items_wrap').each(function(){
		$('.item:last',$(this)).addClass('itemLast')	
	})
	
	
	// tabs
jQuery.fn.liTabSlide = function(options){
	// настройки по умолчанию
	var o = jQuery.extend({
	//n_coll: 2 //колличество колонок
	},options);
	return this.each(function(){
		
		var tabs_wrap = $(this),
			wrap_h = tabs_wrap.outerHeight(),
			tab_h = $('.tab',tabs_wrap).outerHeight()
			
		//День недели	
		today=new Date();
		thisDay=today.getDay();
		thisDay = thisDay - 1
		
		$('.tabLi:eq('+thisDay+')',$('.days')).addClass('cur')
			
			
		//slide auto
			var tab_length = tabs_wrap.children('li').length;
			var tab_contShow = $('.cur',tabs_wrap).find('.tab').next('.tab_cont').show();
			//tabs_wrap.height(tab_contShow.height()+$('.cur').height())
			
			
			//click show
			tabs_wrap.children('li').each(function(){
				var tab = $(this),
					tab_link = $('.tab',tab),
					tab_cont = $('.tab_cont',tab);
				tab_cont.css({top:tab_link.outerHeight()});
				tab_link.bind('click',function(){
					$('.tab_cont').not(tab_cont).stop().hide().css({opacity:'0'});
					$('.cur',tabs_wrap).removeClass('cur');
					tab_link.parent().addClass('cur');
					tab_cont.css({display:'block'}).css({opacity:'1'})
					//tabs_wrap.height(tab_cont.height()+tab_link.height()+15)
					return false
				});
			});
	});
};
$(window).load(function(){
	$('.tabsWrap').liTabSlide();
})
//tabs
	
	
	
	var method = 'easeOutCirc';
	$('.menu_top').each(function(){
		var menuWrap = $(this);
		var menuItem = menuWrap.children('li');
		var menuLink = menuItem.children('a');
		var menuItemLength = menuItem.length;
		mOutWidthSum = 0;
		menuLink.each(function(){
			var mLink = $(this);
			var mText = mLink.text();
			var mWidth = mLink.width();
			
			mOutWidthSum += mWidth
			mLink.width(mWidth);
			mLink.wrapInner('<span class="p_1">');
			$('.p_1',mLink).width(mWidth).clone().attr('class','p_2').appendTo(mLink);
			var mp_1 = $('.p_1',mLink);
			var mp_2 = $('.p_2',mLink);
			mLink.not('.cur').parent().bind('mouseenter',function(){
				mp_1.stop().animate({marginLeft:'-'+mWidth},300,method)
			}).bind('mouseleave',function(){
				mp_1.stop().animate({marginLeft:'0'},300,method)
			})
		})
		var menuLinkMargin = (960 - mOutWidthSum)/menuItemLength/2-1
		menuLink.css({margin:'0 '+menuLinkMargin+'px'})
		
		$('#header').bind('mousemove',function(e) {
			var offset = $(this).offset();
			var relativeX = (e.pageX - offset.left);
			var relativeY = (e.pageY - offset.top);
			var menuWrapPoss = menuWrap.offset();	
			var menuWrapX = menuWrapPoss.left;
			var menuWrapY = menuWrapPoss.top;
			var posX = relativeX - menuWrapX;
			var posY = relativeY - menuWrapY;
			$('.light').css({left:posX-75,top:posY-75});
		});
		
	})
	
	
	var label_w = $('.form_style label').outerWidth()
	$('.form_style .error,.form_style .help,.form_style .but_1').css({marginLeft:label_w})
	$('#image').next('a').addClass('update_captcha')
	//tables style
	$(".table1 tr,.table2 td").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	$(".table1 tr:even").addClass("alt");
	$(".table1 tr").find('td:first').addClass('td_first')
	$(".table2,.table1").wrap('<div class="table_wrap">')
	
	//photo Gallery 0.1
	/*
	$('body').delegate('.img_link','mouseenter',function(){
			$(this).find('img').animate({opacity:'0.5'},100).animate({opacity:'1'},300)
	})
	*/
	//photo Gallery 0.2
	var g_items = $('.img_link,.wrapInner a');
	g_items.each(function(){
		$(this).hover(function(){
			g_items.not(this).find('img').stop().animate({opacity:'0.4'},300)
		},function(){
			g_items.not(this).find('img').stop().animate({opacity:'1'},300)
		})	
	})
	
	var gr = $('.group_link');
	gr.each(function(){
		$(this).hover(function(){
			$(this).find('img').stop().animate({opacity:'0.4'},300)
		},function(){
			$(this).find('img').stop().animate({opacity:'1'},300)
		})	
	})


	// img style
	$('.content>img,.content>p>img,.content>a>img').each(function(){
		var float = $(this).attr('style')
		var align = $(this).attr('align')
		if(float == 'float: left;' || float == 'float: left' || float == 'float:left;' || float == 'float:left' || align == 'left'){
			$(this).addClass('imgLeft')	
		}
		if(float == 'float: right;' || float == 'float: right' || float == 'float:right;' || float == 'float:right' || align == 'right'){
			$(this).addClass('imgRight')	
		}
	})

	/*-----------------------*/
	$(window).load(function(){
		
		
		//quotes min
		jQuery.fn.liQuotes=function(options){var o=jQuery.extend({},options);return this.each(function(){htmlreplace($(this));function htmlreplace(element){if(!element)element=document.body;var nodes=$(element).contents().each(function(){if(this.nodeType==Node.TEXT_NODE){$(this).wrap('<span class="node_t"/>');}else{htmlreplace(this);}});};$('.node_t').each(function(){var el=$(this),str=el.html(),raquo_one=/'\s/g,laquo_one=/\s'/g,raquo_two=/"\s/g,laquo_two=/\s"/g,raquo_brack_one=/'\)/g,laquo_brack_one=/\('/g,raquo_brack_two=/"\)/g,laquo_brack_two=/\("/g,raquo_tag_one=/'$/g,laquo_tag_one=/^'/g,raquo_tag_two=/"$/g,laquo_tag_two=/^"/g,raquo_one_coma=/'\,/g,raquo_one_dot=/'\./g,raquo_two_coma=/"\,/g,raquo_two_dot=/"\./g,raquo_one_colon=/'\:/g,raquo_two_colon=/"\:/g,quest_one_colon=/'\?/g,quest_two_colon=/"\?/g,exclam_one_colon=/'\!/g,exclam_two_colon=/"\!/g,semic_one_colon=/'\;/g,semic_two_colon=/"\;/g;var result=str.replace(laquo_one," &laquo;").replace(raquo_one,"&raquo; ").replace(laquo_two," &laquo;").replace(raquo_two,"&raquo; ").replace(raquo_one_coma,"&raquo;,").replace(raquo_one_dot,"&raquo;.").replace(raquo_two_coma,"&raquo;,").replace(raquo_two_dot,"&raquo;.").replace(raquo_one_colon,"&raquo;:").replace(raquo_two_colon,"&raquo;:").replace(quest_one_colon,"&raquo;?").replace(quest_two_colon,"&raquo;?").replace(exclam_one_colon,"&raquo;!").replace(exclam_two_colon,"&raquo;!").replace(laquo_brack_one,"(&laquo;").replace(raquo_brack_one,"&raquo;)").replace(laquo_brack_two,"(&laquo;").replace(raquo_brack_two,"&raquo;)").replace(laquo_tag_one,"&laquo;").replace(raquo_tag_one,"&raquo;").replace(laquo_tag_two,"&laquo;").replace(raquo_tag_two,"&raquo;").replace(semic_one_colon,"&raquo;;").replace(semic_two_colon,"&raquo;;");el.html(result);})});};
		$('.q').liQuotes();
	})
});
