// основные функции

$(document).ready(function(){

	// поля с подсказкой

	$('input.onfocus').addClass('title_text');

	$('input.onfocus').focus(function(){
		value	= $(this).attr('title');
		if($(this).val() == value) $(this).val('').removeClass('title_text');
	});

	$('input.onfocus').blur(function(){
		value	= $(this).attr('title');
		if($(this).val() == '') $(this).val(value).addClass('title_text');
	});
	
	// проверка форм

	$('form.form_required').each(function(){ current = $(this); formCheck(current);	});
	$('form.form_required .required').keyup(function(){	current = $('form.form_required').has(this); formCheck(current); });

	function formCheck(current){
		empty	= $('.required[value=""]', current).size();
		button	= $('.button', current);

		if (empty == 0) {$(button).attr('disabled', '');}
		else {$(button).attr('disabled', 'disabled');}
	}
	
	$('form.form_required').submit(function(){ $('.button', this).attr({disabled: 'disabled', value: 'идет отправка'});	});
	
	$('.more_fields').hide();
	$('.more_fields_link').click(function(){
		$('.more_fields').toggle();	
	});
	
	// смена фотографий
	
	$("#gallery .thumb a").click(function(){
		imurl = $(this).attr("href");
		$('#gallery .big img').attr({src: imurl});
		return false;
	});
	
	// бегущая строка

	$('#scroll').crawlLine({
		speed: 3,
		crawElement: '#scroll_block',
		textElement: 'p',
		hoverClass: 'viewText'
	});
	
	$('.full_text').hide();

	$('.show_text').click(function(){
		destination = $('#scroll_point').offset().top;
		$("html").animate({ scrollTop: destination}, 300, function() {
		   $('.detail_text').fadeOut(
			"slow", 
			function() {
				$('.full_text').fadeIn(1000);
			}
		   );
		});
		//$('.detail_text').hide();
		//$('.full_text').show();
	});
	
	$('.hide_text').click(function(){
		destination = $('#scroll_point').offset().top;
		$("html").animate({ scrollTop: destination}, 300, function() {
		   $('.full_text').fadeOut(
			"slow", 
			function() {
				$('.detail_text').fadeIn(1000);
			}
		   );
		});
		//$('.detail_text').hide();
		//$('.full_text').show();
	});
});


