$(function(){
		   
	var curPath = location.href;
	var curHost = location.hostname;

		   
	$('.pBoxFix .box').flatHeights();
	/*$('#classifies .box').each(function(){
		var imgSrc = $('.contentsDetail img',this).attr('src');
		$(this).hover(function(){
	
			if(imgSrc.match(/(.*)\.(jpg|gif|png)$/)){
				var repSrc = RegExp.$1+'_f2.'+RegExp.$2;
				$('.contentsDetail img',this).attr('src',repSrc);
			}
			
			$(this).addClass('link')
					.css({cursor:'pointer'})
					.click(function(){
						window.location.href = $('a',this).attr('href');
					});
		   
		},function(){
			$(this).removeClass('link');
			$('.contentsDetail img',this).attr('src',imgSrc);
		});
	});*/
	
	addLink('.boxhover','.box','link','.contentsDetail img');
	
	addLink('.linkparent','tr','link');
	
	addLink('#searchResult','.searchbox','link');
	
	addLink('.column4','.col','link');
	
	$('#navi #naviInner > ul > li').addClass('showNav');
	$('.showNav ul').hide();
	//$('#navi .current').parents().show();
	$('#navi .current').parent().children().show();
	$('#navi .parentsLink').parent().children().show();
	
	
	
	// 2010-12-06
	if(curPath.match("(\/visa\/|\/uc\/|\/jcb\/|\/aauc\/|brand\/visa|brand\/jcb|brand\/uc)") != null || curPath == 'http://'+curHost+'/aa/'){
		
		$('#footerLeft li:not(:last) a').attr('target','_blank');
		$('#footerLeft li:not(:first,:last) a').each(function(){
			var url = $(this).attr('href');
			url = url.replace('http://'+curHost+'/','');
			url = 'http://'+curHost+'/static/'+url;
			$(this).attr('href',url);
		});
	}
	
	
	//2010-09-29
	$('#genreSearch').find('form').submit(function(){
		var genre = $('select',this).val();
		var allGenre = $('#travelTopics').find('.columnThree');
		if(genre != ''){
			allGenre.hide();
			$(genre,'#travelTopics').show();
		}else{
			allGenre.show();
		}
		return false;
	});
	
	//2011-02-08
	$('#searchTab h2,#searchTab a').click(function(){
		$('#searchTabOuter').toggleClass('show');
		return false;
	});
	
	//2011-06-28 up
	$('#navi a ,#classifiesImg h2 a, #classifiesNet h2 a, #sitemap li a').each(function(){
		var $self = $(this);
		var url = $self.attr('href');
	
		switch(url){
			case "http://"+curHost+"/service/gold_member/insurance2/":
			$self.attr('href',"http://"+curHost+"/service/insurance/");
			break;
			case "http://"+curHost+"/card_utilization/payment/suica/":
			$self.attr('href',"http://"+curHost+"/service/web_service/digitalmoney.html");
			break;
		}
	
	});


	
});

window.onload = function(){
	var sets = [], temp = [];
	var column2Obj = '.columnTwo .box, .pBoxFix2 box';
	$(column2Obj).each(function(i) {
		temp.push(this);
		if (i % 2 == 1) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);

	$.each(sets, function() {
		$(this).flatHeights();
	});
	
	/*sets = [], temp = [];
	var column3Obj = '#systemColumn .box,.columnThreeBg .box';
	$(column3Obj).each(function(i) {
		temp.push(this);
		if (i % 3 == 2) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);

	$.each(sets, function() {
		$(this).flatHeights();
	});*/
	
	$('.column4 .col h2').flatHeights();
	
	sets = [], temp = [];
	var column4Obj = '.column4 .col';
	$(column4Obj).each(function(i) {
		temp.push(this);
		if (i % 4 == 3) {
			sets.push(temp);
			temp = [];
		}
	});
	if (temp.length) sets.push(temp);

	$.each(sets, function() {
		$(this).flatHeights();
	});
}

function addLink(linkParent,linkBox,linkClass,imgClass){
	if($('body').find(linkParent)){
		$(linkParent+' '+linkBox).each(function(){
			if(imgClass != undefined){
				var imgSrc = $(imgClass,this).attr('src');
			}
			$(this).hover(function(){
				$(this).addClass(linkClass)
						//.css({cursor:'pointer'})
						/*.click(function(){
							window.location.href = $('a',this).attr('href');
							//$('a',this).trigger('click');
						})*/;
				if(imgClass != undefined){
					var repSrc = imgSrc.replace(new RegExp('(.*)\.(jpg|gif|png)$'), "$1"+ '_f2.' +"$2");
					$(imgClass,this).attr('src',repSrc);
				}
			},function(){
				$(this).removeClass(linkClass);
				if(imgClass != undefined){
					$(imgClass,this).attr('src',imgSrc);
				}
			});
		});
	}
}


