Avtoprokat – Car Rental

JavaScript
$(document).ready(function() {
	$("#get-date").datepicker({
		minDate: 0,
		numberOfMonths: 2,
		showOn: 'button',
		buttonImage: './images/blank.gif',
		buttonImageOnly: true,
		showButtonPanel: true,
		dateFormat: 'dd.mm.yy'
	});

	$("#return-date").datepicker({
		minDate: 0,
		numberOfMonths: 2,
		showOn: 'button',
		buttonImage: './images/blank.gif',
		buttonImageOnly: true,
		showButtonPanel: true,
		dateFormat: 'dd.mm.yy'
	});

	// Select text
	$("#route-planner div.select, #header .languages div.select, #preview div.select, #search div.select, #article .blog div.select,#content .information .container div.select").each(function() {
		var selectOptionText = $(this).children("select").children("option:selected").text();
		$(this).children('.select').text(selectOptionText);
	});
	$("#route-planner select, #header .languages select, #preview select, #search select, #article .blog select, #content .information .container div.select select").change(function() {
		var selectOptionText = $(this).children("option:selected").text();
		$(this).parent().children("span").text(selectOptionText);
	});

	// Checkbox
	$("span.checkbox, label.checkbox").click(function () {
		if (this.nodeName == 'LABEL') {
			var chk = $(this).children('span');
		} else {
			var chk = $(this);
		}
		var input = chk.children();

		if(chk.hasClass('c-checked')) {
			chk.removeClass('c-checked');
			input.removeAttr('checked');
			chk.css({'backgroundposition': '0 -16px'}); // IE6
		} else {
			chk.addClass('c-checked');
			input.attr('checked', 'checked');
			chk.css({'backgroundposition': '0 0'}); // IE6
		}
		return false;
	});

	// Select all checkboxes which checked by default
	function select(e) {
		if (e.length >0) {
			e.addClass('c-checked');
			e.css({'backgroundposition': '0 -16px'}); // IE6
		}
		return false;
	}
	jQuery.each($("input:checked"), function () {select($(this).parent('span'))});

	// Select language
	$("#fleet-list .top .select.language").click(function() {
		var p = $(this).children('ul.select2');
		p.addClass('open');

		p.parent().mouseleave(function () {
			$(this).children().removeClass("open");
		});
	});
	$("#fleet-list .top .select.language ul.select2 li a").click(function() {
		var p = $(this).parent().parent();
		var curr = p.parent().children('span.select2');
		// Change image source
		curr.children('img').attr('src', $(this).children('img').attr('src'));
		p.removeClass("open");

		return false;
	});

	// Hide the elements if visible
	$('body').click(function(event) {
		$('#header .languages a').parent().parent().removeClass('open');
		if($.browser.msie && $.browser.version=="6.0") {
			$('#header .languages .bottom').css({'background-position': '0 -500px'}); // IE6
		}
	});
	// Not hide .language children-block .bottom
	$('#header .languages .bottom').click(function () {
		return false;
	});
	// Submit form.buttom
	$('#header .languages .bottom .actions .button').click(function () {
		$(this).parent().parent().submit();
	});
	// Toggle .languages
	$("#header .languages a").click(function () {
		var p = $(this).parent().parent();
		var hasCls = p.hasClass('open');
		if(hasCls) {
			p.removeClass('open');
			if($.browser.msie && $.browser.version=="6.0") {
				p.children('.bottom').css({'background-position': '0 -500px'}); // IE6
			}
		} else {
			p.addClass('open');
			if($.browser.msie && $.browser.version=="6.0") {
				p.children('.bottom').css({'background-position': '0 0'}); // IE6
			}
		}
		return false;
	});

	// Toggle .fleet-hint
	$("#fleet-list table td.car-description").click(function () {
		var c = $(this).children().children();
		var hasCls = c.hasClass('open');

		$("#fleet-list div.fleet-hint").removeClass('open');
		if(hasCls) {
			c.removeClass('open');
		} else {
			c.addClass('open');
		}
		return false;
	});
	$("#fleet-list div.fleet-hint button.close").click(function () {
		$(this).parent().removeClass('open');
	});

	// Toggle #wrap-form
	$("#wrap-form button.details").click(function () {
		var e = $(this).parent().parent();
		var hasCls = e.hasClass('open');
		if(hasCls) {
			e.removeClass('open');
		} else {
			e.addClass('open');
		}
		return false;
	});

	if($.browser.msie && $.browser.version=="6.0") {
		// .hint-block auto width
		$('#article .hint-block p').each(function () {
			$(this).parent().width($(this).outerWidth());
		});

		// Hovers
		$('#header .languages .bottom .actions .button, #header .block .order input.button, #header .block .nav li, #preview .search fieldset.bottom .button, #footer .subscribe .form fieldset .button, #content .offers .special .info .choose, #search fieldset.bottom .button, #article .blog .pagination li:not(.active), #route-planner div fieldset.actions input.button, #actions .center, #actions .button2, #content .information .login input.button, #content .status-block .container .button').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});

		$('#preview .search fieldset div.select, #preview .search fieldset div.select.date, #preview .search fieldset div.select.time, #article #fleet-list .top .select.language').hover(function(className) {
			className = $(this).attr('class').split(' ')[1];
			if (className === undefined) {
				newClassName = 'select-hover';
			} else {
				newClassName = 'select-' + className + '-hover';
			}
			$(this).addClass(newClassName);
		}, function() {
			$(this).removeClass(newClassName);
		});
	}

	// Change disabled form select background
	if($.browser.msie && $.browser.version<="7.0") {
		$('select[disabled="true"]').parent().addClass('disabled');
	} else {
		$('select[disabled="disabled"]').parent().addClass('disabled');
	}

	// Input field placeholders
	$('#header .block .order input, #footer .subscribe .form fieldset input').focus(function () {
		if (typeof $(this).attr('placeholder') == 'undefined' || $(this).attr('placeholder') == $(this).val()) {
			$(this).attr('placeholder', $(this).val());
			$(this).val();
			$(this).attr('value', '');
		}
	}).blur(function () {
		if ($(this).val().length == 0) {
			$(this).attr('value', $(this).attr('placeholder'));
		}
	});

	// Preview slider
	$("#preview .preview").easySlider({
		auto: true,
		continuous: true,
		numeric: true,
		pause: 5000
	});

	// search-results
	// Open current layer(.info-block)
	$('#search-results a[rel="equipment"], #search-results a[rel="similar"]').click(function () {
		var className = '.' + $(this).attr('rel');
		var p = $(this).parent().parent().parent();
		if (p.hasClass('block')) {
			var pNew = p.parent();
		} else {
			var pNew = p.parent().parent();
		}
		var e = pNew.children().children(className);
		var hasCls = e.hasClass('open');

		$('#search-results div.info-block').removeClass('open');
		if(hasCls) {
			e.removeClass('open');
		} else {
			e.addClass('open');
		}

		// IE6-7 z-index fix
		if($.browser.msie && $.browser.version<="7.0") {
			// Change current element(li.search-results) z-index value by biggest z-index value in this list
			$("#search-results li.search-results").css('z-index', 1); // Reset z-index for all elements
			pNew.css('z-index', 10); // New z-index biggest value
		}
		return false;
	});
	$("#search-results div.info-block div.header button.close").click(function () {
		$(this).parent().parent().removeClass('open');
		return false;
	});

	// Change currency
	$('#search-results .currency .title li a').click(function () {
		$('#search-results .currency .title li').removeClass('active');
		var currentClassName = $(this).parent().attr('class');
		$('#search-results .currency .title li.'+currentClassName).addClass('active');
		$('#search-results .currency .value li').removeClass('active');
		$('#search-results .currency .value li.'+currentClassName).addClass('active');

		return false;
	});

	// Change special offers on mainpage
	$('#content div.offers ul.countries li a').click(function () {
		// Menu
		var p = $(this).parent();
		$('#content div.offers ul.countries li').removeClass('active'); // Reset classes
		$('#content div.offers ul.countries li').removeClass('no-border'); // Reset classes
		p.prev().addClass('no-border');
		p.addClass('active');

		// Items
		var className = '.' + $(this).attr('rel');
		$('#content div.offers ul.special').removeClass('active'); // Reset classes
		p.parent().parent().children(className).addClass('active');

		return false;
	});

});