if(!window.Lang) {
	
	/**
	 *	ru Language
	 */
	
	var Lang = {
		query:'Франшиза',
		email:'Адрес вашей эл. почты',
		invoice:'Введите номер накладной',
		centers:'Ваш адрес (город, улица, дом)',
	}
	
}


$(document).ready(function() {
	TopMenu();
	CentersMenu();
	getItemDetails();
	SelectMbeCity();
	FooterForms();
	FooterEsp();
	
	$('.ui-state-default').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);
	$('.ui-state-hover').hover(
		function() { $(this).addClass('ui-state-default'); },
		function() { $(this).removeClass('ui-state-default'); }
	);
	
});


$(window).resize(function() {
	TopMenu();
	CentersMenu();
	FooterEsp();
});

/**
 * Верхнее навигационное меню
 */

function TopMenu() {
		
	$('#topmenu ul.navigation li:has(ul)').hover(
		function() { $(this).find('ul:first').show(); },
		function() { $(this).find('ul:first').hide(); }
	); 
	     
}

/**
 * Меню центров MBE
 */

function CentersMenu() {
	
	var Left = -1;
	var Zindex = 100;
		
	$('#centersmenu ul.navigation li').each(function(i) { 
		var Width = $(this).width();
		$(this).css("left",Left).css("z-index",Zindex--);
		Left = Width+Left+10;
	}); 
	     
}

/**
 * Обработка фокуса на формах поиска, подписки и трекинга
 */

function FooterForms() {
	
	var Color1 = "C3C3C3";
	var Color2 = "4A4A4A";
	
	var Elements = [
		{element:'#footer #query',text:Lang.query},
		{element:'#footer #email',text:Lang.email},
		{element:'#maincontent #invoicecode',text:Lang.invoice},
		{element:'#footer #invoicecode',text:Lang.invoice},
		{element:'#centers input[name=cityname]',text:Lang.centers}
	];
	
	$(Elements).each(function(i,v){
		var Element = $(v.element);
		if(Element.val()=='') {
			Element.val(v.text).css("color","#"+Color1);
			Element.focus(function() { if($(this).val()==v.text) $(this).val('').css("color","#"+Color2); });
			Element.blur(function() { if($(this).val()=='') $(this).val(v.text).css("color","#"+Color1); });
		}
	});
	
}

/**
 * Меняет размер распорки над футером
 */

function FooterEsp() {
	
	$("#footeresp").css("height",$("#footer").height()+50);
	
}

/**
 * Обрабатываем смену значения в селекте выбора города центров MBE
 */

function SelectMbeCity() {
	
	$("#centers .cities select").change(function(){
		if($(this).val()!='') location.href = $(this).val();
	});
	
}

/**
 * Загружаем полное описание товара
 */

function getItemDetails() {
	
	$(".items .title a").toggle(
	
		function(){
			
			var Container = $(this).parents("li:first").find(".txt");
			
			if(Container.html()=='') {
				
				$.getJSON($(this).attr("href"),function(data){
					Container.html(data.resourcetxt);
				});
			
			}
			
			Container.show();
			
			return false;
			
		},
		
		function(){
			
			$(this).parents("li:first").find(".txt").hide();
			
			return false;
			
		}
	
	);
	
}
