jQuery.noConflict()(function($){

	var preLoadImg = new Object();

// メインメニュー / バナーメニュー
	$("ul#mainmenu > li,#brandbannerbox > ul > li").each(function(){
																  
		$(this).css('cursor','pointer').hover(
			function() {
				$(this).children('ul').css('visibility','visible').slideDown('250');
			},
			function() {
				$(this).children('ul').css('visibility','hidden').hide();
			}
		);
	});

// ショールームリスト
	$('#showroomlistbox > a > img').hover(
		function() {
			$(this).css('opacity','0.5');
		},
		function() {
			$(this).css('opacity','1');
		}
	);

// トップページ マップ
	if(navigator.userAgent.indexOf("MSIE 6")!=-1){
		$("#areamap").attr('src','pic/map.gif');
	}
	$("#mapbox > a > img.hoverimage").each(function(){
		var imgSrc = '/common_2009/pic/spacer.gif';
		var onSrc = '/common_2009/pic/hoverimage.png';
		preLoadImg[imgSrc] = new Image();
		preLoadImg[imgSrc].src = onSrc;
		$(this).hover(
			function() {
				$(this).attr('src',onSrc);
				var title = $(this).attr('alt');
				$(this).parent('a').attr('title',title);
			},
			function() {
				$(this).attr('src',imgSrc);
			}
		);
	});
	$('#topmapbrandvw').hover(
		function() {
			$('#brandvwimage').fadeIn(250);
		},
		function() {
			$('#brandvwimage').fadeOut(250);
		}
	);
	$('#topmapbrandaudi').hover(
		function() {
			$('#brandaudiimage').fadeIn(250);
		},
		function() {
			$('#brandaudiimage').fadeOut(250);
		}
	);
	$('#topmapbrandlamborghini').hover(
		function() {
			$('#brandlamborghiniimage').fadeIn(250);
		},
		function() {
			$('#brandlamborghiniimage').fadeOut(250);
		}
	);


// トップページ ニュース
	$('#newsbrandbox > img').css('cursor','pointer');
	$('body.home #newsallb').css('opacity','0.5');
	$('body.vw #newsvwb').css('opacity','0.5');
	$('body.audi #newsaudib').css('opacity','0.5');
	$('body.bentley #newsbentleyb').css('opacity','0.5');
	$('#newsallb').click(
		function() {
			$('#newsbrandbox > img').css('opacity','1');
			$(this).css('opacity','0.5');
			$('ul.newslist > li').fadeIn(250);
		}
	);
	$('#newsvwb').click(
		function() {
			$('#newsbrandbox > img').css('opacity','1');
			$(this).css('opacity','0.5');
			$('ul.newslist').find('li').hide().end()
			.find('li.vw , li.all').fadeIn(250);
		}
	);
	$('#newsaudib').click(
		function() {
			$('#newsbrandbox > img').css('opacity','1');
			$(this).css('opacity','0.5');
			$('ul.newslist').find('li').hide().end()
			.find('li.audi , li.all').fadeIn(250);
		}
	);
	$('#newsbentleyb').click(
		function() {
			$('#newsbrandbox > img').css('opacity','1');
			$(this).css('opacity','0.5');
			$('ul.newslist').find('li').hide().end()
			.find('li.bentley , li.all').fadeIn(250);
		}
	);

// 新車
	$('ul.lineuplist:last').after('<p id="message"></p>');
	$('#lineupselect select').find('option:first').attr('selected','selected').end()
	.find('option:gt(1)').attr('selected','');
	$('body.vw #lineupselect select[name^="brand"]').find('option:eq(1)').attr('selected','selected');
	$('body.audi #lineupselect select[name^="brand"]').find('option:eq(2)').attr('selected','selected');
	$('body.lamborghini #lineupselect select[name^="brand"]').find('option:eq(3)').attr('selected','selected');
	changelineup();
	$('.lineup #lineupselect select').change(
		function(){
			changelineup();
		});

	function changelineup(){
		var dispflug = 0;
		var selecttype = $('.lineup select[name^="type"] option:selected').attr('value');
		var selectusage = $('.lineup select[name^="usage"] option:selected').attr('value');
		var selectbrand = $('.lineup select[name^="brand"] option:selected').attr('value');
		var selectprice = $('.lineup select[name^="price"] option:selected').attr('value');
		var selecttech = $('.lineup select[name^="tech"] option:selected').attr('value');
		var selecteco = $('.lineup select[name^="eco"] option:selected').attr('value');
		$('body.lineup').attr('class','widepage lineup imageheight150 '+selectbrand);
		if(selectbrand == 'vw' || selectbrand == 'audi' || selectbrand == 'lamborghini'){
			$('#lineupimage').attr('src','pic/mainimage-'+selectbrand+'.jpg')
		}else{
			$('#lineupimage').attr('src','pic/mainimage.jpg');
		}
		$('ul.lineuplist > li').css('display','none');
		$('ul.lineuplist > li > ul > li').each(
		function(){
			$(this).css('display','none');
			var hit = 1;
			var classstr = $(this).attr('class');
			if(classstr.lastIndexOf(selecttype) < 0 && selecttype!='all') {
				hit=0;
			}
			if(classstr.lastIndexOf(selectusage) < 0 && selectusage!='all') {
				hit=0;
			}
			if(classstr.lastIndexOf(selectbrand) < 0 && selectbrand!='all') {
				hit=0;
			}
			if(classstr.lastIndexOf(selectprice) < 0 && selectprice!='all') {
				hit=0;
			}
			if(classstr.lastIndexOf(selecttech) < 0 && selecttech!='all') {
				hit=0;
			}
			if(classstr.lastIndexOf(selecteco) < 0 && selecteco!='all') {
				hit=0;
			}
			if(hit) {
				$(this).css('display','block').parent().parent().css('display','block');
				dispflug = 1;
			}
		});
		if(!dispflug) {
			$('#message').text('当てはまる車種はありませんでした。');
		} else if(selecteco == 'eco2010') {
			$('#message').text('※2010年度燃費基準達成モデルは、装備により対象とならない場合があります。');
		} else {
			$('#message').text('');
		}
	}

// 新車 リスト表示
	var zindex = 50;
	$('ul.lineuplist > li').each(function(){
		$(this).css('z-index',zindex);
		zindex=zindex-1;
	}).find('a').hover(
		function(){
			$(this).parent().children('ul').slideDown(250);
		},function(){
			$(this).parent().children('ul').slideUp(250);
	});
// 新車 リスト表示
	$('body.vw #lineupselect select').change(function(){
		$('.lineup select[name^="brand"] option:selected');
		});

// ロールオーバー
	$("a.rollover img").each(function(){
		var imgSrc = this.src;
		var sep = imgSrc.lastIndexOf('.');
		var onSrc = imgSrc.substr(0, sep) + '_f2' + imgSrc.substr(sep, 4);
		preLoadImg[imgSrc] = new Image();
		preLoadImg[imgSrc].src = onSrc;
		$(this).parent("a.rollover").hover(
			function() {
				$(this).children("img").css({opacity: "0"}).attr('src',onSrc).animate({ 
    				opacity: 1}, 250 );
			},
			function() {
				$(this).children("img").attr('src',imgSrc);
			}
		);
	});

});

function openSidemenu(selector){
	jQuery.noConflict()(function($){
		$(selector).children('ul').slideDown(250).end()
		.children('div.open').css('display','none').end()
		.children('div.close').css('display','block');
  		return $(selector);
	});
}


window.addEvent('domready', function(){
	//call multiBox
	var initMultiBox = new multiBox({
		mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
		container: $(document.body),//where to inject multiBox
		descClassName: 'mbDesc',//the class name of the description divs
		path: './Files/',//path to mp3 and flv players
		useOverlay: true,//use a semi-transparent background. default: false;
		maxSize: {w:900, h:1000},//max dimensions (width,height) - set to null to disable resizing
		addDownload: false,//do you want the files to be downloadable?
		pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
		addRollover: false,//add rollover fade to each multibox link
		addOverlayIcon: false,//adds overlay icons to images within multibox links
		addChain: false,//cycle through all images fading them out then in
		recalcTop: true,//subtract the height of controls panel from top position
		addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
	});
});

