$("#cotnent img").lazyload();

var IE7 = false;
if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 7){
	IE7 = true;
}
var IEl9 = false;
if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 9){
	IEl9 = true;
}

var WebKit = false;
if(jQuery.browser.webkit){
	WebKit = true;
}

$(document).ready(function(){
	$("a[rel='gal']").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"95%", maxHeight:"95%", current:"{current} / {total}", slideshow:true, slideshowAuto:false, slideshowStart:"", slideshowStop:""});
	$("a.gal").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%", current:"", slideshow:false, slideshowAuto:false, slideshowStart:"", slideshowStop:""});
	
	inputActivation();
	searchHelper();
	//debugFunctions();
	rurReplace();
	$(window).load(function(){
		if($('.headerPlace').length){
			getSearchLinePlace();
		}
	});
	//switchShopBlock();
	bankSlider();
	logoSlider();
	askForm();
	productPage();
	titleWidth();
	$(window).load(function(){
		actionsMain();
	});
	
	productButtons();
	credLink();
	
	buttonsHelpers();
	
	compareOverflow();
	
	
	if($('.catalog-section').length){
		if($(document).width()< 1244){
			$('.pContainer').each(function(){
				$(this).find('.product:last').hide();
			});
		}else{
			$('.product').show();
		}
		$(window).resize(function(){
			if($(document).width()< 1244){
				$('.pContainer').each(function(){
					$(this).find('.product:last').hide();
				});
			}else{
				$('.product').show();
			}
		});
	}
	
	if($('.mpBlock').length){
		$('.mpBlock').each(function(){
			$(this).find('.product').show();
		});
		if($(document).width()< 1252){
			$('.mpBlock').each(function(){
				$(this).find('.product:eq(7)').nextAll().hide();
			});
		}
		
		if($(document).width()< 1049){
			$('.mpBlock').each(function(){
				$(this).find('.product:eq(5)').nextAll().hide();
			});
		}
		
		$(window).resize(function(){
			$('.mpBlock').each(function(){
				$(this).find('.product').show();
			});
			if($(document).width()< 1252){
				$('.mpBlock').each(function(){
					$(this).find('.product:eq(7)').nextAll().hide();
				});
			}
			
			if($(document).width()< 1049){
				$('.mpBlock').each(function(){
					$(this).find('.product:eq(5)').nextAll().hide();
				});
			}
		});
	}
});

var ShowReaktiveFlag = false;

function ShowReaktiveStart(){ ShowReaktiveFlag = true; setTimeout("ShowReaktive()",50); }
function ShowReaktive(){
	if ((ShowReaktiveFlag) && ($("#reaktive_block").css('display')=='none')){
		$("#reaktive_block").css({display: "block"});
		$("#reaktive_block IMG").css({width: 0, height: 0, left: 205, top: 121});
		$("#reaktive_block IMG").animate({width: 274, height: 131, left:0, top:0}, 300);
	}
}

function HideReaktiveStart(){ ShowReaktiveFlag = false; setTimeout("HideReaktive()",50); }
function HideReaktive(){
	if ((!ShowReaktiveFlag) && ($("#reaktive_block").css('display')!='none')){
		if ($.browser.msie) $("#reaktive_block").css('display','none');
		else $("#reaktive_block").fadeOut(300);
	}
}


function debugFunctions(){
	$('.mainMenu a').click(function(){
		$('.mainMenu div').removeClass('active');
		$(this).parent().toggleClass('active');
		setMenuTriangle()
	});
}

$('.triangle').ready(function(){
	setMenuTriangle();
	$(window).resize(function(){
		setMenuTriangle();
	});
});

function searchHelper(){
	if($('#smallSearchString').val() == ""){$('#smallSearchString').val('Поиск по каталогу');}
	$('#smallSearchString').focus(function(){
		if($('#smallSearchString').val() == "Поиск по каталогу"){
			$('#smallSearchString').val('').removeClass('void');
		}else{
			$('#smallSearchString').select();
		}
		
	});
	$('#smallSearchString').blur(function(){
		if($('#smallSearchString').val() == ""){$('#smallSearchString').val('Поиск по каталогу').addClass('void');}
	});
}

function inputActivation(){
	$('.inpC').click(function(){
		$(this).find('input').focus();
	});
	
	$('.inpC').hover(function(){
		$(this).addClass('iHover');
	},function(){
		$(this).removeClass('iHover');
	});
	
	$('.inpC input, .inpC textarea').focus(function(){
		$(this).parent().addClass('iFocus');
	});
	$('.inpC input, .inpC textarea').blur(function(){
		$(this).parent().removeClass('iFocus');
	})
}
function rurReplace(){
	$('span.RUR').html('&#8399');
}

function getSearchLinePlace(){
	var ie7d = 0;
	if(IE7){
		ie7d = 0;
	}
	var hH = $('.headerPlace').height();
	var sH = $('.searchLeft').height();
	$('.searchLeft').css('margin-top', hH-sH+6 - ie7d);
	
	$(window).resize(function(){
		hH = $('.headerPlace').height();
		sH = $('.searchLeft').height();
		$('.searchLeft').css('margin-top', hH-sH+6 - ie7d);
	});
}

function setMenuTriangle(){
	var icon = $('#header .cCenter .active');
	var tri = $('.triangle');
	var tl = $('#header .tl');
	var	iconOffset = Math.round(icon.offset().left-$('#header').offset().left);
	if(icon.hasClass('mCFirst')){
		tri.width(icon.width());
	}else{
		if(icon.hasClass('menuContainer-last')){
			tri.width(icon.outerWidth()+20);
		}else{
			tri.width(icon.outerWidth());
		}
	}
	tl.width(iconOffset);
}

function logoSlider(){
	var slWidth = $('.fSlider-overflow').width();
	var itWidth = 0;
	var rC = $('#footer .fs-Right');
	var lC = $('#footer .fs-Left');
	var cont = $('#footer .fSlider-container');
	var offset = 0;
	cont.css('left', 0);
	$('.fSlider .item').each(function(){
		itWidth += $(this).width()+25;
	});
	itWidth += -25;
	
	offset = slWidth - itWidth;
	
	if(offset > 0){
		lC.hide();
		rC.hide();
		$('#footer .fSlider-pad').css('padding', '0');
		cont.width(itWidth+5);
		cont.css('margin', '0 auto');
		cont.css('left','auto');
	}else{
		lC.hide();
		rC.show();
		$('#footer .fSlider-pad').css('padding', '0 30px');
		cont.width(itWidth+5);
		cont.css('margin', '0 0');
		cont.css('left','0');
	}
	
	lC.mousedown(function(){
		rC.show();
		cont.animate({left:0},'slow', function(){cont.stop(true); lC.hide();});
	});
	lC.mouseup(function(){cont.stop(true);});
	
	rC.mousedown(function(){
		lC.show();
		cont.animate({left:offset},'slow', function(){cont.stop(true); rC.hide();});
	});
	rC.mouseup(function(){cont.stop(true);});
	
	$(window).resize(function(){
		slWidth = $('.fSlider-overflow').width();
		offset = slWidth - itWidth;
		cont.css('left', 0);
		if(offset > 0){
			lC.hide();
			rC.hide();
			$('#footer .fSlider-pad').css('padding', '0');
			cont.css('margin', '0 auto');
			cont.css('left','auto');
		}else{
			lC.hide();
			rC.show();
			$('#footer .fSlider-pad').css('padding', '0 30px');
			cont.css('margin', '0 0');
			cont.css('left','0');
		}
	});
}

function bankSlider(){
	var slWidth = $('.bs-overflow').width();
	var itWidth = 0;
	var rC = $('#bs-right');
	var lC = $('#bs-left');
	var cont = $('.bs-container');
	var offset = 0;
	var curItem = 1;
	cont.css('left', 0);
	
	//offset = slWidth - itWidth;
	
	if($('.bs-item').length - 1 <= curItem){
		lC.hide();
		rC.hide();
		$('#banksSlider .bs-pad').css('padding', '0');
		
	}else{
		lC.hide();
		rC.show();
		t.css('left', 0);
	}
	
	lC.click(function(){
		curItem --;
		//console.log('cItem: '+curItem);
		//console.log($('.bs-item').length-1);
		rC.show();
		if(curItem == 1){
			curItem = 1;
			var widthOffset = $('.bs-item:eq('+curItem+')').width()+20;
			cont.animate({left:cont.position().left + widthOffset},100);
			lC.hide();
		}else{
			var widthOffset = $('.bs-item:eq('+curItem+')').width()+20;
			cont.animate({left:cont.position().left + widthOffset},100);
		}
	});
	
	rC.click(function(){
		curItem++;
		//console.log('cItem: '+curItem);
		//console.log($('.bs-item').length-1);
		
		lC.show();
		if(curItem == $('.bs-item').length-1){
			curItem = $('.bs-item').length-1;
			var widthOffset = $('.bs-item:eq('+curItem+')').width()+20;
			cont.animate({left:cont.position().left - widthOffset},100);
			rC.hide();
		}else{
			var widthOffset = $('.bs-item:eq('+curItem+')').width()+20;
			cont.animate({left:cont.position().left - widthOffset},100);
		}
	});
	
	$(window).resize(function(){
		slWidth = $('.bs-overflow').width();
		curItem = 1;
		cont.css('left', 0);
		if($('.bs-item').length-1 <= curItem){
			lC.hide();
			rC.hide();
		}else{
			lC.hide();
			rC.show();
		}
	});
}

function switchShopBlock(){
	$('#switchShopBlock').click(function(){
		if($('#permH').hasClass('active')){
			$('#permH').removeClass('active');
			$('#permKrayH').addClass('active');
			$('#permH').hide();
			$('#permKrayH').show();
			$('#permShops').hide();
			$('#permKrayShops').show();
			$('#switchShopBlock span').html('Магазины в&nbsp;Перми');
		}else{
			$('#permH').addClass('active');
			$('#permKrayH').removeClass('active');
			$('#permH').show();
			$('#permKrayH').hide();
			$('#permShops').show();
			$('#permKrayShops').hide();
			$('#switchShopBlock span').html('Магазины в&nbsp;Пермском крае');
		}
	});
}

function askForm(){
	$('#askLink').click(function(){
		$('#dark').show();
		$('#askQuestion').show();
		
		$('#dark').click(function(){
			$('#askQuestion').hide();
			$('#dark').hide();
		});
		
		$('#aQClose').click(function(){
			$('#askQuestion').hide();
			$('#dark').hide();
		});
	});
}

function titleWidth(){
	$('.headerPlace').ready(function(){
		$('.headerPlace h1').css('margin-right', $('.headerServiceLinks').width()+20);
	});
	$(window).resize(function(){
		$('.headerPlace h1').css('margin-right', $('.headerServiceLinks').width()+20);
	});
}

function productPage(){
	$('#prodDesc').click(function(event){
		event.preventDefault();
		$('.listMenu a').removeClass('active');
		$(this).addClass('active');
		$('.productDescription').show();
		$('.productCharacteristics').hide();
	});
	$('#prodChar').click(function(event){
		event.preventDefault();
		$('.listMenu a').removeClass('active');
		$(this).addClass('active');
		$('.productDescription').hide();
		$('.productCharacteristics').show();
	});
}
function productButtons(){
	$('.product .pButtons .pb-nal').bind('click', function(){
		if(!$(this).hasClass('active')){
            $('#nal .rsb-container').html('<div class="pad"><p class="infLoading"><img src="/pics/i/info-loading.gif" alt="Данные загружаются" />Получение данных, пожалуйста подождите...</p></div>');
			$('#nal').hide();
			$('#compareF').hide();
			$('#characteristicsF').hide();
			$('.product .pButtons a').removeClass('active');
			$(this).addClass('active');
			$('.product').css('z-index', 0);
			var form = $('#nal');
			var window = form.find('.window');
			var prod = $(this).parent().parent();
			prod.css('z-index', 4);
			var pW = prod.width();
			var pH = prod.height()-25;
			var marginPx = 0;
			if(!WebKit){
				marginPx = parseInt(prod.css('margin-right'), 10);
			}else{
				if(!prod.parent().hasClass('pFullList')){
					marginPx = Math.round((parseInt(prod.css('margin-right'),10)/100)*prod.parent().width(), 10);
				}else{
					marginPx = parseInt(prod.css('margin-right'), 10);
				}
			}
			//console.log(marginPx);
			var marginTop = 25;
			var prLeft = prod.offset().left;
			var prTop = prod.offset().top;
			pW = pW + marginPx*2 - 20;
			pH = pH + 55;
			window.css({width:pW, height:pH});
			form.find('.rsb-container').width(pW);
			form.width(pW+26);
			if(IE7){
				$('.product').css('visibility','visible');
				window.find('.product').remove();
				var $currentProduct = prod.html();
				window.html('<div class="product">'+$currentProduct+"</div>");
				prod.css('visibility','hidden');
				$('.rsb .pb-nal').unbind('click');
				$('.rsb .pb-comp').unbind('click');
				$('.rsb .pb-comp').click(function(){
					prod.find('.pb-comp').trigger('click');
				});
				$('.rsb .pb-nal').click(function(){
					prod.find('.pb-nal').trigger('click');
				});	
			}

            $.ajax({
                type: "GET",
                url: "/catalog/rsb_address.php?ELEMENT_ID="+$(this).attr('id'),
                cache: false,
                success: function(html){
                    $('#nal .rsb-container').html(html);
                },
                failure: function(){
                    $('#nal .rsb-container').html('Нет данных');
                }
            });
            
			var offIE = 0;
			if(IE7){offIE = 20;}
			form.css({left: prLeft-marginPx, top:prTop-55+offIE});
			form.find('.rsb-container .pad').css('padding', '0 ' + (marginPx-9) + 'px  12px');
			form.show();
			resizeHandler(this, form);
			form.find('.close-small').click(function(){
				$('#nal').hide();
				$('#compareF').hide();
				$('#characteristicsF').hide();
				$('.product .pButtons a').removeClass('active');
				if(IE7){
					$('.product').css('visibility','visible');
					window.find('.product').remove();
				}
			});
		}else{
			$('#nal').hide();
			$('.product .pButtons a').removeClass('active');
			if(IE7){
				$('.product').css('visibility','visible');
				window.find('.product').remove();
			}
			
		}
		
	});
	
	$('.product .pButtons .pb-comp').bind('click', function(){
		if(!$(this).hasClass('active')){
            $('#compareF .rsb-container').html('<div class="pad"><p class="infLoading"><img src="/pics/i/info-loading.gif" alt="Данные загружаются" />Получение данных, пожалуйста подождите...</p></div>');
			$('#nal').hide();
			if(IE7){
				$('.product').css('visibility','visible');
			}
			$('#compareF').hide();
			$('#characteristicsF').hide();
			$('.product .pButtons a').removeClass('active');
			$(this).addClass('active');
			$('.product').css('z-index', 0);
			var form = $('#compareF');
			var window = form.find('.window');
			var prod = $(this).parent().parent();
			prod.css('position', 'relative');
			prod.css('z-index', 4);
			var pW = prod.width();
			var pH = prod.height()-25;
			var marginPx = 0;
			if(!WebKit){
				marginPx = parseInt(prod.css('margin-right'), 10);
			}else{
				if(!prod.parent().hasClass('pFullList')){
					marginPx = Math.round((parseInt(prod.css('margin-right'),10)/100)*prod.parent().width(), 10);
				}else{
					marginPx = parseInt(prod.css('margin-right'), 10);
				}
			}
			var marginTop = 25;
			var prLeft = prod.offset().left;
			var prTop = prod.offset().top;
			pW = pW + marginPx*2 - 20;
			pH = pH + 55;
			
			form.find('.rsb-container').width(pW);
			form.width(pW+26);
			window.css({width:pW, height:pH});

			if(IE7){
				$('.product').css('visibility','visible');
				window.find('.product').remove();
				var $currentProduct = prod.html();
				window.html('<div class="product">'+$currentProduct+"</div>");
				prod.css('visibility','hidden');
				$('.rsb .pb-nal').unbind('click');
				$('.rsb .pb-comp').unbind('click');
				$('.rsb .pb-comp').click(function(){
					prod.find('.pb-comp').trigger('click');
				});
				$('.rsb .pb-nal').click(function(){
					prod.find('.pb-nal').trigger('click');
				});
			}
            $.ajax({
                type: "GET",
                url: "/catalog/rsb_add_compare.php?ELEMENT_ID="+$(this).attr('id')+"&clear_cache=Y",
                cache: false,
                success: function(html){
                    $('#compareF .rsb-container').html(html);
                },
                failure: function(){
                    $('#compareF .rsb-container').html('Нет данных');
                }
            });

			var offIE = 0;
			if(!$('#compareCount').length){
				prTop +=32;
			}
			if(IE7){offIE = 20;}
			form.css({left: prLeft-marginPx, top:prTop-55+offIE});
			//console.log(prTop);
			//console.log(offIE);
			form.find('.rsb-container .pad').css('padding', '0 ' + (marginPx-9) + 'px  12px');
			form.show();
			resizeHandler(this, form);
			form.find('.close-small').click(function(){
				$('#nal').hide();
				$('#compareF').hide();
				$('#characteristicsF').hide();
				$('.product .pButtons a').removeClass('active');
				if(IE7){
					$('.product').css('visibility','visible');
					window.find('.product').remove();
				}
			});
		}else{
			$('#compareF').hide();
			$('.product .pButtons a').removeClass('active');
			if(IE7){
				$('.product').css('visibility','visible');
				window.find('.product').remove();
			}
		}
	});
	
	$('.product .pButtons .pb-char').click(function(){
		if(!$(this).hasClass('active')){
            $('#characteristicsF .rsb-container').html('<div class="pad"><p class="infLoading"><img src="/pics/i/info-loading.gif" alt="Данные загружаются" />Получение данных, пожалуйста подождите...</p></div>');
			$('#nal').hide();
			$('#compareF').hide();
			$('#characteristicsF').hide();
			$('.product .pButtons a').removeClass('active');
			$(this).addClass('active');
			$('.product').css('z-index', 0);
			var form = $('#characteristicsF');
			var window = form.find('.window');
			var prod = $(this).parent().parent();
			prod.css('position', 'relative');
			prod.css('z-index', 4);
			var pW = prod.width();
			var pH = prod.height();
			var marginPx = 0;
			if(!WebKit){
				marginPx = parseInt(prod.css('margin-right'), 10);
			}else{
				marginPx = Math.round((parseInt(prod.css('margin-right'),10)/100)*prod.parent().width(), 10);
				console.log(marginPx);
			}
			var marginTop = 25;
			var prLeft = prod.offset().left;
			var prTop = prod.offset().top;
			pW = pW + marginPx*2 - 20;
			pH = pH + 25;
			form.find('.rsb-container').width(pW);
			form.width(pW+26);
			window.css({width:pW, height:pH});

            $.ajax({
                type: "GET",
                url: "/catalog/rsb_properties.php?ELEMENT_ID="+$(this).attr('id'),
                cache: false,
                success: function(html){
                    $('#characteristicsF .rsb-container').html(html);
                },
                failure: function(){
                    $('#characteristicsF .rsb-container').html('Нет данных');
                }
            });


			var offIE = 0;
			if(IE7){offIE = 20;}
			form.css({left: prLeft-marginPx, top:prTop-25+offIE});
			form.find('.rsb-container .pad').css('padding', '0 ' + (marginPx-9) + 'px  12px');
			form.show();
			resizeHandler(this, form);
			form.find('.close-small').click(function(){
				$('#nal').hide();
				$('#compareF').hide();
				$('#characteristicsF').hide();
				$('.product .pButtons a').removeClass('active');
			});
		}else{
			$('#characteristicsF').hide();
			$('.product .pButtons a').removeClass('active');
		}
	});
}

function resizeHandler(tgt, frm){
	var target = $(tgt);
	var form = $(frm);
	$(window).resize(function(){
		$('.product').css('z-index', 0);
		var window = form.find('.window');
		var prod = target.parent().parent();
		prod.css('position', 'relative');
		prod.css('z-index', 4);
		var pW = prod.width();
		var pH = prod.height();
		var marginPx = parseInt(prod.css('margin-right'), 10);
		var marginTop = 25;
		var prLeft = prod.offset().left;
		var prTop = prod.offset().top;
		pW = pW + marginPx*2 - 20;
		form.find('.rsb-container .pad').css('padding', '0 ' +(marginPx-9) + 'px  12px');
		pH = pH + 25;
		form.find('.rsb-container').width(pW);
		window.css({width:pW, height:pH});
		form.css({left: prLeft-marginPx, top:prTop-50});
	});
}
var counter = 0;
function actionsMain(){
	
	$('.actionsListMain li a').click(function(){
		$('.actionsContent').stop(true,true);
		if(!$(this).parent().hasClass('active')){
			var lastRel = $('.actionsListMain .active a').attr('rel');
			$('.actionsListMain li').removeClass('active');
			var rel = $(this).attr('rel');
			$(this).parent().addClass('active');
			if(IE7){
				$('.actionsContent').hide();
				$('.actionsContent[rel='+rel+']').show();
			}else{
				$('.actionsContent[rel='+lastRel+']').animate({opacity:0.1},500, function(){
					$('.actionsContent[rel='+lastRel+']').hide();
					$('.actionsContent[rel='+rel+']').show();
					$('.actionsContent[rel='+rel+']').css({opacity:0});
					$('.actionsContent[rel='+rel+']').animate({opacity:0.9},500);
				});
			}
		}
	});
	
	
	
	//Считаем высоту
	var maxHeight = 0;
	$('.actionsContent').each(function(){
		$(this).show();
		if($(this).height() > maxHeight){maxHeight = $(this).height();}
		$(this).hide();
	});
	var ulH = 0;
	$('.actionsListMain li').each(function(){
		if(!$(this).hasClass('first') && !$(this).hasClass('last')){
			ulH = ulH + $(this).outerHeight();
		}
	});
	if(maxHeight < 228){maxHeight = 228;}
	$('.actionsContent').height(maxHeight);
	$('.actionsMain').height(maxHeight+6);
	
	var liFH = (maxHeight - ulH)/2 - 11-18;
	$('.actionsListMain li.first').height(liFH);
	
	var tH = 0;
	var aC = 0;
	$('.actionsContent').each(function(){
		var mt = (($(this).height()-40) - $(this).find('.textContent').height())/2;
		
		if($(this).find('.h2Only').length){
			$(this).show();
			var $h2 = $(this).find('.h2Only');
			var ht = $(this).height()-40;
			if($h2.height() < ht){
				$h2.css('margin-top', (ht - $h2.height())/2);
			}
			$(this).hide();
		}
		/* $(this).find('.textContent').css({'margin-top': mt}); */
	});
	
	$('.actionsContent').show();
	$('.actionsContent').hide();
	$('.actionsContent:eq(0)').show();
	
	$(window).resize(function(){
		var maxHeight = 0;
		$('.actionsContent').css('height','auto');
		$('.actionsContent').find('.h2Only').css('margin-top', 0)
		$('.actionsContent').each(function(){
			var dblock = $(this).css('display');
			$(this).show();
			if($(this).height() > maxHeight){maxHeight = $(this).height();}
			if(dblock != 'none'){
				$(this).hide();
			}
		});
		
		$('.actionsContent').each(function(){
			if($(this).find('.h2Only').length){
				$(this).stop(true,true);
				var $h2 = $(this).find('.h2Only');
				var ht= $(this).height()-40;
				var dblock = $(this).css('display');
				$(this).show();
				if($h2.height() < ht){
					$h2.css('margin-top', (ht - $h2.height())/2);
				}
				if(dblock != 'none'){
					$(this).hide();
				}
			}
		});
		if(maxHeight < 228){maxHeight = 228;}
		$('.actionsContent').height(maxHeight);
		$('.actionsMain').height(maxHeight+6);
		ulH = 0;
		$('.actionsListMain li').each(function(){
			if(!$(this).hasClass('first') && !$(this).hasClass('last')){
				ulH = ulH + $(this).outerHeight();
			}
		});
		
		var liFH = (maxHeight - ulH)/2 - 10;
		$('.actionsListMain li.first').height(liFH);
	});
	
	
	//Ставим таймеры
	$('.actionsMain').everyTime(10000, function(){
		var lastRel = $('.actionsListMain .active a').attr('rel');
		var $li = $('.actionsListMain .active');
		var $next;
		$('.actionsListMain li').removeClass('active');
		
		if(!$li.next('li').hasClass('last')){
			$next = $li.next('li');
		}else{
			$next = $('.actionsListMain li:eq(1)');
		}
		$next.addClass('active');
		var rel = $next.find('a').attr('rel');
		if(IE7){
			$('.actionsContent').hide();
			$('.actionsContent[rel='+$next.find('a').attr('rel')+']').show();
		}else{
			$('.actionsContent[rel='+lastRel+']').animate({opacity:0.1}, 500, function(){
				$('.actionsContent[rel='+lastRel+']').hide();
				$('.actionsContent[rel='+rel+']').show();
				$('.actionsContent[rel='+rel+']').css({opacity:0});
				$('.actionsContent[rel='+rel+']').animate({opacity:0.9}, 500);
			});
		}
	});
	
	$('.actionsMain').hover(function(){
		$(this).stopTime();
	},function(){
		$('.actionsMain').everyTime(10000, function(){
			var lastRel = $('.actionsListMain .active a').attr('rel');
			var $li = $('.actionsListMain .active');
			var $next;
			$('.actionsListMain li').removeClass('active');
			
			if(!$li.next('li').hasClass('last')){
				$next = $li.next('li');
			}else{
				$next = $('.actionsListMain li:eq(1)');
			}
			$next.addClass('active');
			var rel = $next.find('a').attr('rel');
			if(IE7){
				$('.actionsContent').hide();
				$('.actionsContent[rel='+$next.find('a').attr('rel')+']').show();
			}else{
				$('.actionsContent[rel='+lastRel+']').animate({opacity:0.1},500, function(){
					$('.actionsContent[rel='+lastRel+']').hide();
					$('.actionsContent[rel='+rel+']').show();
					$('.actionsContent[rel='+rel+']').css({opacity:0});
					$('.actionsContent[rel='+rel+']').animate({opacity:0.9}, 500);
				});
			}
		});
	});
}



/*Отправка форм*/
$(document).ready(function(){
	$('#creditRequestForm button').click(function(event){
		event.preventDefault();
		var error = 0;
		
		$('#rQError').removeClass('error');
		$('#rName').parent().removeClass('inpCError');
		$('#rPhone').parent().removeClass('inpCError');
		$('#creditRequestForm input.chBox').parent().removeClass('error');
		$('#rSumm').parent().removeClass('inpCError');
		$('#rFirstFee').parent().removeClass('inpCError');
		$('#rTime').parent().removeClass('inpCError');
		$('#rCharge').parent().removeClass('inpCError');
		$('#rIncome').parent().removeClass('inpCError');
		var chChecked = 0;
		$('#creditRequestForm input.chBox').each(function(){
			if($(this).attr('checked') == true){chChecked++;}
		});
		/* if(chChecked == 0){
			error++;
			$('#creditRequestForm input.chBox').parent().addClass('error');
		} */
		if($('#rName').val() == ''){
			error++;
			$('#rName').parent().addClass('inpCError');
		}
		if($('#rPhone').val() == ''){
			error++;
			$('#rPhone').parent().addClass('inpCError');
		}else{
			if(!$('#rPhone').val().match(/((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]/)){
				error++;
				$('#rPhone').parent().addClass('inpCError');
				alert('Телефон указан не правильно');
			}
		}
		if($('#rSumm').val() == ''){
			error++;
			$('#rSumm').parent().addClass('inpCError');
		}
		if($('#rFirstFee').val() == ''){
			error++;
			$('#rFirstFee').parent().addClass('inpCError');
		}
		
		
		
		
		if(error == 0){
			$('#rQError').hide();
			$('#rQWait').show();
			$('#creditRequestForm button').hide();
			
			$.post("/sendmail/index.php", $('form#creditRequestForm').serialize(),
			 function(data){
				//alert(data);
			   if(data == '1'){
					$('#rQError').hide();
					$('#rQWait').hide();
					$('#rQSuccess').show();
					
					$('#rName').val('');
					$('#rPhone').val('');
					$('#rSumm').val('');
					$('#rFirstFee').val('');
					$('#rCharge').val('');
					$('#rIncome').val('');
					$(this).oneTime(7000, function(){
						$('#rQSuccess').hide();
						$('form#creditRequestForm button').show();
					});
			   }else{
					$('#rQError').html('К сожалению произошла ошибка, попробуйте обовить страницу и отправить заявку еще раз');
					$('#rQError').show();
					$(this).oneTime(10000, function(){
						$('#rQError').html('Все поля обязательны для заполнения');
						$('form#feedbackForm button').show();
					});
			   }
			 }
			);
		}else{
			$('#rQError').addClass('error');
		}
		return false;
	});
	
	
	$('#feedbackForm button').click(function(){
		var error = 0;
		$('#uName').parent().removeClass('inpCError');
		$('#uCont').parent().removeClass('inpCError');
		$('#uQuest').parent().removeClass('inpCError');
		$('#aQError').removeClass('error');
		if($('#uName').val() == ''){
			error = error+1;
			$('#uName').parent().addClass('inpCError');
		}
		if($('#uCont').val() == ''){
			error = error+1;
			$('#uCont').parent().addClass('inpCError');
		}
		if($('#uQuest').val() == ''){
			error = error+1;
			$('#uQuest').parent().addClass('inpCError');
		}
		if(error == 0){
			$('#aQError').hide();
			$('#aQWait').show();
			$('#feedbackForm button').hide();
			
			$.post("/sendmail/index.php", $('form#feedbackForm').serialize(),
			 function(data){
			   if(data == '1'){
					$('#aQWait').hide();
					$('#aQSuccess').show();
					$(this).oneTime(3000, function(){
						$('#aQWait').hide();
						$('#aQError').show();
						$('#aQSuccess').hide();
						$('form#feedbackForm button').show();
						$('#askQuestion').hide();
						$('#dark').hide();
					});
			   }else{
					$('#aQError').html('Произошла ошибка, попробуйте обновить страницу и отправить форму еще раз');
					$(this).oneTime(10000, function(){
						$('aQError').hide();
						$('aQError').html('Все поля обязательны для заполнения');
						$('aQError').show();
						$('form#feedbackForm button').show();
					});
			   }
			 }
			);
		}else{
			$('#aQError').addClass('error');
		}
		return false;
	});
});

$(document).ready(function(){
	if($.browser.msie && $.browser.version.substr(0,1)<7){
		showIe6Alert();
	}
});

function showIe6Alert(){
	$('body').append('<div id="dark2"></div>');
	$('body').append('<div class="popupIE6"><div class="pad"><h2>Внимание! Вы используйте устаревший браузер Internet&nbsp;Explorer&nbsp;6</h2><p>Данный сайт построен на передовых, современных технологиях и не поддерживает Internet Explorer 6-ой версии.</p> <p>Настоятельно Вам рекомендуем выбрать и установить любой из современных браузеров. Это бесплатно и займет всего несколько минут.</p><ul><li><a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer</a></li><li><a href="http://www.opera.com/download/">Opera Browser</a></li><li><a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a></li><li><a href="http://www.google.com/chrome">Google Chrome</a></li></ul></div><div class="close"><img src="/pics/i/close.gif" alt="Закрыть" /></div></div>');
	$('#dark2').show();
	$('#dark2').click(function(){
		$('.popupIE6').hide();
		$('#dark2').hide();
	});
	$('.popupIE6 .close').click(function(){
		$('.popupIE6').hide();
		$('#dark2').hide();
	});
}

function credLink(){
	$('#gotoCredReq').click(function(){
		var ot = $('a[name=credReq]').offset().top;
		$('html').animate({scrollTop:ot},1300);
		
		return false;
	});
}

function buttonsHelpers(){
	$('a.pb-nal').attr('title', 'Наличие в магазинах');
	$('a.pb-comp').attr('title', 'Добавить в сравнение');
	$('a.pb-char').attr('title', 'Характеристики товара');
}

function compareOverflow(){
	if($('.compareTableContaier').width() >= $('.compareProducts').width()){
		$('.compareTableContaier').css('overflow-x', 'hidden');
	}else{
		$('.compareTableContaier').css('overflow-x', 'scroll');
	}
	
	$(window).resize(function(){
		if($('.compareTableContaier').width() >= $('.compareProducts').width()){
		$('.compareTableContaier').css('overflow-x', 'hidden');
		}else{
			$('.compareTableContaier').css('overflow-x', 'scroll');
		}
	});
}
