jQuery.noConflict()(function($){

	var preLoadImg = new Object();

// メインメニュー
	$('body.news #mainmenunewsimg').css({opacity:"0"}).attr('src','/common_2010/pic/news-b_f2.gif').animate({opacity:"1"}, 1000 );
	$('body.newcar #mainmenunewcarimg').css({opacity:"0"}).attr('src','/common_2010/pic/newcar-b_f2.gif').animate({opacity:"1"}, 1000 );
	$('body.usedcar #mainmenuusedcarimg').css({opacity:"0"}).attr('src','/common_2010/pic/usedcar-b_f2.gif').animate({opacity:"1"}, 1000 );
	$('body.showroom #mainmenushowroomimg').css({opacity:"0"}).attr('src','/common_2010/pic/showroom-b_f2.gif').animate({opacity:"1"}, 1000 );
	$('body.inquiry #mainmenuinquiryimg').css({opacity:"0"}).attr('src','/common_2010/pic/inquiry-b_f2.gif').animate({opacity:"1"}, 1000 );

	$("#mainmenu li a").each(function(){
		$(this).hover(
			function() {
				$(this).find('img').animate({ 
				opacity: 0.75}, 250 );
			},
			function() {
				$(this).find('img').animate({ 
				opacity: 1}, 250 );
			}
		);
	});
	
// グローバルメニュー
	$("#groupmenu a img").each(function(){
		var imgSrc = this.src;
		var sep = imgSrc.lastIndexOf('.');
		var sepprev = sep;
		var chkstr = imgSrc.substr(sep - 3, 3);
		if(chkstr == '_f2') {sepprev = sepprev - 3}
		var onSrc = imgSrc.substr(0, sepprev) + '_f2' + imgSrc.substr(sep, 4);
		$(this).hover(
			function() {
				$(this).attr('src',onSrc);
			},
			function() {
				$(this).attr('src',imgSrc);
			}
		);
	});

// サイドコンテンツメニュー
	var current_pass='';
	var current_pass_arr=location.href.split("/");
	for(i=3;i<current_pass_arr.length;i++){
		current_pass=current_pass+'/'+current_pass_arr[i];
	}
	$("#sidecontents li a").each(function(){
		var href_pass=$(this).attr('href');
		if(current_pass == href_pass){
			$(this).css({'background-color':'#f1f1f1','color':'#999'});
		}
	});

// サイドバナー
	$(".sidebanner li a").each(function(){
		$(this).hover(
			function() {
				$(this).find('img').animate({ 
				opacity: 0.5}, 250 );
			},
			function() {
				$(this).find('img').animate({ 
				opacity: 1}, 250 );
			}
		);
	});

// ロールオーバー
	$("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);
			}
		);
	});

// トップページイメージ

	$('.home #mainimage img').each(function(idx){
		var imgSrc = this.src;
		$('.home #thumbimage').append('<img src="'+imgSrc+'" alt="" width="90" height="40" class="thumbnail" id="thumbnail'+idx+'" />');
	});
	$('.home #mainimage img:gt(0)').hide();
	$('.home #thumbimage img:eq(0)').css({opacity: 0.5});
	$('.home #thumbimage img').css({'cursor':'pointer'}).each(function(){
		var opcity_num;
		$(this).hover(function() {
			opcity_num=$(this).css('opacity');
			$(this).css({opacity: 0.75} );
			var thumb_id = $(this).attr('id');
			var thumb_no = thumb_id.substr(9,1);
			$('.home #mainimage img').hide();
			$('.home #mainimage img:eq('+thumb_no+')').fadeIn(500);
			$('.home #thumbimage img').css({opacity: 1});
			$(this).css({opacity: 0.5});
			opcity_num=$(this).css('opacity');
		},function() {
			$(this).css({opacity: opcity_num});
		}).click(function(){
			var thumb_id = $(this).attr('id');
			var thumb_no = thumb_id.substr(9,1);
			var imagelink=$('.home #mainimage img:eq('+thumb_no+')').parent('a').attr('href');
			var target=$('.home #mainimage img:eq('+thumb_no+')').parent('a').attr('target');
			if(imagelink&&!target){
				location.href=imagelink;
			}else if(imagelink){
				window.open(imagelink, target);
			}
		});
	});
	
// 新車

	$('#newcarlist').after('<p id="message"></p>');
	$('.newcar #newcarselect select').find('option:first').attr('selected','selected').end()
	.find('option:gt(1)').attr('selected','');
	$('.newcar #newcarselect select').change(
		function(){
			var dispflug = 0;
			var selecttype = $('.newcar select[name^="type"] option:selected').attr('value');
			var selectengine = $('.newcar select[name^="engine"] option:selected').attr('value');
			var selecteco = $('.newcar select[name^="eco"] option:selected').attr('value');
			var selectprice = $('.newcar select[name^="price"] option:selected').attr('value');
			$('#newcarlist > li').each(
			function(){
				$(this).css('display','none');
				var delay;
				var hit = 1;
				var classstr = $(this).attr('class');
				if(classstr.lastIndexOf(selecttype) < 0 && selecttype!='all') {
					hit=0;
				}
				if(classstr.lastIndexOf(selectengine) < 0 && selectengine!='all') {
					hit=0;
				}
				if(classstr.lastIndexOf(selecteco) < 0 && selecteco!='all') {
					hit=0;
				}
				if(classstr.lastIndexOf(selectprice) < 0 && selectprice!='all') {
					hit=0;
				}
				if(hit) {
					$(this).fadeIn(750);
					dispflug = 1;
				}
			});
			if(!dispflug) {
				$('#message').text('当てはまる車種はありませんでした。');
			} else {
				$('#message').text('※グレード・装備によりエコカー減税対象車とならない場合があります');
			}
		});
	$('#newcarlist > li > a').each(function(){
		var self = $(this);
		var alttext = self.parent().find('img').attr('alt')
		var carspec = self.parent().find('span.spec').html();
		self.hover(function(e){
			$(this).parent().find('img').animate({ 
			opacity: 0.5}, 250 ).attr('alt','');
			$("body").append('<div id="tooltip"><div class="tooltiptop">&nbsp;</div><div class="tooltipbody"><strong>'+alttext+'</strong><br />'+carspec+'</div><div class="tooltipbottom">&nbsp;</div></div>');
        	$("#tooltip").css({
				top: e.pageY+16,
				left: e.pageX+4
				}).fadeIn(250);
			},function(){
				$(this).parent().find('img').animate({ 
			opacity: 1}, 250 ).attr('alt',alttext);
				$("#tooltip").hide().remove();
		});
    	self.mousemove(function(e){
			$("#tooltip").css({
				top: e.pageY+16,
				left: e.pageX+4
			});
		});
	});
	$('#lineuplist > li > a').each(function(){
		var self = $(this);
		self.hover(function(){
			$(this).parent().find('img').animate({ 
			opacity: 0.5}, 250 );
			},function(){
				$(this).parent().find('img').animate({ 
			opacity: 1}, 250 );
		});
    	
	});


// トップページタブ
	var listheight = 0;
	var maxlistheight = 0;
	$('body.toppage #tabnewcar li').each(function(){
		listheight = $(this).height();
		if(listheight > maxlistheight) {
			maxlistheight = listheight;
		}
	});
	$('body.toppage #tabnewcar li').height(maxlistheight);
	$('body.toppage #tabnewcar').hide();
	$('body.toppage #tabcampaignh').css({'cursor':'pointer','position':'absolute','top':'0','left':'380px'}).attr('src','pic/campaign-h_f2.png').click(function() {
			$(this).attr('src','pic/campaign-h_f2.png');
			$('body.toppage #tabcampaign').fadeIn(500);
			$('body.toppage #tabnewcarh').attr('src','pic/newcar-h.png');
			$('body.toppage #tabnewcar').hide();
		});
	$('body.toppage #tabnewcarh').css({'cursor':'pointer','position':'absolute','top':'0','left':'510px'}).click(function() {
			$(this).attr('src','pic/newcar-h_f2.png');
			$('body.toppage #tabnewcar').fadeIn(500);
			$('body.toppage #tabcampaignh').attr('src','pic/campaign-h.png')
			$('body.toppage #tabcampaign').hide();
		});
	var tabheight=$('body.toppage #calendarbox').height();
	$('body.toppage .tabbox').css({'position':'absolute','top':'50px','left':'20px','overflow':'auto','width':'620px'}).height(tabheight-50);

// トップページコンテンツバナー
	$('body.toppage #contentsbannerbox img').hover(
			function() {
				$(this).animate({ 
    				opacity: 0.5}, 250 );
			},
			function() {
				$(this).animate({ 
    				opacity: 1}, 250 );
			})

// 地図
	$('#showroomlist li .showroomicon').css({'opacity':'0.25'});
	$('#showroomlist li').css({'cursor':'pointer'}).hover(
			function() {
				$(this).css({'background-color':'#fff'}).find('.showroomicon').animate({ 
    				opacity: 1}, 250 );
			},
			function() {
				$(this).css({'background-color':'transparent'}).find('.showroomicon').animate({ 
    				opacity: 0.25}, 250 );
			}).click(function() {
			var showroomlink=$(this).find('a').attr('href');
			location.href=showroomlink;
		});
	
	$('#showroomlist li .showroomicon').mouseover(
			function() {
				var topOffset=$('#showroomlist').height()/2-30;
				var divOffset = $('#showroomlist').offset().top;
				var pOffset = $(this).parent().parent('li').offset().top;
				var pScroll = pOffset - divOffset - topOffset;
				$('#showroomlist').animate({ 
    				scrollTop: '+=' + pScroll + 'px'}, 250 );
			});
});



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: true,//add rollover fade to each multibox link
		addOverlayIcon: true,//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)
	});
});

