p = {
	ie:jQuery.browser.msie && jQuery.browser.version < 9,
	ie6:jQuery.browser.msie && jQuery.browser.version < 7,
	ie7:jQuery.browser.msie && jQuery.browser.version < 8,
	clear:'img/clear.gif'
}

jQuery(document).ready(function(){
	if(p.ie) $('#head-deco-1 >ul.menu li:last-child').addClass('last');
	if(p.ie6) $('div.logo img','#head-deco-1').pngFix();
	
	$('form a.but-1').click(function(){
		$(this).parents('form').submit();
		return(false);
	});
	
	if(p.ie7) $('ul.ul-gallery a').not('ul.lightbox a, div.block-gallery ul.ul-gallery a').click(function(){
			window.location = $(this).attr('href');
		});
	
	$('ul.lightbox a, a.lightbox').lightBox({
				fixedNavigation:false,
				txtImage: 'Фотография',
				txtOf: 'из'
		});
	
	$('div.block-gallery').slider();
});

jQuery.fn.pngFix = function(){
	this.each(function(){
		var param = {
			width:jQuery(this).width(),
			height:jQuery(this).height(),
			src:'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+jQuery(this).attr('src')+'",sizingMethod="scale")'
		}
		jQuery(this).attr('src',p.clear).css({'width':param.width,'height':param.height,'filter':param.src});
	});
}


jQuery.fn.slider = function(){
	this.each(function(){
		var param = {
			list:$('>div.list',this),
			ul:$('>div.list >ul',this),
			a:$('>div.list >ul >li >a',this),
			bigImg:$('>div.big-img',this),
			a2:$('>div.big-img >a',this),
			img:$('>div.big-img >a >img',this)
		}
		
		param.height = $(param.list).height();
		param.height2 = $(param.ul).height()-6;
		
		$(param.a).click(function(){
			var src = $(this).attr('href');
			var href = $(this).attr('rel');
			if(src != $(param.img).attr('src')){
				var loading = $(param.bigImg).append('<img src="'+src+'" class="loading" />').children('img.loading').css('opacity',0);
				$(loading).load(function(){
					$(this).animate({opacity:1},300,function(){
						$(param.img).attr('src',src);
						$(param.a2).attr('href',href);
						$(this).remove();
					});
				});
			}
			return(false);
		});
		
		if(param.height<param.height2){
			$(param.list).mousemove(function(e){
				var top = $(this).offset().top;
				var pos = Math.ceil((param.height2-param.height)/(param.height/(e.pageY - top)));
				$(param.ul).css('top',0-pos);
			});
		}
	});
}
