p = {
	ie:jQuery.browser.msie && jQuery.browser.version < 9,
	heightEtc:100, //высота списка block-info без обрезания
	timeHeader:8000 //задержка слайдшоу
}
if(p.ie){
	(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while (i--){document.createElement(e[i])}})()
	$('table >tbody >tr:last-child').addClass('last-child');
	$('table >tbody >tr:even').addClass('even');
}

jQuery(document).ready(function(){
	if(p.ie){
		$('table >tbody >tr:last-child').addClass('last-child');
		$('table >tbody >tr:odd').addClass('even');
	}
	
	$('#header').header();
	
	$('div.block-info ul').etc();
	
	$('form a.but-1').click(function(){
		$(this).parents('form').submit();
		return(false);
	});
});

jQuery.fn.header = function(){
	var param = {
		img:$('#header-img').children()
	}
	param.count = $(param.img).length;
	
	if(param.count > 1){
		var html = '<a href="#prev" class="prev" title="Предыдущая">Предыдущая</a><a href="#next" class="next" title="Следующая">Следующая</a>';
		$('#header-deco').append(html);
		
		param.list = $('#header-deco >a');
		
		$(param.list).click(function(){
			$('#header-img').stop(true).autoslide()
			
			var c = $(param.img).filter(':visible');
			var z = $(c).length;
			if($(this).is('.next')) var next = ($(c).last().next().length)?$(c).last().next():$(param.img).first();
			else var next = ($(c).first().prev().length)?$(c).first().prev():$(param.img).last();
			
			$(next).css('z-index',z).animate({opacity:'show'},300,function(){ $(c).not(next).hide(); $(this).css('z-index',0); });
			
			return(false);
		});
		
		$('#header-img').autoslide();
	}
}

jQuery.fn.autoslide = function(){
	$(this).animate({marginTop:0},p.timeHeader,function(){
		var c = $('#header-img >*:visible');
		var z = $(c).length;
		
		var next = ($(c).last().next().length)?$(c).last().next():$('#header-img').children().first();
		
		$(next).css('z-index',z).animate({opacity:'show'},300,function(){ $(c).not(next).hide(); $(this).css('z-index',0); });
		
		$(this).autoslide();
	});
}

jQuery.fn.etc = function(){
	this.each(function(){
		var param = {
			ul:this,
			li:$('>li',this),
			detail:$(this).next('div.detail').children('a')
		}
		param.count = $(param.li).length;
		var i = 0;
		
		for(h=0;h<p.heightEtc;i++){
			h = h + $(param.li).eq(i).outerHeight();
			if(i == param.count-1) h = p.heightEtc;;
		}
		
		if(i < param.count-1){
			param.h = $(this).height();
			param.h2 = h;
			param.etc = $(this).height(h).after('<div class="etc">...</div>').data('param',param).next('div.etc');
			$(param.detail).click(function(){
				$(param.ul).animate({height:($(param.ul).height() < param.h)?param.h:param.h2},300);
				$(param.etc).slideToggle(300);
				
				return(false);
			});
		}else $(param.detail).parent().hide();
	});
}



