//СОБЫТИЯ
$(function(){
	$.datepicker.setDefaults({
		firstDay: 1,
		dateFormat: 'yy-mm-dd',
		dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
		dayNamesMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
		monthNames: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
		duration: 'fast',
		changeYear: true
	});
	
	// FEEDBACK
	$("#feedback").fancybox({
		'scrolling'  : 'no',
		'titleShow'  : false
	});
    
    $('#mycarousel').jcarousel({
        wrap: 'circular',
        scroll: 1
    });
    $('#open_list').click(
        function() {
            $('.all_gallery_list').is(':hidden') ? $('.all_gallery_list').slideDown('fast') : $('.all_gallery_list').slideUp('fast');
            return false;
        }
    );
    $('.all_gallery_list > li > a').click(
        function() {
            $(this).parent().parent().slideUp('fast');
            return true;
        }
    );    
    $('#main_menu > ul > li').hover(
        function() {
            $(this).addClass("open");
            $(this).find('> ul').stop(true, true);
            $(this).find('> ul').show('fast');
        },
        function() {
            $(this).removeClass("open");
            $(this).find('> ul').hide('fast');
        }
    );
    $('#subs').click(
        function() {
            $('#subs_main').is(':hidden') ? $('#subs_main').show('fast') : $('#subs_main').hide('fast');
            return false;
        }
    );
    
    $('#select_country').change(function() {
            document.location.href='/ru/country/'+$(this).val()+'/';
    });

	$("ul.menu_country li ul:not(:first)").hide();
	
	$('ul.menu_country a.sub').click(function() {
		$(this).css('outline','none');
		if($(this).parent().hasClass('open')) {
			$(this).siblings('ul').slideUp('slow',function() {
				$(this).parent().removeClass('open');
			});
		} else {
			$('ul.menu_country li.open ul').slideUp('slow',function() {
				$(this).parent().removeClass('open');
			});
			$(this).siblings('ul').slideToggle('slow',function() {
				$(this).parent().toggleClass('open');
			});
		}
		return false;
	})
	
	//SUBSCRIBE
	$('#subscribe-add').click(function(){
		var vars = {
			ru : {
				errors : {
					emptyMail : 'Введите e-mail',
					wrongMail : 'E-mail некорректен'
				},
				loading : 'Загрузка',
				enter : 'Подписаться'
			},
			en : {
				errors : {
					emptyMail : 'Enter e-mail',
					wrongMail : 'E-mail is incorrect'
				},
				loading : 'Loading',
				enter : 'Subscribe'
			}
		};
		var that = this;
		var el = $('#subscribe-mail');
		var val = el.val();
		var msg = [];
		if( val=='' || val==el.attr('title') ) msg.push(vars[_LANG_].errors.emptyMail);
		else if( !val.match(/^[\d\w\.-]+@([\d\w-]+)((\.[\w\d-]+)+)?\.\w{2,6}$/) ) msg.push(vars[_LANG_].errors.wrongMail);
		
		if(msg.length>0){
			alert(msg.join("\n"));
			return false;
		}
		$(this).text(vars[_LANG_].loading).attr('disabled', 'disabled');
		$.get(ajaxFile, {go:'subscribe_add', mail:val}, function(html){
			$(that).text(vars[_LANG_].enter).removeAttr('disabled');
			alert(html);
		});
	});
});

$(function(){
	$('.needClear')
		 .focus(function(){
			  if(this.value==this.title) this.value='';
		 })
		 .blur(function(){
			  if(this.value=='') this.value=this.title;
		 });
});

function checkSearchForm(f){
	var msg = [];
	
	if(f['what'].value=='Поиск по сайту' || f['what'].value=='') msg.push('Введите слово для поиска');
	else if(f['what'].value.length<3) msg.push('Слово для поиска должно быть длиннее 3-х символов');
	
	if(msg.length>0){
		alert(msg.join("\n"));
		return false;
	}
	return true;
}
