/* Popup Window
-------------------------------------------------------------*/
function window_pop( $url, $width, $hight ){
	$param = "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes,location=no";
	if ( screen.width > $width ){
		$param += ',left='+(screen.width - $width)/2;
	} else {
		$param += ',left='+screen.width;
	}
	$param += ',width='+$width;
	if ( screen.height > $hight ){
		$param += ',top='+(screen.height - $hight)/2;
	} else {
		$param += ',top='+screen.height;
	}
	$param += ',height='+$hight;
	window.open($url,'cars',$param);
}

/* jquery.rollover.js
-------------------------------------------------------------*/
/**
 * rollOver on jQuery
 * rollOver tag:img,input
 * rollOver class:Over
 * rollOver FileName:*_on.*
 * Last modify:20081210
 * Licensed:MIT License
 * @author AkiraNISHIJIMA(http://nishiaki.probo.jp/)
 */

function rollOver(){
    var preLoad = new Object();
    $('img.Over,input.Over').not("[src*='_on.']").each(function(){
        var imgSrc = this.src;
        var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
        var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
        var imgOver = imgName + '_on' + fType;
        preLoad[this.src] = new Image();
        preLoad[this.src].src = imgOver;
        $(this).hover(
            function (){
                this.src = imgOver;
            },
            function (){
                this.src = imgSrc;
            }
        );
    });
}
$(document).ready(rollOver);



$(function(){
/* Date Base Setting
-------------------------------------------------------------*/
	var nowdate = new Date();
	def1_year = nowdate.getFullYear();
	def1_month = nowdate.getMonth() + 1;
	def1_day = nowdate.getDate();
	
	var nowms = new Date().getTime();
	var after = 1;
	after = after*24*60*60*1000;
	ans = new Date(nowms+after);
	def_year = ans.getFullYear();
	def_month = ans.getMonth() + 1;
	def_day = ans.getDate();
	
	$("select[name=year_loans],select[name=year_return]").val(def_year);
	$("select[name=month_loans],select[name=month_return]").val(def_month);
	$("select[name=day_loans],select[name=day_return]").val(def_day);
	$("select[name=hour_loans]").val(10);
	$("select[name=hour_return]").val(17);

/* Date Change Setting
-------------------------------------------------------------*/
	$("select[name=year_loans],select[name=month_loans],select[name=day_loans],select[name=hour_loans]").change(function(){
		DeYYYY = $("select[name=year_loans]").val();
		DeMM = $("select[name=month_loans]").val();
		DeDD = $("select[name=day_loans]").val();
		ReYYYY = $("select[name=year_return]").val();
		ReMM = $("select[name=month_return]").val();
		ReDD = $("select[name=day_return]").val();
		
		var DeDates = new Date(DeYYYY,DeMM-1,DeDD).getTime();
		var ReDates = new Date(ReYYYY,ReMM-1,ReDD).getTime();
		if(nowms > DeDates){
			$("select[name=year_loans]").val(def1_year);
			$("select[name=month_loans]").val(def1_month);
			$("select[name=day_loans]").val(def1_day);
		} else {
			if(DeDates > ReDates){
				$("select[name=year_return]").val(DeYYYY);
				$("select[name=month_return]").val(DeMM);
				$("select[name=day_return]").val(DeDD);
			}
		}
	});
	$("select[name=year_return],select[name=month_return],select[name=day_return],select[name=hour_return]").change(function(){
		DeYYYY = $("select[name=year_loans]").val();
		DeMM = $("select[name=month_loans]").val();
		DeDD = $("select[name=day_loans]").val();
		ReYYYY = $("select[name=year_return]").val();
		ReMM = $("select[name=month_return]").val();
		ReDD = $("select[name=day_return]").val();
		var DeDates = new Date(DeYYYY,DeMM-1,DeDD).getTime();
		var ReDates = new Date(ReYYYY,ReMM-1,ReDD).getTime();
		if(nowms > ReDates){
			$("select[name=year_loans],select[name=year_return]").val(def1_year);
			$("select[name=month_loans],select[name=month_return]").val(def1_month);
			$("select[name=day_loans],select[name=day_return]").val(def1_day);
			$("select[name=hour_loans]").val(10);
			$("select[name=hour_return]").val(17);
		} else {
			if(DeDates > ReDates){
	//			alert("設定された日付が間違っています。\n返却日をお確かめ下さい。")
				$("select[name=year_loans]").val(ReYYYY);
				$("select[name=month_loans]").val(ReMM);
				$("select[name=day_loans]").val(ReDD);
			}
		}
	});


/* Image Mouse Over
-------------------------------------------------------------*/
	$(".img_hv").hover(
	function () {
		imgSrc = $(this).attr("src");
		changeSrc = imgSrc.replace("_off.", "_on.");
		$(this).attr("src",changeSrc);
	}, 
	function () {
		imgSrc = $(this).attr("src");
		changeSrc = imgSrc.replace("_on.", "_off.");
		$(this).attr("src",changeSrc);
	});
	$(".img_ov img").hover(
	function () {
		imgSrc = $(this).attr("src");
		changeSrc = imgSrc.replace("_off.", "_on.");
		$(this).attr("src",changeSrc);
	}, 
	function () {
		imgSrc = $(this).attr("src");
		changeSrc = imgSrc.replace("_on.", "_off.");
		$(this).attr("src",changeSrc);
	});

/* Input Mouse Over
-------------------------------------------------------------*/
	$(".btn_ov").hover(
	function () {
		imgSrc = $(this).attr("src");
		imgSrc = imgSrc.replace("_off.", "_on.");
		$(this).attr("src",imgSrc);
	}, 
	function () {
		imgSrc = imgSrc.replace("_on.", "_off.");
		$(this).attr("src",imgSrc);
	});

/* CheckBox Tab
-------------------------------------------------------------*/
	$(".chkTab").each(function(){
		if($(this).is(":checked")){
			$(this).parent("label").addClass("Selected");
			$(this).parent().parent().show();
		}else{
			$(this).parent("label").removeClass("Selected");
		}
	});
	$(".chkTab").live("click",function(event) {
		if($(this).is(":checked")){
			$(this).parent("label").addClass("Selected");
		}else{
			$(this).parent("label").removeClass("Selected");
		}
	});

/* 
-------------------------------------------------------------*/
	var input_id = "#dataSearchOption";
	var input_id2 = "#dataSearchType";
	for(var i = 0; i <= 12; i++) {
		if($(input_id + i).attr("checked")){
			$(input_id + i).next("label").addClass("on");
		}
	}
	for(var i = 0; i <= 12; i++) {
		if($(input_id2 + i).attr("checked")){
			$(input_id2 + i).next("label").addClass("on");
		}
	}
	if($("#dataSearchIndemnity").attr("checked")){
		$("#dataSearchIndemnity").next("label").addClass("on");
	}
    $(".toggle_check").click(function(){
        if($(this).is(":checked")){
            $(this).next("label").addClass("on");
        }else{
            $(this).next("label").removeClass("on");
        }
    });

/* こだわり
-------------------------------------------------------------*/
	$("#btn_acc img").toggle(
		function() {$("#commitment").slideDown(180);},
		function() {$("#commitment").slideUp(180);}
	);
	$("#btn_acc").mouseover(function() {
		$(this).css({"cursor":"pointer"});						 
	});

/* Accordion Menu
-------------------------------------------------------------*/
	$(".Switch").click(function(){
		$("+dd.SwitchOn",this).slideToggle("normal");
	})

/* Tab Menu
-------------------------------------------------------------*/
	$("a.tab").click(function(){
		$(".Select").removeClass("Select");
		$(this).addClass("Select");
		$(".tabBox").addClass("disnon");
		var muestra = $(this).attr("title");
		$("#"+muestra).removeClass("disnon"); 
	});

/* Cmp Search Button
-------------------------------------------------------------*/
	$("#BtnCmpSearch").click(function(){
		var url = "http://www.rental-car.jp/cars/index/";
		url += $("#cmp_shop").val() + "/0/"
			+  $("#cmp_area").val() + "/0/"
			+  $("#cmp_loans").val() + "/"
			+  $("#cmp_return").val() + "/"
			+  $("#cmp_hour_loans").val() + "-00/"
			+  $("#cmp_hour_return").val() + "-00/";
		location.href = url;
//		window.open(url)
	})

/* Cmp Search Button ver2
-------------------------------------------------------------*/
	$("#BtnCmpSearch2").click(function(){
		var url = "http://www.rental-car.jp/cars/index/";
		var AllVals = new Array;
		$("input[name=car_type]:checked").map(function() {
			AllVals.push($(this).val());
		});
		url += $("#cmp_shop").val() + "/0/"
			+  $("#cmp_area").val() + "/0/"
			+  $("#cmp_loans").val() + "/"
			+  $("#cmp_return").val() + "/"
			+  $("#cmp_hour_loans").val() + "-00/"
			+  $("#cmp_hour_return").val() + "-00/"
			+  AllVals;
		location.href = url;
//		window.open(url)
	})

/* RenNavi Cmp Search Button
-------------------------------------------------------------*/
	$("#BtnRenCmpSearch").click(function(){
		var url = "http://www.rental-car.jp/cars/index/0/0/";
		var AllVals = new Array;
		$("input[name=car_type]:checked").map(function() {
			AllVals.push($(this).val());
		});
		url += $("#pref").val() + "/"
			+  $("#area").val() + "/"
			+  $("#cmp_loans").val() + "/"
			+  $("#cmp_return").val() + "/"
			+  $("#cmp_hour_loans").val() + "-00/"
			+  $("#cmp_hour_return").val() + "-00/"
			+  AllVals;
		location.href = url;
//		window.open(url)
	})

/* Index Search Button
-------------------------------------------------------------*/
	$("#BtnIndexSearch").click(function(){
		var url = "/cars/index/0/0/";
		area = $("select[name=area]").val();
		if(area == "" || area == "undefined" || area == null){
			alert('ご利用エリアのピンポイントエリアを選択して下さい。');
		}else{
			var AllVals = new Array;
			$("input[name=car_type]:checked").map(function() {
				AllVals.push($(this).val());
			});
			url += $("select[name=prefecture]").val() + "/"
				+  $("select[name=area]").val() + "/"
				+  $("select[name=year_loans]").val() + "-"
				+  $("select[name=month_loans]").val() + "-"
				+  $("select[name=day_loans]").val() + "/"
				+  $("select[name=year_return]").val() + "-"
				+  $("select[name=month_return]").val() + "-"
				+  $("select[name=day_return]").val() + "/"
				+  $("select[name=hour_loans]").val() + "-00/"
				+  $("select[name=hour_return]").val() + "-00/"
				+  AllVals;
			location.href = url;
//			window.open(url)
		}
	})

});

/* プラン詳細
-------------------------------------------------------------*/
(function($){
	$.fn.fixedIE = function(options) {
		var s = $.extend({'fixed' : true,'top': 0,'left': 0}, options);
		this.each(function() {
			if(s.fixed){
				if(!$.support.style){
					var el = $(this).css({'position':'absolute'})[0];
					el.style.setExpression(
						'top','eval('+ s.top +'+(document.body.scrollTop||document.documentElement.scrollTop))'
					);
					el.style.setExpression(
						'left','eval('+ s.left +'+(document.body.scrollLeft||document.documentElement.scrollLeft))'
					);
					$('html').css({
						'background-image':'url(null)',
						'background-attachment':'fixed'
					});
				}
				else {
					$(this).css({'position':'fixed'}).css('top',s.top+'px');
				}
			}else{
				if(!$.support.style){
					var el = $(this).css({'position':'absolute'})[0];
					el.style.setExpression('top', s.top);
					el.style.setExpression('left', s.left);
				}
				else {
					$(this).css({'position':'absolute'})[0];
				}
			}
		});

		return this;
	};
})(jQuery);

$(function(){
	if($("#SimplePriceBox").size() > 0){
		if(!$.support.style){	//IE6,7
			var top = $('#SimplePriceBox').offset().top * -1 + 80;
		}else{
			var top = 80;
		}
	$(window).scroll(function () {
		var left = $('#SimplePriceBox').parent().position().left;
		var ScrTop = $(document).scrollTop() + 80;
		var subTop = $('#SimplePriceBox').parent().offset().top;
		
		$('#SimplePriceBox').css('width','205px').css('backgroundColor','#fff');
		if (ScrTop > subTop) {
			$('#SimplePriceBox').fixedIE({
				fixed:true,
				top: top,
				left: 0
			});
		}
		if (ScrTop < subTop) {
			$('#SimplePriceBox').css({'position':'static'});
		}
	});
	}
});

/* 比較画面
-------------------------------------------------------------*/
/*ラベル表示・非表示切替*/
$(function() {
	comp_flg($("#a-1-3"));
	comp_flg($("#a-1-5")); 
	comp_flg($("#a-1-7")); 
	comp_flg($("#a-1-8")); 
	comp_flg($("#a-1-9")); 
});
function comp_flg(myFlg) {
	myFlg.toggle(
		//表示
		function() {
			nowSrc = myFlg.attr("src")
			chSrc = nowSrc.replace("_df","_no");
			$(this).attr("src",chSrc);
		},
		//非表示
		function() {
			nowSrc = myFlg.attr("src")
			chSrc = nowSrc.replace("_no","_df");
			myFlg.attr("src",chSrc);
		}
	);
	//カーソール表示
	myFlg.mouseover(function() {
		$(this).css({"cursor":"pointer"});						 
	});
};
$(function(){
	$("#a-1-3").click(function() {$(".row-1-3").slideToggle(100);});
	$("#a-1-5").click(function() {$(".row-1-5").slideToggle(100);});
	$("#a-1-6").click(function() {$(".row-1-6").slideToggle(100);});
	$("#a-1-7").click(function() {$(".row-1-7").slideToggle(100);});
	$("#a-1-8").click(function() {$(".row-1-8").slideToggle(100);});
	$("#a-1-9").click(function() {$(".row-1-9").slideToggle(100);});
});

/* height Align
-------------------------------------------------------------*/
$(function() {
	equalHeight($("#list_a .row-1-1")); 
	equalHeight($("#list_a .row-1-2")); 
	equalHeight($("#list_a .row-1-3"));
	equalHeight($("#list_a .row-1-4")); 
	equalHeight($("#list_a .row-1-5")); 
	equalHeight($("#list_a .row-1-6")); 
	equalHeight($("#list_a .row-1-7")); 
	equalHeight($("#list_a .row-1-8")); 
	equalHeight($("#list_a .row-1-9")); 
	equalHeight($("#list_a .row-1-10")); 
	equalHeight($("#list_b .row-1-1")); 
	equalHeight($("#list_b .row-1-2")); 
	equalHeight($("#list_b .row-1-3"));
	equalHeight($("#list_b .row-1-4")); 
	equalHeight($("#list_b .row-1-5")); 
	equalHeight($("#list_b .row-1-6")); 
	equalHeight($("#list_b .row-1-7")); 
	equalHeight($("#list_b .row-1-8")); 
	equalHeight($("#list_b .row-1-9")); 
	equalHeight($("#list_b .row-1-10")); 
});

function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}

/* height Align 2
-------------------------------------------------------------*/
;(function($) {
	$.fn.tile = function(columns) {
		var tiles, max, c, h, last = this.length - 1, s;
		if(!columns) columns = this.length;
		this.each(function() {
			s = this.style;
			if(s.removeProperty) s.removeProperty("height");
			if(s.removeAttribute) s.removeAttribute("height");
		});
		return this.each(function(i) {
			c = i % columns;
			if(c == 0) tiles = [];
			tiles[c] = $(this);
			h = tiles[c].height();
			if(c == 0 || h > max) max = h;
			if(i == last || c == columns - 1)
				$.each(tiles, function() { this.height(max); });
		});
	};
})(jQuery);
