jQuery.noConflict()(function($){

	var preLoadImg = new Object();

// メインメニュー
	$('body.group.home #mainhomeimg').css({opacity:"0"}).attr('src','/common_2009/pic/home-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.company #maincompanyimg').css({opacity:"0"}).attr('src','/common_2009/pic/company-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.service #mainserviceimg').css({opacity:"0"}).attr('src','/common_2009/pic/service-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.recruitment #mainrecruitmentimg').css({opacity:"0"}).attr('src','/common_2009/pic/recruitment-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.location #mainlocationimg').css({opacity:"0"}).attr('src','/common_2009/pic/location-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.inquiry #maininquiryimg').css({opacity:"0"}).attr('src','/common_2009/pic/inquiry-b_f2.jpg').animate({opacity:"1"}, 1000 );
	$('body.group.usedcar #mainusedcarimg').css({opacity:"0"}).attr('src','/common_2009/pic/usedcar-b_f2.jpg').animate({opacity:"1"}, 1000 );

	$("#mainmenu li a").each(function(){
		$(this).hover(
			function() {
				$(this).find('img').animate({ 
				opacity: 0.4}, 250 );
			},
			function() {
				$(this).find('img').animate({ 
				opacity: 1}, 250 );
			}
		);
	});
	
// グローバルメニュー
	$('body.group #globalgroupimg').attr('src','/common_2009/pic/global-group-b_f2.png');
	$('body.citroen #globalcitroenimg').attr('src','/common_2009/pic/global-citroen-b_f2.png');
	$('body.jaguar #globaljaguarimg').attr('src','/common_2009/pic/global-jaguar-b_f2.png');
	$('body.maserati #globalmaseratiimg').attr('src','/common_2009/pic/global-maserati-b_f2.png');
	$('body.lancia #globallanciaimg').attr('src','/common_2009/pic/global-lancia-b_f2.png');
	$("#globalmenu li > 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);
			}
		);
	});
	
// サイドバナー
	$("#sideshowroombanner li a").each(function(){
		$(this).hover(
			function() {
				$(this).find('img').animate({ 
				opacity: 0.5}, 250 );
			},
			function() {
				$(this).find('img').animate({ 
				opacity: 1}, 250 );
			}
		);
	});

// メインイメージ
	$("body.group #mainimage").append('<div class="shadow">&nbsp;</div>');

// 地図
	$('#globalmap ul li img').css('opacity','0.6');
	$('#globalmap ul li a').each(function(){
		var self = $(this);
		var alttext = self.find('img').attr('alt')
		var showroominfo = self.parent().find('span.info').html();
		self.hover(function(e){
			$(this).find('img').animate({ 
    				opacity: 1}, 500 ).attr('alt','');
			$("body").append('<div id="tooltip"><div class="tooltiptop">&nbsp;</div><div class="tooltipbody">'+showroominfo+'</div><div class="tooltipbottom">&nbsp;</div></div>');
        	$("#tooltip").css({
				top: e.pageY+16,
				left: e.pageX-110
				}).fadeIn(250);
			},function(){
				$(this).find('img').animate({ 
    				opacity: 0.6}, 500 ).attr('alt',alttext);
				$("#tooltip").hide().remove();
		});
    	self.mousemove(function(e){
			$("#tooltip").css({
				top: e.pageY+16,
				left: e.pageX-110
			});
		});
	});

// マトリックスメニュー
	$('.matrixmenu a').hover(
		function() {
			$(this).children("img").animate({ 
				opacity: 0.5}, 250 );
		},
		function() {
			$(this).children("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);
			}
		);
	});

// トップページ リンク
	$('body.group.toppage .showroominfo').css('cursor','pointer').each(function(){
		var position = $(this).attr('id').indexOf("box",0)
		var showroom_name = $(this).attr('id').substr(0,position);
		$(this).hover(function(){
			$(this).css('opacity','0.5');
			$('#'+showroom_name+'image').css('z-index','20').animate({ 
    				height: 400}, 250 );
		},function(){
			$(this).css('opacity','1');
			$('#'+showroom_name+'image').css('z-index','10').animate({ 
    				height: 0}, 250 );
		})
	}).click(function(){
		var showroomsitelink=$(this).find('a').attr('href');
		location.href=showroomsitelink;
	});


// トップページ ニュース高さ合わせ
	var showroombox_ul_max_height = 0;
	var showroombox_ul_height;
	$('body.group.toppage .showroombox ul').each(function(){
		var showroombox_ul_height = $(this).height();
		if(showroombox_ul_height > showroombox_ul_max_height){
			showroombox_ul_max_height = showroombox_ul_height;
		}
	}).height(showroombox_ul_max_height);


	
});


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)
	});
});
