$(function(){	
	showCounter();
	windowFunc();
	$(window).resize(function() {
		topHeight();
		windowFunc();
	});
	
	if (jQuery.browser.msie == true){
		ieFunc();
	}
	$('a.imgZoom').fancybox();
});
window.onload = function(){
	topHeight();
	$(window).resize(function() {
		topHeight();
	});
	
	// SCROLL ->
	if($('.scroll').length){
	sc_height = $('.scrollList').height()
	sc_width = $('.scrollList').width()
	li_scrol = Math.floor(sc_width*0.23);
	li_width = Math.floor(sc_width*0.21);
	li_padding = Math.floor(sc_width*0.02);
	sc_last = $('.scrollList li.yes:last').position().left;
	li_width = $('.scrollList li.yes:last').width()
	li_last = Math.floor(sc_width)-Math.floor(sc_last) - Math.floor(li_width);
	}
	// close
	
}

function topHeight(){
	if($('#a').length){
		ftop = $('#a').offset().top;
		$('body').css('background', '#fff')
		$('.homBG').css({'height':ftop + 20});
	}
}

function windowFunc(){
	var body_width = $('body').width();
	
	if (body_width <= 1350) {
		$('#empty').append('<div id="emp1">'+$('#Tehnika').html()+'</div><div id="emp2">'+$('#manufacturers').html()+'</div>');
		$('#empty').css('padding-bottom','40px');
		$('#manufacturers').empty();
		$('#Tehnika').empty();
		$('.homeAnonsBlock').hide();
		$('.hometextblock').stop().animate({width: "100%"})

	}else{
		// add content
		$('#Tehnika').append($('#emp1').html());
		$('#manufacturers').append($('#emp2').html());
		// clear container
		$('#emp1').empty();
		$('#emp2').empty()
		$('#empty').empty();
		// clear padding;
		$('#empty').css('padding-bottom','0');
		
		$('.homeAnonsBlock').show();
		$('.hometextblock').show().stop().animate({width: "75%"});
	}

	if(body_width <= 1200){
		$('.main').css({'width': '100%', 'margin':0});		
		
		if(body_width <= 1024){
			$('.main').css({'minWidth': '1000px', 'margin': '0 auto'});
		}else{		
			$('.main').css({'width': '100%', 'margin':0});
		}
		
	}else{
		$('.main').css({'width': '90%', 'margin': '0 0 0 5%'});
	}
	
}

function showCounter(){
	document.getElementById('footerCounter').innerHTML = '<a href="http://www.liveinternet.ru/click" '+'target=_blank><img src="http://counter.yadro.ru/hit?t14.1;r'+escape(document.referrer)+((typeof(screen)=='undefined')?'':';s'+screen.width+'*'+screen.height+'*'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+';'+Math.random()+'" alt="liveinternet.ru: iieacaii ?enei oeoia ca 24 ?ana, iinaoeoaeae ca 24 ?ana e ca naaiai\y" '+'border=0 width=88 height=31></a>';
}

function scroll(position){
	$('.scrollList').attr('style', 'height: ' + sc_height + 'px;');
	
	if(position == 0){
		$('.scrollList li.yes:first').animate({'margin-left': '-'+li_scrol},500, function(){
			non = $('.scrollList li.yes:first').html()
			$('.scrollList li.yes:first').remove()
			$('.scrollList').append('<li class="non">'+non+'</li>')
		});
		$('.scrollList li.non:first').attr({'class': 'yes', 'style': 'width: '+ li_width +'px; padding: 0 '+ li_padding+'px; position:absolute; right: -'+li_scrol+'px;top:0'});
		$('.scrollList li.yes:last').animate({'right': 0},500, function(){
				$('.scrollList li.yes:last').removeAttr('style');
		});
		
	}
	
	
	
	if(position == 1){
		$('.scrollList li.yes').each(function(i, val){
			left = $(val).position().left;
			$(val).attr('style', 'top:0; left:'+left);
		});
		yes = $('.scrollList li.non:last').html();
		$('.scrollList li.non:last').remove();
		
		$('.scrollList').prepend('<li class="yes" style="position:absolute; top:0; left:-253px;">' + yes + '</li>');
		
		$('.scrollList li.yes').css('position', 'absolute').animate({left: '+=' + li_scrol},500)

		setTimeout(function(){
			$('.scrollList li.yes:last').attr('class', 'non').removeAttr('style');
			//$('.scrollList li.non:first').removeAttr('style');
			$('.scrollList li.yes').removeAttr('style');
		},500);
	}

}
function loadPage(t, name){
	if(!$(t).hasClass('cur')){
		$('.owerBlock').hide();
		$('.menuCAR li').removeClass('cur');
		$(t).addClass('cur');
		$('.'+name).show();
	}
}

/*
function leftScroll (){
	$('.scrollList li.yes:first').hide("slow", function(){ 
		li = $('.scrollList li.yes:first').html();
		$('.scrollList li.yes:first').remove();
		$('.scrollList').append('<li class="non">'+li+'</li>');
		$('.scrollList li.non:first').addClass('yes').removeClass('non');
		topHeight();
	})
	
}
function rightScroll (){
	$('.scrollList li.yes:last').hide()
	li = $('.scrollList li.yes:last').html();
	new_li = $('.scrollList li.non:last').html();
	$('.scrollList li.non:last').remove();
	$('.scrollList li.yes:last').remove();
	$('.scrollList').append('<li class="non">'+li+'</li>');
	$('.scrollList').prepend('<li class="yes slow" style="display: none">'+new_li+'</li>');
	$('.scrollList li.slow:last').show("slow").removeClass("slow")
	topHeight();
	
	
	$('.scrollList li.yes:last').hide("slow", function(){ 
		li = $('.scrollList li.yes:last').html();
		new_li = $('.scrollList li.non:last').html();
		$('.scrollList li.non:last').remove();
		$('.scrollList li.yes:last').remove();
		$('.scrollList').append('<li class="non">'+li+'</li>');
		$('.scrollList').prepend('<li class="yes">'+new_li+'</li>');
		topHeight();
	})

}*/









