// -------------------------------------------------------------------
// Главная страница - Верхнее меню -----------------------------------
// -------------------------------------------------------------------
var active_pan;
zan_display=true;
zan_blocked=false;
function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
};
function check_mail(str) {
	if (str.replace(/^[\w_\.-]+@[\w_-]+\.[\w_\.-]+[a-z]$/i,"")!=str) return true;
	else return false;
};
function check_phone(str) {
	if (str.replace(/^[+]?[0-9- ]{5,12}$/i,"")!=str) return true;
	else return false;
}
$(document).ready (function () {
	$('#submenu li a').mouseover(function () {
		if (!$(this).hasClass('active')) {
			var id=$(this).attr('id');
			$('#'+id+'_cur').css('visibility','visible');
		};
		}).mouseout(function () {
			if (!$(this).hasClass('active')) {
				var id=$(this).attr('id');
				$('#'+id+'_cur').css('visibility','hidden');
			};
		}).click(function () {
			var id=$(this).attr('id');
			$('#submenu li a:not(#'+id+')').removeClass('active');
			$('#submenu li span:not(#'+id+'_cur)').css('visibility','hidden');
			$(this).addClass('active');
			$('#'+id+'_cur').css('visibility','visible');
			
			$('#sliding').animate ({'width':'hide'},300, function () {
				if (id=='li1') { 
					$('#sph').html('<a href="#">Графический дизайн</a>');
				}
				if (id=='li2') {
					$('#sph').html('<a href="#">Рекламное сопровождение</a>');
				}
				if (id=='li3') {
					$('#sph').html('<a href="#">Фирменный стиль, логотип</a>');
				}
				if (id=='li4') {
					$('#sph').html('<a href="#">Продвижение сайтов (SEO)</a>');
				}
				if (id=='li5') {
					$('#sph').html('<a href="#">Разработка игр</a>');
				}
				if (id=='li6') {
					$('#sph').html('<a href="#">Директ реклама</a>');
				}
				
				$('#slide-text').html($('#slide-text_'+id).html());
				
				$('#spicon').attr('src',"/hostcmsfiles/images/pub/"+id+"_spicon.jpg");
				$('#sliding').animate ({'width':'show'},300);
				$('#go-form').hide(0);
				$('#go-button').show();
				$('#slide-text').show(0);
			});
		});
	$('#centralpan .cell_pans').bind("mouseenter",function(){
			vid=$(this).attr('id');
			$('#'+vid+' img').animate({'opacity':'hide'},50);
		}).bind("mouseleave",function(){
			vid=$(this).attr('id');
			if (vid!='pan'+active_pan) {
				$('#'+vid+' img').animate({'opacity':'show'},50);
			}
		});
	$('#go-button').bind("mouseenter",function(){
			$('#go-button img').css({'visibility':'hidden'});
		}).bind("mouseleave",function(){
			$('#go-button img').css({'visibility':'visible'});
		}).click(function () {
			$('#slide-text').animate({'height':'hide'},300);
			$('#go-form').animate({'height':'show'},300);
			$('#go-button').animate({'height':'hide'},300);
		});
	$('#go-submit').click(function () {
			var error=false;
			if (trim($('#go-form-name').val())=='') {
				$('#go-form-name').css({'background-color':'#fcc'});
				error=true;
			} else $('#go-form-name').css({'background-color':'#cfc'});
			if (!check_phone($('#go-form-phone').val())) {
				$('#go-form-phone').css({'background-color':'#fcc'});
				error=true;
			} else $('#go-form-phone').css({'background-color':'#cfc'});
			if (!check_mail($('#go-form-email').val())) {
				$('#go-form-email').css({'background-color':'#fcc'});
				error=true;
			} else $('#go-form-email').css({'background-color':'#cfc'});
			if (!error) $('#go-form-action').submit();
		});
	$('#no_words').click (function() {
		if (!zan_blocked) {
			if (zan_display) {
				ChangePreWidthBack();
				zan_display=false;
			}
			else {
				ChangePreWidth();
				zan_display=true;
			}
		}
	});
	mainPageInit();
});
// -------------------------------------------------------------------
// Главная страница - Плашки -----------------------------------------
// -------------------------------------------------------------------

// Массив адресов загружаемых картинок
var loadImages = new Array(
	'/hostcmsfiles/images/pub/apicon1.gif',
	'/hostcmsfiles/images/pub/apicon2.gif',
	'/hostcmsfiles/images/pub/npicon1.gif',
	'/hostcmsfiles/images/pub/npicon2.gif',
	'/hostcmsfiles/images/pub/npicon3.gif',
	'/hostcmsfiles/images/pub/border1.gif',
	'/hostcmsfiles/images/pub/li6.gif',
	'/hostcmsfiles/images/pub/r_m_icon.gif',
	'/hostcmsfiles/images/pub/li1_spicon.jpg',
	'/hostcmsfiles/images/pub/li2_spicon.jpg',
	'/hostcmsfiles/images/pub/li3_spicon.jpg',
	'/hostcmsfiles/images/pub/li4_spicon.jpg',
	'/hostcmsfiles/images/pub/li5_spicon.jpg',
	'/hostcmsfiles/images/pub/li6_spicon.jpg',
	'/hostcmsfiles/images/pub/submenu_h.gif',
	'/hostcmsfiles/images/pub/work_img.gif'
	);

// Массив загруженных картинок
var loadedImages  = new Array();

// Событие при изменении размера клиентской части
window.onresize=ChangeWidth;
	
// Инициализация главной страницы
function mainPageInit() {
	ChangeWidth();
	LoadingImages();
	ChangePreWidth();
}

// Анимация исчезновения занавеса
function ChangePreWidth() {
	zan_blocked=true;
	$('#preloader').animate({'width':'hide'},1000, function () {
		$('#content').css({'marginTop':0});
		$('#centralpan').animate({'marginLeft':-12},200);
		$('#no_words').fadeOut(200,function(){
			$('#no_words').html('нет слов');
			$('#no_words').fadeIn(200);
		});
		zan_blocked=false;
	});
}
// Анимация появления занавеса
function ChangePreWidthBack() {
	zan_blocked=true;
	$('#content').css({'marginTop':'-725px'});
	$('#centralpan').animate({'marginLeft':0},200);
	$('#preloader').animate({'width':'show'},1000,function(){
		$('#no_words').fadeOut(200,function(){
			$('#no_words').html('одни эмоции');
			$('#no_words').fadeIn(200);
		});
		zan_blocked=false;
	});
}

// Функция загрузки изображений
function LoadingImages() {
	for (i = 0; i < loadImages.length; i++) {
		loadedImages[i] = new Image();
		loadedImages[i].src = loadImages[i];
	}
} 

// Инициализация параметров ширины плашки
function ChangeWidth() {
	// Определение ширины занавеса
	prewidth=getClientWidth()-140;
	$('#preloader').width(prewidth);
	ccfw=prewidth-60;
	if (ccfw>1220) ccfw=1220;
	$('#centralpan').width(ccfw+110);
	// Определение ширины и параметров плашек
	if (ccfw<1000) {
		$('.cell.last').hide();
		$('.cell').css({'paddingLeft': 7}).css({'padding-right': 7});
	}
	else if (ccfw<1200) {
		$('.cell.last').hide();
		$('.cell').css({'paddingLeft': ((ccfw)/25)}).css({'padding-right': ((ccfw)/25)});
	}
	else {
		$('.cell.last').show();
		$('.cell').css({'paddingLeft': 5}).css({'padding-right': 5});
		$('.cell.first').css({'paddingLeft': 60});
	}
	slide_ccp(4);
}

// Смена активной плашки
function slide_ccp(x)
{
	if (active_pan!=x) {
		active_pan=x;
		$('.cells_container:not(#cc'+x+')').animate({'width':0},500);
		$('#cc'+x).animate({'width':ccfw},500);
		$('.cell_pans:not(#pan'+x+') img').animate({'opacity':'show'},50);
		$('#pan'+x+' img').animate({'opacity':'hide'},50);
	}
}
// -------------------------------------------------------------------
// конец - Главная страница ------------------------------------------
// -------------------------------------------------------------------
