// Получить ширину клиентской части
function getClientWidth() {
    return (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth)); 
}

function sorting(s){
	$('span:not(.'+s+')').animate({'opacity':'hide'},100,function(){
		$('span.'+s).animate({'opacity':'show'},100);
	});
	$('#a_'+s).addClass('enabled');
	$('a:not(#a_'+s+')').removeClass('enabled');
}

function showall()
{
	$('span').animate({'opacity':'show'},600);
}

$(document).ready (function () {
	// Страница - О нас
	$("#linkImages a").click(function () {
		$("#linkImages a.current").attr("class"," ");
		var linkID = $(this).attr("id");
		$("#photoImages div:visible").fadeOut(400, function () {
			$("#photoImages div#"+linkID+"_i").fadeIn(400, function () {
				$('#'+linkID).attr("class","current");
			});
		});	
	});
	// Окно контактов -------------------------
	src=location.href;
	if (src.match(/.*#contact/i)==location.href) {
	    $('#body_fill').css ({'height':$(document).height()});
		$('#body_fill').animate({opacity:'show'},300,function () {
			$('#contact_window').animate({opacity:'show'},300);
		});
	}
	$("#contact_window_show").click(function () {
		$('#body_fill').css ({'height':$(document).height()});
		$('#body_fill').animate({opacity:'show'},300,function () {
			$('#contact_window').animate({opacity:'show'},300);
		});
	});
	$("#contact_window_hide").click(function () {
		$('#contact_window').animate({opacity:'hide'},300,function () {
			$('#body_fill').animate({opacity:'hide'},300);
		});
	});
	// Страница отзывов ---------------------
	i=0;
	curel=1;
	if (getClientWidth()>1100) onpage=3;
	else onpage=2;
	var el_count;
	var cont_id;
	$('#our-list .review').each(function (index, domEle) {
		i++;
		if (i%2==1) {
			cont_id='re_container_'+((i+1) / 2);
			$('#our-list #reviews').append('<div class="re_container" id="'+cont_id+'"></div>');
		}
		$(this).appendTo('#'+cont_id);
		$(this).show();
		el_count=(i+1) / 2;
	});
	j=0;
	if (el_count>onpage) $("#scroll-right").animate({opacity:'show'},500);
	$('#our-list .re_container').each(function (index, domEle) {
		if (j<onpage) {
			j++;
			$(this).animate({opacity:'show'},1000);
		} else return false;
	});
	$("#scroll-right").click(function () {
		if (el_count>curel+onpage-1) {
			$('#our-list #reviews #re_container_'+curel).animate({width:'hide'},500);
			curel++;
			$('#our-list #reviews #re_container_'+(curel+onpage-1)).animate({width:'show'},500);
		} 
		if (el_count<curel+onpage) $("#scroll-right").animate({opacity:'hide'},500);
		if (curel>1) $("#scroll-left").animate({opacity:'show'},500);
	});
	$("#scroll-left").click(function () {
		if (curel>1) {
			$('#our-list #reviews #re_container_'+(curel+onpage-1)).animate({width:'hide'},500);
			curel--;
			$('#our-list #reviews #re_container_'+curel).animate({width:'show'},500);
		} 
		if (curel==1) $("#scroll-left").animate({opacity:'hide'},500);
		if (el_count>=curel+onpage) $("#scroll-right").animate({opacity:'show'},500);
	});
});


