$(document).ready(function(){

	if ($('.new_select').length > 0) {
		$('.new_select').sSelect({				selectClass: 'smallList'			});
	}

	if ($('.big_select').length > 0) {
		$('.big_select').sSelect({
				selectClass: 'bigList'
			});
	}

	if ($('.middle_select').length > 0) {
		$('.middle_select').sSelect({
				selectClass: 'middleList'
			});
	}

	if ($('.scroll_container').length > 0) {
		$('.scroll_container').jScrollPane({showArrows:true, scrollbarWidth:17, dragMaxHeight:69, dragMinHeight: 69});
	}

	$('a.color_link').click(function(){
		var bg_id = $(this).attr('rel');
		if ($(this).hasClass('cl_open')) {
			$(this).removeClass('cl_open');
			$('.bg_block#'+bg_id).slideUp('fast');
		} else {
			$(this).addClass('cl_open');
			$('.bg_block#'+bg_id).slideDown('fast');
		}

		return false;
	});

	// Стилизация чекбокса
	$(function(){ $("input:checkbox").uniform(); });

	/* Подсказки для input-полей. Берутся из title. По клику убираются */
	$('form input').each(function(){
		$(this).bind('focus', function () {
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}
		})
		.bind ('blur', function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr('title'));
			}
		});

		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});


	/* Слайды */

	if ($('#slides').length > 0) {
		$('#slides').slides({
			next: '#arrow_next',
			prev: '#arrow_prev',
			generatePagination: false
		});
	}
	/* Слайды */
	if ($('#page_slide').length > 0) {
		$('#page_slide').slides({
			play: 5000,
			generatePagination: false
		});
	}

	/* Всплывающая форма регистрации */
	$('a#register_link').click(function(e) {
		$('#register_form').lightbox_me({
			centered: false,
			lightboxSpeed:	0,
			modalCSS: {
				top: "230px"
			},
			overlayCSS: {
				background: 'black',
				opacity: .85
			}
		});
		e.preventDefault();
		$('#register_form a.submit').click(function(){
			$('#register_form').find('form').submit();
		});
	});

	/* Всплывающая форма заказа карты */
	$('a#cardorder_link').click(function(e) {
		jQuery.validator.addMethod("neqtitle", function(value, element) { 
			  return this.optional(element) || (element.title!=value && value != '') ; 
			});
		
		$('#cardorder_form').validate({
			messages:  {
				custname: 	"Укажите ФИО владельца карты",
				phones: 	"Укажите телефоны для связи",
				branch: 	"Выберите клуб"
			}
		});
		
		$('#cardorder_div').lightbox_me({
			centered: false,
			lightboxSpeed:	0,
			modalCSS: {
				top: "100px"
			},
			overlayCSS: {
				background: 'black',
				opacity: .85
			}
		});
		e.preventDefault();
		$('#cardorder_div a.submit').click(function(){
			$('#cardorder_form').submit();
		yaCounter11390218.reachGoal('ORDER');
		});
		$('#cardorder_div input, #cardorder_div select').change(function(){
			$('#post_'+$(this).attr('id')).val($(this).val());
		});
	});
	
	$('form#cardorder_form').submit(function(e){
		//$(this).find('input.text').each(function(){if (this.value==this.title) this.value='';});
	});

	/* Всплывающая картa 
	$('a#map_link').click(function(e) {
		$('#maplink_div').lightbox_me({
			centered: false,
			lightboxSpeed:	0,
			modalCSS: {
				top: "30px"
			},
			overlayCSS: {
				background: 'black',
				opacity: .85
			}
		});
		e.preventDefault();
	});
	*/

	/* Всплывающая карта, три дэ тур и ютюбовский клип */
	$('a.tdt_link,a.map_link,a.yt_link').click(function(e) {
		$('.'+$(this).attr('href')+'link_div').lightbox_me({
			centered: false,
			lightboxSpeed:	0,
			modalCSS: {
				top: "30px"
			},
			overlayCSS: {
				background: 'black',
				opacity: .85
			}
		});
		e.preventDefault();
	});

	/* Всплывающая форма входа */
	$('a#login_link').click(function(e) {
		$('#login_form').lightbox_me({
			centered: false,
			lightboxSpeed:	0,
			modalCSS: {
				top: "100px"
			},
			overlayCSS: {
				background: 'black',
				opacity: .85
			}
		});
		e.preventDefault();
		$('#login_form a.submit').click(function(){
			$('#login_form').find('form').submit();
		});
	});

});

