$(document).ready(function(){ 
	$("#menu li a").css({"opacity": "1"}).hover(
		function(ev){
			$(this).stop();
			$(this).css({"cursor": "pointer"}).animate( {marginLeft: "10px", "opacity": "1"}, "fast" , "easeOutCubic" )},
		function(ev){
			$(this).stop();
			$(this).css({"cursor": "pointer"}).animate({marginLeft: "0px", "opacity": "1"}, "fast" , "easeOutCubic",
		function(){
		})
	});	
	$('#ticker').innerfade({
		speed: 1000,
		timeout: 6000,
		type: 'random',
		containerheight: '1em'
	});
	$('li.headlink').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	);
	if (typeof document.documentElement.style.maxHeight != "undefined") {
		/*$(function(){
			$('#menu').tabSlideOut({
			 imageHeight: '102px',                               //height of tab image *required*
			 imageWidth: '25px',                               //width of tab image *required*    
			 tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
			 speed: 2000,                                        //speed of animation
			 action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
			 topPos: '0px',
			 fixedPosition: true,                               //options: true makes it stick(fixed position) on scroll
			 onLoadSlideOut: true
			});
		});*/
		var cf = new Crossfader( new Array('bg01' , 'bg02' , 'bg03' , 'bg04' , 'bg05'), 500, 5000 );
	}
	else {
		var cf = new Crossfader( new Array('bg01' , 'bg02' , 'bg03' , 'bg04' , 'bg05'), 500, 5000 );
	}
	//alpha btn
	$(".alphabtn,.alphabtn img").hover(function(){
		$(this).stop();
		$(this).animate( { opacity:0.7 }, 500 , "easeOutCubic");
	},function(){
		$(this).stop();
		$(this).animate( { opacity:1 }, 500 , "easeOutCubic");
	});
	
//	$(function() {
//		var num = 1;
//		$('#logo li.logobtn')
//		//マウスオーバー画像を配置
//		.each(function(){
//			$(this).css('background', 'url(/images/logo0'+num+'.gif) no-repeat 0px -60px')
//			num++;
//		})
//		.find('img').hover(
//			function(){  
//				$(this).stop().animate({'opacity' : '0'}, 500);  
//			},
//			function(){
//				$(this).stop().animate({'opacity' : '1'}, 1000);
//			}
//		); 
//	});
	$(window).resize(function(){
		//alert("test")
		onResizeHandler();
	});
	
	//smooth scroll
    $('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') &&　location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length && target;
            if (target.length) {
                var sclpos = 30;
                var scldurat = 1200;
                var targetOffset = target.offset().top - sclpos;
                $('html,body')
                    .animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
                return false;
            }
        }
    });
});
$.event.add(window, "load", function(){
	onResizeHandler();
	$(".alpha").animate( { opacity:1 }, 2000 , "easeOutCubic");
	loadSWF();
	//$("#menu").animate( { width: "70%", opacity: 1, marginLeft: "0px" }, 3000 , "easeOutCubic" );
});
function getActualDimension(image) {
	var run, mem, w, h, key = "actual";
 
	// for Firefox, Safari, Google Chrome
	if ("naturalWidth" in image) {
		return {width: image.naturalWidth, height: image.naturalHeight};
	}
	if ("src" in image) { // HTMLImageElement
		if (image[key] && image[key].src === image.src) {return  image[key];}
		 
		if (document.uniqueID) { // for IE
			w = $(image).css("width");
			h = $(image).css("height");
		} else { // for Opera and Other
			mem = {w: image.width, h: image.height}; // keep current style
			$(this).removeAttr("width").removeAttr("height").css({width:"",  height:""});    // Remove attributes in case img-element has set width  and height (for webkit browsers)
			w = image.width;
			h = image.height;
			image.width  = mem.w; // restore
			image.height = mem.h;
		}
		return image[key] = {width: w.replace("px",""), height: h.replace("px",""), src: image.src}; // bond
	}
	 
	// HTMLCanvasElement
	return {width: image.width.replace("px",""), height: image.height.replace("px","")};
}
function fullscreen( ){
	var maxheight = 700;
	$("body").height( Math.max( 700 , $(window).height()) );
	$("#wrap").height( Math.max( 700 , $(window).height()) );
	$("#background").width( Math.max( 1150 , $(window).width()) );
	$("#background").height( Math.max( 700 , $(window).height()) );
	var idarray = new Array("bg01","bg02","bg03","bg04","bg05");
	for( var i = 0; i < idarray.length; i++ ){
		var canvas = document.getElementById(idarray[i]);
		if(canvas){
			$(canvas).width( $("#background").width() );
			var scaleX = $(canvas).width() / getActualDimension(canvas).width;
			$(canvas).height( getActualDimension(canvas).height*scaleX );
		
			if( $(canvas).height() < $("#background").height() ){
				$(canvas).height( $("#background").height() );
				var scaleY = $(canvas).height() / getActualDimension(canvas).height;
				$(canvas).width( getActualDimension(canvas).width*scaleY );
			}
			$(canvas).css( { "position":"absolute","top":( $("#background").height() - $(canvas).height() ) / 2 , "left":( $("#background").width() - $(canvas).width() ) / 2 } );
			
		}
	}
	
	$("#footer").css( {"top": $("#background").height() - $("#footer").height()} );
}
function onResizeHandler(){
if (document.querySelectorAll) {
	fullscreen();
	$("#container-inner").height($(window).height()-$("#header").height()-$("#footer").height());
	//$("#menu").height($(window).height()-$("#footer").height());
}
else {
	fullscreen();
}
}

(function($){
	$.fn.extend({
		tagdrop: function(options) {
			var defaults = {
				tagPaddingTop: '30px',
				tagDefaultPaddingTop: '0px',
				bgColor: '#FFFFFF',
				bgMoverColor: '#FFFFFF',
				textColor: '#e0e0e0',
				textDefaultColor: '#fff'
			};
			var options = $.extend(defaults, options);

			return this.each(function() {
				var obj = $(this);
				var li_items = $("li", obj);
				$("li", obj).css('background-color', options.bgColor);
				
				li_items.mouseover(function(){
					$(this).stop();
					$(this).animate({paddingTop: options.tagPaddingTop}, 150);
					$(this).css('background-color', options.bgMoverColor);
					$(this).css('background-position', 'left bottom');
				}).mouseout(function() {
					$(this).stop();
					$(this).animate({paddingTop: options.tagDefaultPaddingTop}, 150);
					$("li",$(this).parent()).css('background-color', options.bgColor);
					$("li",$(this).parent()).css('color', options.textDefaultColor);
				});
			});
		}
	});
})(jQuery);
