var logo = 'none';
var lang_id = 'ru';

var menu = {
	about_ru:'О компании',
	about_en:'About us',
	map_ru:'География поставок',
	map_en:'Supply chain',
	contacts_ru:'Контакты',
	contacts_en:' Contacts'
}

var footer = {
	copy_ru:'&copy; 2011 Холдинг &laquo;Белорусские обои&raquo;',
	copy_en:'&copy; 2011 Holding &quot;Belorusskie oboi&quot;',
	info_ru:'Контактная информация',
	info_en:'Contact Information',
	csf_ru:'Сделано CSFactory',
	csf_en:'Made by CSFactory'
}

var css_a = {
	logo_beloboi: {top:'60px',left:'90px',width:'150px',height:'127px'},
	logo_gomeloboi: {top:'60px',left:'381px',width:'204px',height:'127px'},
	'logo_geroy-truda': {top:'64px',left:'697px',width:'214px',height:'131px'}
}

var css_na = {
	logo_beloboi: {top:'65px',left:'95px',width:'145px',height:'122px'},
	logo_gomeloboi: {top:'65px',left:'386px',width:'199px',height:'122px'},
	'logo_geroy-truda': {top:'69px',left:'702px',width:'209px',height:'126px'}
}

// Replacement
function replacement(list_id, lang_id){
	//logo = '';
	var page = list_id+'_'+lang_id+'.html';
	var text_id = 'text';
	text_id = $('.text-block:visible').attr('id');
	
	slide(text_id);
	if(list_id == 'map' || list_id == 'contacts' || (list_id == 'about' && logo == 'none')){
		text_id = 'text';
	}
	$.ajax({
		url:page,
		dataType: 'html',
		success:function(data){
			setTimeout(function(){
				$('#content').html(data);
				if(logo!='none'){
					$('#'+logo).attr('src','images/'+logo+'_'+lang_id+'_a.png');
					$('#'+logo).css({top:css_a[logo].top, left:css_a[logo].left, width:css_a[logo].width, height:css_a[logo].height});
				}
				slide(text_id);
				color(text_id);
			},2000);
		}
	});

}
// Color
function color(id){
	var color = {
		beloboi:'color-pink',
		gomeloboi:'color-blue',
		'geroy-truda':'color-green',
		text:''
	}
	$(document.body).attr('class',color[id]);
}

// Company
function company(e){
	var id = $(e.target).attr('class');
	logo = 'logo_'+id;
	
	$('#main-block').children().each(function(){
		if(this.id == logo){
			$('#'+logo).attr('src','images/'+logo+'_'+lang_id+'_a.png');
			$('#'+logo).css({top:css_a[logo].top, left:css_a[logo].left, width:css_a[logo].width, height:css_a[logo].height});
		}else{
			this.src = this.src.replace('_a', '_na');
			$('#'+this.id).css({top:css_na[this.id].top, left:css_na[this.id].left, width:css_na[this.id].width, height:css_na[this.id].height});
		}
	});
	
	//$('.text-block:visible').slideUp(1000);
	if( $('#'+id).is(':hidden') ){
		$('.text-block:visible').animate({'top': '0'}, 1000, function(){
			$('.text-block:visible').hide();
			$('#'+id).show();
			$('#'+id).animate({'top': '258px'}, 1000);
		});
		color(id);
	}
}

// Slide
function slide(){
	var id = 'text';
	var mainBlock = 'main-block';
	
	if(arguments.length){
		id = arguments[0];
	}
	
	if( $('#' + mainBlock).is(':hidden')) {
		$('#' + mainBlock).fadeIn(1000, function(){
			
			$('#'+id).show();
			$('#'+id).animate({'top': '258px'}, 1000);
			
		});
	}else{
		if($('#'+id).is(':visible')){
			$('#'+id).animate({'top': '0'}, 1000, function(){
				$('#'+id).hide();
				$('#' + mainBlock).fadeOut(1000);
			});
		}
	
	}
}
// Redy
$(document).ready(function(){
	var list_id = 'about';
	
	
	slide();
	
	$('#lang').click(function(e){
		if ($(e.target).parent().is('div')){
			var lang = $(e.target);
			lang_id = lang.attr('id');
			lang.siblings().removeClass('active');
			lang.addClass('active');
			replacement(list_id, lang_id);
			$('#copy').html(footer['copy_'+lang_id]);
			$('#info').html(footer['info_'+lang_id]);
			$('#csf').html(footer['csf_'+lang_id]);
			$('#csf').html(footer['csf_'+lang_id]);
			$('#about').html(menu['about_'+lang_id]);
			$('#map').html(menu['map_'+lang_id]);
			$('#contacts').html(menu['contacts_'+lang_id]);
			$('#mainlogo').css('background','url(images/logo_'+lang_id+'-big.png) 50% 0 no-repeat');
		}
		return false;
	});
	
	$('#menu').click(function(e){		
		if ($(e.target).parent().is('div')){
			if($(e.target).attr('id') != list_id){
				var list = $(e.target);
				list_id = list.attr('id');
				list.siblings().removeClass('active');
				list.addClass('active');
				logo = 'none';
				replacement(list_id, lang_id);
			}
		}
		return false;
	});
	
	$('#info').click(function(){
		$('#menu').children().removeClass('active');
		$('#contacts').addClass('active');
		logo = 'none';
		replacement('contacts', lang_id);
		
		return false;
	});
	
	$('#mainlogo').click(function(){
		$('#menu').children().removeClass('active');
		$('#about').addClass('active');
		logo = 'none';
		replacement('about', lang_id);
		
		return false;
	});
	
});
