// JavaScript Document
function flapLeftForward() {
	
	var flapLeftPos = $('#flapLeft').position();
	var flapRightPos = $('#flapRight').position();
	
	if (flapLeftPos.left > -300 && flapRightPos.left < 1000) $('#flapLeft').animate({ left : '-=555px' });
	else if (flapRightPos.left > 1000) $('#flapRight').animate({ right : '+=555px' }, function(){ flapLeftForward(); });
	
}
function flapRightForward() {
	
	var flapLeftPos = $('#flapLeft').position();
	var flapRightPos = $('#flapRight').position();
	
	if (flapRightPos.left < 1000 && flapLeftPos.left > -300) $('#flapRight').animate({ right : '-=555px' });
	else if (flapLeftPos.left < -300) $('#flapLeft').animate({ left : '+=555px' }, function(){ flapRightForward(); });
	
}
function flapRightBack() {
	
	var flapLeftPos = $('#flapLeft').position();
	var flapRightPos = $('#flapRight').position();
	
	if (flapRightPos.left > 1000) $('#flapRight').animate({ right : '+=555px' });
	
}

$(document).ready(function(){
	
	if ($('form.transForm').length!=0) {
		$(function(){
			$('form.transForm').jqTransform({imgPath:'../img/formElements/'});
		});
	}
	
	Cufon.replace('#menuMain a', { 
		fontFamily: 'Myriad Pro'
	});
	
	Cufon.replace('#menuAuth a', { 
		fontFamily: 'Myriad Pro'
	});
	
	Cufon.replace('#menuLang a.cur', { 
		fontFamily: 'Myriad Pro'
	});
	
	Cufon.replace('#menuLang-selector a', { 
		fontFamily: 'Myriad Pro',
		hover: {
			color: '#fff'
		}
	});
	
	Cufon.replace('#lSide .blockRegist .grTitle', { 
		fontFamily: 'Tahoma',
		color: '-linear-gradient(#c9db29,#85ae17)',
		textShadow: '#000 1px 1px'
	});
	
	Cufon.replace('#rSide .blockRegist .grTitle', { 
		fontFamily: 'Tahoma',
		color: '-linear-gradient(#0fc5e8,#0ea3d4)',
		textShadow: '#000 1px 1px'
	});
	
	Cufon.replace('#flapLeft .blockRegist .grTitle', { 
		fontFamily: 'Tahoma',
		color: '#1e5b6f',
		textShadow: '#57bfe1 1px 1px, #000 -1px -1px'
	});
	
	Cufon.replace('.blockText .grTitle', { 
		fontFamily: 'Tahoma',
		color: '-linear-gradient(#0fc5e8,#0ea3d4)',
		textShadow: '#000 1px 1px'
	});
	
	Cufon.replace('#menuContent a', { 
		fontFamily: 'Myriad Pro',
		hover: {
			color: '#11c4ff'
		},
		textShadow: '#000 1px 1px'
	});
	
	var documentHeight = $(document).height();
	var windowHeight = $(window).height();
	
	//alert(documentHeight + ' --- ' +windowHeight);
	
	if (windowHeight > documentHeight) flapHeight = windowHeight; else flapHeight = documentHeight;
	
	$('#container').css({ 'height' : flapHeight + 'px' });
	$('#flapLeft, #flapRight').css({ 'height' : flapHeight + 'px' });
	
	if ($('#arr-flapLeft').length != 0 ) {
		
		Cufon.CSS.ready(function(){
		
			$('#arr-flapLeft-cur').each(function(){
				
				var position = $('#menuMain a.cur').position();
				var left = position.left;
				var width = $('#menuMain a.cur').width();
				var pos = Math.round(width / 2) + left;
				
				$(this).css({ 'left' : 280 + pos + 'px' });
				
			});
			
		});
	
		$('#menuMain a').hover(function(){
			
			var position = $(this).position();
			var left = position.left;
			var width = $(this).width();
			var pos = Math.round(width / 2) + left;
			
			$('#arr-flapLeft').css({ 'left' : 280 + pos + 'px' }).show();
			
		}, function(){
			
			$('#arr-flapLeft').hide();
			
		});
	
	} else {
		
		$('#flapLeft, #flapRight').css({ 'height' : flapHeight + 'px' });
		
	}
	
	$('#menuLang a.cur').click(function(){
		if ($('#menuLang-selector').is(":hidden")) {
			$('#menuLang-selector').fadeIn('fast');
		}
	});
	$('#menuLang a.cur').click(function(){
		if ($('#menuLang-selector').is(":hidden")) {
			$('#menuLang-selector').fadeIn('fast');
		}
		return false;
	});
	$('#menuLang').mouseleave(function(){
		if ($('#menuLang-selector').is(":visible")) {
			$('#menuLang-selector').fadeOut('fast');
		}
	});
	
	if ($('.blockTable').length != 0 ) {
		
		$('.blockTable table tr:last td').css({ 'background' : 'none' });
		
	}
	
	$('a#bt-login').click(function(){ flapRightBack(); return false; });
	
	$('a#bt-regist').click(function(document){
		if( $.browser.opera) {
			$('html').animate({scrollTop:160}, 'slow');
		} else {
			$('html, body').animate({scrollTop:160}, 'slow');
		}
		return false;
	});
	
	$('#flapLeft a.bt-rm').click(function(){ flapRightForward(); return false; });
	
	$('a#bt-flapLeftTriangle').click(function(){ flapRightForward(); return false; });
	
	$('#flapRight a.bt-rm').click(function(){ flapLeftForward(); return false; });
	
	$('a#bt-flapRightTriangle').click(function(){ flapLeftForward(); return false; });
	
	$('.blockFaq:last').css({ 'border-bottom' : 'none' });
	
});
