(function($)
{
	
	
	
	$.fn.extend({
		topvisual: function(option)
		{
			var _self = $(this);
			if(_self.length ==0) return;
			var _imgs = [];
			var _btns = [];
			var _currentNum = 0;
			var ie6 = ($.browser.msie && $.browser.version.indexOf("6") != -1);
			var hostname = location.hostname;
			var btnbox = $("<div class='clearfix'></div>");
			var imagepath = '';
			btnbox.css("position", "absolute");
			btnbox.css("z-index", "100");
			switch(hostname) {
				case 'others.apollon.tbn':
					imagepath = '/brass';
					break;
				case 'others.turbine.cc':	
					imagepath = '/brass/html';
					break;
				default:
					imagepath = '';
					break;	
			}
			var btnOut = imagepath + "/image/btn_key.png";
			var btnOver = imagepath + "/image/btn_key_o.png";
			
			var sId;
			
			_self.find("> *").each(function(i){
				var c = $(this);
				c.css("position", "absolute");
				if(i != 0){
					c.css("opacity",0);
					c.css("z-index",0);
				} else {
					c.css("opacity",1);
					c.css("z-index",1);
				}
				btnbox.append(createBtn(i));
				_imgs.push(c);
			});
			
			changeBtnImage(0);
			
			_self.append(btnbox);
			sId = setInterval(timerHandler , 6000);
			
			var btnboxX = 715 - _btns.length * 26;
			var btnboxY = 375;
			btnbox.css("left",btnboxX + "px");
			btnbox.css("top",btnboxY + "px");
			
			//if(!ie6) _self.css("opacity",0).animate({opacity: 1},2000);
			
			function timerHandler(){
				_imgs[_currentNum].stop().animate({opacity: 0,"z-index":0},2000);
				_currentNum = _currentNum >= _imgs.length-1 ? 0 : _currentNum+1;
				_imgs[_currentNum].stop().animate({opacity: 1,"z-index":1},2000);
				changeBtnImage(_currentNum);
			}
			
			function createBtn(i){
				var btnhtml = "<div class='btn'><img src='"+ btnOut +"' width='16' height='17' /></div>";
				var btn = $(btnhtml);
				btn.css("width","16px");
				btn.css("height","17px");
				btn.css("margin-right","10px");
				btn.css("float","left");
				btn.data("_idx",i);
				btn.hover(
					function(){
						clearInterval(sId);
						sId = setInterval(timerHandler , 5000);
						
						_imgs[_currentNum].stop().animate({opacity: 0,"z-index":0},500);
						_currentNum = $(this).data("_idx");
						_imgs[_currentNum].stop().animate({opacity: 1,"z-index":1},500);
						changeBtnImage($(this).data("_idx"));
					}
				);
				_btns.push(btn);
				return btn;
			}
			
			function changeBtnImage(idx){
				for(i=0;i<_btns.length;i++){
					var img = $("img",_btns[i]);
					if(i == idx){
						img.attr("src",btnOver);
					} else {
						img.attr("src",btnOut);
					}
					
				}
			}
			
		}
	});
})(jQuery);


$(function(){

	
	
	
	//リサイズ
	function resizeHandler(){
		var stageWidth = $('html').outerWidth();
		var stageHeight = $('html').outerHeight();
		var dWrapper = $('div#dWrapper');
		var dLeftContents = $('div#dLeftContents');
		var dRightContents = $('div#dRightContents');
		var dPageTop = $('div#dPageTop');
		var dFooter = $('div#dFooter');
		var dNaviBtn = $('div.dNaviBtn');
		var ie6 = ($.browser.msie && $.browser.version.indexOf("6") != -1);
		var ie7 = ($.browser.msie && $.browser.version.indexOf("7") != -1);
		var w;
		w = stageWidth
			 - Number(dWrapper.css("padding-left").replace('px', '')) *1
			 - Number(dWrapper.css("margin-left").replace('px', '')) *1
			;
		w = w < 960 ? 960 : w;
		dWrapper.width(w);
		w = w - Number(dLeftContents.width())
			  - Number(dLeftContents.css("padding-left").replace('px', ''))
			  - Number(dLeftContents.css("margin-right").replace('px', ''))
			  - Number(dRightContents.css("margin-left").replace('px', ''))
			  ;
		w = w < 735 ? 735 : w;
		dRightContents.width(w - 30);
		dFooter.width( Math.floor(w/245) * 245 + dLeftContents.width() + Number(dRightContents.css("margin-left").replace('px', '')) - 10 );
		dNaviBtn.width(dFooter.width());
		
		if(ie7 || ie6){
			dPageTop.width(dFooter.width()-30);
			
		}else{
			dPageTop.width(dFooter.width());
			
		}
		
		
		
		
	}
	$(window).resize(function(e)
	{
		resizeHandler();
	});
	resizeHandler();
	
	var vg = $("#dGridContents").vgrid({
		easeing: "easeOutQuint",
		useLoadImageEvent: false,
		useFontSizeListener: false,
		time: 500,
		delay: 10,
		fadeIn: {
			time: 500,
			delay: 50
		},
		onStart: function(){
			
		},
		onFinish: function(){
			
		},
		priority:".priority",
		limitMinWidth:735,
		loading:true
	});

	
	
	
	
	
	
	//トップヴィジュアルの制御
	$("#dKeyVisual").topvisual();
});

