SunCar Rental

JavaScript
function slideShow() {
	var e = $("#promo");
	var count_e = $("#slideshow>li").size();
	if (e.data("count") >= (count_e - 1)) {
		var count = 0;
	} else {
		var count = (e.data("count") || 0) + 1;
	}
	e.data("count", count);

	var curr = $("#slideshow>li:eq("+ count +")");
	if (count == 0) {
		$("#slideshow>li:last-child").fadeOut("slow");
	} else {
		curr.prev('li').fadeOut("slow");
	}
	curr.fadeIn("slow");

	return false;
}
$(document).ready(function() {
	// Startpage big banner
	setInterval('slideShow()', 6000);

	$("#pickup_date INPUT").datepicker({
		numberOfMonths: 2,
		showOn: 'button',
		buttonImage: './images/calc-ico.gif',
		buttonImageOnly: true,
		dateFormat: 'dd M yy'
	});
	$("#dropoff_date INPUT").datepicker({
		numberOfMonths: 2,
		showOn: 'button',
		buttonImage: './images/calc-ico.gif',
		buttonImageOnly: true,
		dateFormat: 'dd M yy'
	});

	// Hint hover
	$("#promo .hint, #wrap2 .hint, #filter .hint").hover(
		function () {
			$(this).children('span').children('em').show();
		},
		function () {
			$(this).children('span').children('em').hide();
		}
	);

	// Autocomplete
	$(".text-type1 input").focusin(function () {
		var par = $(this).parent().children("div");
		par.addClass("opened");
		return false;
	});
	$("#dcdebox-hint li:not(.dcdebox-pager)").click(function () {
		var par = $(this).parent().parent();
		var input = par.parent().children("input");
		var str = jQuery.trim($(this).text());
		input.val(str);
		par.removeClass("opened");

		return false;
	});

	// Reservation login
	$("#header .reservation p, #header .reservation .reservation-title").click(function () {
		if ($(this).hasClass('reservation-title')) {
			var par = $(this).parent();
		} else {
			var par = $(this).parent().children('div');
		}
		if(par.hasClass('open')) {
			par.removeClass('open');
			par.children('.reservation-form').hide(); /*IE 6*/
		} else {
			par.addClass('open');
			par.children('.reservation-form').show(); /*IE 6*/
		}
	});

	// Special offers sort
	$("#content .sort .title").click(function () {
		var par = $(this).parent();
		if(par.hasClass('open')) {
			par.removeClass('open');
		} else {
			par.addClass('open');
		}
		return false;
	});
	// Select sort variant
	$("#content .sort ul li").click(function () {
		var par = $(this).parent().parent();
		var title = par.children('span.title');
		var title_text = title.text();
		var curr_text = $(this).text();

		$(this).text(title_text);
		title.text(curr_text);
		par.removeClass('open');
	});

	// Hide text from input and textarea
	$(".hide-text").focusin(function () {
		if ($(this).css('text-indent') != '1px') {
			$(this).attr('alt' ,$(this).val());
			$(this).val('');
		}
	});
	$(".hide-text").focusout(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('alt'));
			$(this).attr('alt', '');
			$(this).removeAttr('style');
		}
	});
	$(".hide-text").change(function () {
		$(this).css({'text-indent' : '1px'});
	});

	// Filter collapse-explode form
	$("#filter h2 span").click(function () {
		var par = $(this).parent().parent();
		if(par.hasClass('open')) {
			par.removeClass('open');
			//par.css({'background': 'url(./images/filter-bg.png) no-repeat left top'}); /* for IE6 */

		} else {
			par.addClass('open');
			//par.css({'background': 'url(./images/filter-open-bg.png) no-repeat left top'}); /* for IE6 */
		}
	});
	// Car result collapse-explode
	$("#search .r .result").click(function () {
		var button = $(this).children('li').children('div.button1');
		if($(this).hasClass('r-open')) {
			$(this).removeClass('r-open');
			button.text('Show');
		} else {
			$(this).addClass('r-open');
			button.text('Hide');
		}
		return false;
	});
	// Payment + Checkbox
	$("#info .payment label.title").click(function () {
		var chk = $(this).children('span');
		var input = chk.children();
		// Get .l or .r class from HTML
		var paymentMethod = $(this).parent().parent().attr('class');
		// Clear other method
		if (paymentMethod == "l") {
			var otherMethod = $("#info .r .payment label.title");
			// Hide message
			otherMethod.parent().children('p.message').hide();
		} else {
			var otherMethod = $("#info .l .payment label.title");
			// Show message
			$(this).parent().children('p.message').show();
		}
		var otherMethodChk = otherMethod.children('span');
		var otherMethodInput = otherMethodChk.children('input');

		otherMethodInput.removeAttr('checked');
		otherMethodChk.removeClass('c-checked');
		otherMethod.removeClass('t-open');
		otherMethodChk.css({'backgroundposition': 'left center'}); /* IE6 */

		// Checkbox
		if(chk.hasClass('c-checked')) {
			chk.removeClass('c-checked');
			input.removeAttr('checked');
			chk.css({'backgroundposition': 'left center'}); /* IE6 */
		} else {
			chk.addClass('c-checked');
			chk.css({'backgroundposition': '-15px center'}); /* IE6 */
			input.attr('checked', 'checked');
		}
		// Background
		if($(this).hasClass('t-open')) {
			$(this).removeClass('t-open');
		} else {
			$(this).addClass('t-open');
		}
		return false;
	});
	// 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': 'left center'}); /* IE6 */
		} else {
			chk.addClass('c-checked');
			//chk.css({'backgroundposition': '-15px center'}); /* IE6 */
			input.attr('checked', 'checked');
		}
		return false;
	});
	// Select text
	$("#content span.select, #message span.select").each(function() {
		var selectOptionText = $(this).parent().children("select").children("option:selected").text();
		//console.log(selectText);
		$(this).text(selectOptionText);
	});
	$("#content select, #message select").change(function() {
		var selectOptionText = $(this).children("option:selected").text();
		$(this).parent().children("span").text(selectOptionText)
	});

	// Message Box
	$("a.message").click(function () {
		var messageClass = $(this).attr("id");
		$("#message").show();
		$("#message").children('.'+messageClass).show();
	});
	$("#message div.box div.header a").click(function () {
		$(this).parent().parent().hide();
		$("#message").hide();
	});
	// Message Calendar
	$("#message .datepicker-arrival").datepicker({
		defaultDate: "-1m",
		showOtherMonths: true,
		selectOtherMonths: true
	});
	$("#message .datepicker-departure").datepicker();
});