ie = jQuery.browser.msie && jQuery.browser.version == 6;

jQuery(document).ready(function(){
	if(ie){
		jQuery('img[src$=".png"]').pngFix();
		
		ieFixScroll();
		jQuery(window).resize(function(){ ieFixScroll(); });
	}
	
	jQuery('ul.ul-stores b >a').click(function(){
		var parent = jQuery(this).parent().parent();
		if(!jQuery(parent).is('.current')){
			var href = jQuery(this).attr('href');
			jQuery(parent).parent().children('li.current').children('ul').slideToggle(500).parent().removeClass('current');
			jQuery('>ul',parent).slideToggle(500,function(){ jQuery('#deco-img >iframe').attr('src',href); }).parent().addClass('current');
		}
		return(false);
	});
	
	jQuery('div.catalog-item-list').catalogList();
	
	jQuery('ul.ul-catalog-2').liHeight(); // Выравнивание высоты блоков
});

function ieFixScroll(){
	if( jQuery('#main-deco').height() > jQuery('#wrap').height() ) jQuery('#footer,#main-deco').css('width',jQuery('#wrap').width()-17);
	else jQuery('#footer,#main-deco').css('width','100%');
}

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','/img/clear.gif').css({'width':param.width,'height':param.height,'filter':param.src});
	});
}

jQuery.fn.catalogList = function(){
	this.each(function(){
		var p = {
			list:jQuery('>div.item-scroll >ul',this),
			img:jQuery(this).next('div.catalog-item-img'),
			count:jQuery('li',this).length,
			current:1,
			height:119,
			speed:300,
			fspeed:300
		}
		if( p.count<=3 ) jQuery('>a',this).addClass('unact').click(function(){ return(false); });
		else{
			jQuery('li',p.list).clone().appendTo(p.list);
			
			jQuery('>a',this).click(function(){
				if( jQuery(this).is('.bottom') ){
					if( p.current == p.count-2 ){
						jQuery(p.list).css('top',0);
						p.current = 1;
					}
					jQuery(p.list).stop(true).animate({top:0-p.current++*p.height},p.speed);
				}else{
					if( p.current == 1 ){
						jQuery(p.list).stop(true).css('top',0-(p.count-3)*p.height);
						p.current = p.count-2;
					}
					jQuery(p.list).stop(true).animate({top:0-(p.current-- -2)*p.height},p.speed);
				}
				return(false);
			});
		}
		
		jQuery('a',p.list).click(function(){
			jQuery(p.img).append('<img src="'+jQuery(this).attr('href')+'" width="510" height="385" alt="'+jQuery(this).attr('title')+'" />').children('img:last').css('position','absolute').hide().fadeIn(p.fspeed,function(){ jQuery('>img:lt('+jQuery(this).css('position','static').index()+')',p.img).remove(); });
			return(false);
		});
	});
}

jQuery.fn.liHeight = function(){
	var li = jQuery('>li:even',this);
	jQuery(li).each(function(){
		var h = jQuery('>div.info',this).height();
		var h2 = jQuery(this).next().children('div.info').height();
		
		if(h > h2) jQuery(this).next().children('div.info').height(h);
		else if(h < h2) jQuery('>div.info',this).height(h2);
	});
}

