﻿//-----------------------------------------------------------
// COMMON JAVASCRIPT FILE require jQuery 1.3
//-----------------------------------------------------------

$(function() {
	/*
		jCarouselLite Setting
		++++ require jcarousellite_1.0.1. +++
		
		See Document
		------------------------------------------
		http://www.gmarwaha.com/jquery/jcarousellite/
	
	*/
	if ($(".season-bus-roll").length) {
		var biggest = 107;
		$(".season-bus-roll ul li img").each(function(){
			if(biggest < $(this).height()) {
				biggest = $(this).height();
			}
		});
		
		$(".season-bus-roll").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			biggestLi: biggest
		});
	}
	
	/*
		Sidemenu Click Behavior
	
		Markup Example
		------------------------------------------
		<div id="Navigation" class="switch">
			<h2><a href="#">hogehoge</a></h2>
			<ul>
				<li><a href="hogehoge.html">hogehoge link</a></li>
				<li><a href="hogehoge.html">hogehoge link</a></li>
			</ul>
		</div>
	
	*/
	if ($("#Navigation.switch h2 a").length) {
		$("#Navigation.switch h2 a").click(function(){
			var h2 = $(this).parent();
			h2.next().toggle();
			if(h2.parent().attr("class") === "block-on") {
				h2.parent().attr("class", "block-off")
			} else {
				h2.parent().attr("class", "block-on")
			}
			return false;
		});
	}
	
	/*
		initRollOverImages
	 
		Markup Example
		------------------------------------------
		<div class"rollover"><a href="hogehoge.html"><img src="hogehoge.jpg"></a></div>
	
		File Name Example
		------------------------------------------
		hogehoge.jpg <--> hogehoge_on.jpg

	*/
	var initRollOverImages = function() {
		var image_cache = new Object();
		$(".rollover a img").not("[src*='_on.']").each(function(i) {
			var imgsrc = this.src;
			var dot = this.src.lastIndexOf('.');
			var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
			image_cache[this.src] = new Image();
			image_cache[this.src].src = imgsrc_on;
			$(this).hover(
				function() { this.src = imgsrc_on; },
				function() { this.src = imgsrc; }
			);
		});
	}
	
	initRollOverImages();
	AC_FL_RunContent = 0;


	// See this URL "/car/index.html". Style fix for non IE browsers.
	if ($("div.pickup div.lead").length) {
		$('div.pickup div.fig img').load(function(){
			if(!jQuery.browser.msie) {
				$('div.pickup div.lead').css({
					'margin-left'	: $('div.pickup div.fig').outerWidth(),
					'float'			: 'none'
				});
			}
		});
	}
	
});

function addEve(obj, eve, func){
	if (obj.addEventListener) { //for W3C DOM
	  obj.addEventListener(eve, func, false);
	} else if (obj.attachEvent) { //for IE
	  window.attachEvent("on"+eve, func);
	} else  {
		if(eve=="load")obj.onload = func;
		if(eve=="mouseover")obj.mouseover = func;
		if(eve=="mouseout")obj.mouseout = func;
		if(eve=="unload")obj.onunload = func;
	}
}