$(function() {
	//smartRollover

	var imgCount = 0;
	var images_pre = [];
	$('img[src*="_off."],input[src*="_off."]').each (function(){
		images_pre[imgCount] = new Image();
		images_pre[imgCount].src = $(this).attr("src").replace("_off.", "_on.");
		$(this).hover(
			function() {
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			},
			function() {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
			}
		);
		imgCount ++;
	});



	// opacity Rollover

	$('img[src*="_op."],input[src*="_op."], .movie_list img, #newsList img, .movie_banner a > img').hover(
		function() {
			$(this).css('opacity', 0.7);
		},
		function() {
			$(this).css('opacity', 1);
		}
	);



	// external

	var notBlank = new Array(""),
		n = "";
	for (var i = 0; i < notBlank.length; i ++) if(notBlank[i]) n += ":not([href*='" + notBlank[i] + "'])";
	if(document.domain) n += ":not([href*='" + document.domain + "'])";

	$("a[rel='external'], a[href$='.pdf']").attr("target", "_blank");
	$("a[href^=http]"+n).attr("target", "_blank");

	if(!location.href.match(/^http/)){
		$("a[href$='/']").not("a[href^='http']").each( function(){
			$(this).attr('href', $(this).attr('href') + 'index.html');
		});
		$("a[href*='/#']").not("a[href^='http'],a[href$='.html']").each( function(){
			var n = $(this).attr('href').lastIndexOf("/#") + 1;
			$(this).attr('href', $(this).attr('href').substring(0, n) + 'index.html' + $(this).attr('href').substring(n));
		});
	}



	// smoothScroll

//	$('a[href^=#]').each (function(){
//		var hash = this.hash;
//		if(hash.length > 1 && !this['rel']){
//			$(this).click(function() {
//				smoothScroll(hash);
//				return false;
//			})
//		}
//	});

	
	//fancybox

	$("#openPolicy, #openPolicy2, #for_en, #for_ja").fancybox({
		'overlayOpacity' : 0.85,
		'overlayColor' : "#000000"
	});
	
	$("#special a[rel=group]").fancybox({
		'overlayOpacity' : 0.85,
		'overlayColor' : "#000000"
	});

});


//function smoothScroll(hash) {
//	var target = $(hash).offset().top;
//
//	$(($.browser.safari) ? 'body' : 'html')
//		.animate({scrollTop: target >= 15 ? target - 15 : target}, 600, 'swing', function(){$(this).unbind("mousewheel DOMMouseScroll");})
//		.bind("mousewheel DOMMouseScroll",function(){
//			$(this).queue([]).stop();
//			$(this).unbind("mousewheel DOMMouseScroll");
//		})
//}
function optionSelected() {
	var uri = $(location).attr('href');
	$('option').each(function() {
		var option_value = $(this).attr('value');
		if(uri == option_value){
			$(this).attr('selected', 'selected');
		}
	});
}
function fixfloat() {
	var ele = '.flat';
	var wrapEle = $(ele).parent().width();
	var outerW = $(ele + '> *').outerWidth('margin', true);
	var thisW = $(ele + '> *').width();
	var mr = outerW - thisW;
	var setWidth = wrapEle + mr;
	var childSize = $(ele + '> *').size();
	var columnN = Math.floor(setWidth / outerW);
	$(ele + '> *:nth-child('+ columnN + "n" +')').css('margin-right', 0);
	
	$(ele).each(function(i){	
		$(this).addClass('f-' + i);
		var childSize = $('.f-' + i + ' > *').size();
		if(childSize > 2){
			//$('.f-' + i + ' > *').css("float", "left");
			$('.f-' + i + ' > :last-child').addClass("last");
		}
		else if(childSize == 1) {
			$('.f-' + i + ' > :first-child').css("float", "left");
		}
		else {
			$('.f-' + i + ' > :first-child').css("float", "left");
			$('.f-' + i + ' > :last-child').css("float", "right").addClass("last");
		}
	});
}
