/**
 * @author Sergey Chikuyonok (serge.che@gmail.com)
 * @link http://chikuyonok.ru
 */$(function(){
	var page = $('#page'),
		imagery = $('#imagery-wrap'),
		words = $('#words-wrap'),
		anim_opts = {
			time: 1,
			transition: 'easeinoutcubic',
			namespace: 'page-switch'
		};
	
	jTweener.addNSAction({
		onComplete: function() {
			resetSection(imagery);
			resetSection(words);
			page.css('height', '').removeClass('fixed');
			
			var body = $('body');
			if (is_words) {
				$.cookie('page-type', 'words', {expires: 300, path: '/'});
				body.removeClass('type-imagery').addClass('type-words')
			}
			else {
				$.cookie('page-type', 'images', {expires: 300, path: '/'});
				body.removeClass('type-words').addClass('type-imagery')
			}
			
			body.css('background-color', '');
		}
	}, anim_opts.namespace);	
	
	function fixHeight(elem) {
		elem.css('height', elem[0].offsetHeight);
	}
	
	function resetSection(section) {
		$(section).css({
			position: '',
			left: '',
			height: ''
		}).removeClass('fixed');
		
	}
	
	function switchToWords() {
		var w = page[0].offsetWidth;
		
		fixHeight(page);
		fixHeight(imagery);
		
		page.addClass('fixed');
		words.css('height', 'auto');
		
		$t(imagery.css({position: 'absolute'}), anim_opts)
			.tween({left: w});
		
		$t(page, anim_opts).tween({height: words[0].offsetHeight});
		
		$t(words.css({position: 'absolute', left: -w, height: 'auto'}), anim_opts)
			.tween({left: 0});
		
		$t(document.body, anim_opts).tween({backgroundColor: '#efeff3'});
	}
	
	function switchToImagery() {
		var w = page[0].offsetWidth;
		
		fixHeight(page);
		fixHeight(words);
		
		page.addClass('fixed');
		imagery.css('height', 'auto');
		
		$t(words.css({position: 'absolute'}), anim_opts)
			.tween({left: -w});
		
		$t(page, anim_opts).tween({height: imagery[0].offsetHeight});
		
		$t(imagery.css({position: 'absolute', left: w, height: 'auto'}), anim_opts)
			.tween({left: 0});
		
		$t(document.body, anim_opts)
			.tween({backgroundColor: '#000'});
	}
	
	var is_words = !$('body').hasClass('type-imagery');
	function toggleState() {
		if (is_words)
			switchToImagery();
		else
			switchToWords();
			
		is_words = !is_words;
	}
	
	$('.page-switcher, .calendar-href').click(toggleState);
	
});

$(function(){
	$('#imagery .map-logo').click(function(){
		$('#imagery .map-zoom').toggle();
	});
	
	
	$('.tours').each(function(){
		var content = $(this).find('.content');
		
		$('.pseudo-href', this).click(function(){
			content.slideToggle(300);
		});
	});
	
	
	// login form
	var form = $('.user-auth-login-form');
	$('.user-auth-action .login').click(function(/* Event */ evt) {
		form.show();
		$(document).one('click', function(){
			form.hide();
		});
		
		evt.preventDefault();
		return false;
	});
	
	form.click(function(/* Event */ evt) {
		evt.stopPropagation();
	});
	
	
	
});


