﻿$(document).ready(function(){
	
	//----------------------------------------
	//
	// NEWS
	//
	// [ToolTip] http://flowplayer.org/tools/tooltip/index.html
	// [Fade] http://www.skuare.net/test/jintervalfade.html
	//
	//----------------------------------------

	//--------------------
	// ToolTip
	//--------------------
	$("ul#news_list li").tooltip({
		position: 'top center',
		offset: [170, 0],
		delay: 30,
		effect: "toggle"
	});
	
	//--------------------
	// Fade
	//--------------------
	var intId = 0;
	function initNews(){
		if (intId != 0) {
			clearInterval(intId);
			intId = 0;
		}
		$('#news_list li').hide();
	}
	function startNews(){
		if (intId != 0) {
			initNews();
		}
		var i = 0;
	    intId = setInterval(function(){ 
		    var list = $('#news li').length;
		    if (i >= list){
		        clearInterval(intId);
				intId = 0;
		    }
		    $('#news_list li').eq(i).fadeIn(1000);
		    i++;
		}, 100);
	};
	$('#news_list li').hide();

	//----------------------------------------
	//
	// BLOG
	//
	// [ImageOverlay] http://www.ferretarmy.com/files/jQuery/ImageOverlay/ImageOverlay.html
	// [QBox] http://www.skuare.net/test/jqBox.html
	//
	//----------------------------------------

	//--------------------
	// ImageOverlay
	//--------------------
	//$('#blog_list').ImageOverlay({
	//	overlay_speed: 'fast',
	//	overlay_speed_out: 'slow',
	//	overlay_origin: 'bottom'
	//});
	
	//--------------------
	// QBox
	//--------------------
	function initQbox(){
		$('ul#blog_list').qbox({ 
			slide: { 
			    effect:    'linear',  // エフェクト指定
			    duration:  500,       // 動作間隔
			    from:      'all',     // スライド位置（all, top, right, bottom or left）
			    by:        'asc'      // スライド順序（random, asc or desc）
			},                          
			box: { 
			    selector: 'li',       // 要素指定 
			    rows:     4,          // 行数 
			    cols:     5           // 列数 
			}, 
			qtime: { 
			    interval: 2,          // スライド前の秒数 
			    step:     1000        // スライド時間 
			} 
		});
	}
	function stopQbox(){
		if($('ul#blog_list').qbox().isRunning()){
			$('ul#blog_list').qbox().pause();
		}
	}
	function startQbox(){
		if(!$('ul#blog_list').qbox().isRunning()){
			$('ul#blog_list').qbox().resume();
		}
	}
	initQbox();
	stopQbox();
	
	//----------------------------------------
	//
	// SLIDE(Menu)
	//
	//----------------------------------------
	var isInitialDisplay = true;
	$('.navigation li #movie_link').hover(function(){
		isInitialDisplay = false;
		stopQbox();
		$('.navigation li #feature_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #news_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #blog_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #books_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #movie_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
	});
	$('.navigation li #feature_link').hover(function(){
		isInitialDisplay = false;
		stopQbox();
		$('.navigation li #movie_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #news_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #blog_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #books_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #feature_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
	});
	$('.navigation li #news_link').hover(function(){
		isInitialDisplay = false;
		stopQbox();
		$('.navigation li #movie_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #feature_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #blog_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #books_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #news_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
	});
	$('.navigation li #blog_link').hover(function(){
		isInitialDisplay = false;
		$('.navigation li #movie_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #feature_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #news_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #books_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #blog_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
	});
	$('.navigation li #books_link').hover(function(){
		isInitialDisplay = false;
		stopQbox();
		$('.navigation li #movie_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #feature_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #news_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #blog_img').animate({marginLeft:'-140px'}, {queue:false, duration:200});
		$('.navigation li #books_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
	});
	
	//----------------------------------------
	//
	// SLIDE(Contents)
	//
	// [Coda Slider Effect] http://jqueryfordesigners.com/coda-slider-effect/
	//
	//----------------------------------------

	//--------------------
	// Coda Slider Effect
	//--------------------
    var $panels = $('#wrapper .scrollContainer > div');
    var $container = $('#wrapper .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = false;

    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });

        // calculate a new width for the container (so it holds all panels)
        $container.css('width', $panels[0].offsetWidth * $panels.length);
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#wrapper .contents').css('overflow', 'hidden');

    // handle nav selection
    function selectNav() {
        $(this)
            .parents('ul:first')
                .find('a')
                    .removeClass('selected')
                .end()
            .end()
            .addClass('selected');
    }

    $('#wrapper .navigation').find('a').click(selectNav);

	function beforeProc(){
		if(!$('div #movie').is(':visible')) $('div #movie').show();
		if(!$('div #feature').is(':visible')) $('div #feature').show();
		if(!$('div #news').is(':visible')) $('div #news').show();
		if(!$('div #blog').is(':visible')) $('div #blog').show();
		if(!$('div #books').is(':visible')) $('div #books').show();
	}
	
    // go find the navigation link that has this target and select the nav
    function trigger(data) {
		
		if(isInitialDisplay){
			isInitialDisplay = false;
			$('.navigation li #' + data.id + '_img').animate({marginLeft:'0px'}, {queue:false, duration:200});
		}
		
		var el = $('#wrapper .navigation').find('a[href$="' + data.id + '"]').get(0);
        selectNav.call(el);
		
		if(data.id === 'movie'){
			initNews();
			$('div #feature').hide();
			$('div #news').hide();
			$('div #blog').hide();
			$('div #books').hide();
		}else if(data.id === 'feature'){
			initNews();
			$('div #news').hide();
			$('div #blog').hide();
			$('div #books').hide();
		}else if(data.id === 'news'){
			startNews();
			$('div #blog').hide();
			$('div #books').hide();
		}else if(data.id === 'blog'){
			startQbox();
			initNews();
			$('div #books').hide();
		}else if(data.id === 'books'){
			initNews();
		}
	}

    if (window.location.hash) {
        trigger({ id : window.location.hash.substr(1) });
    } else {
        $('ul.navigation a:first').click();
    }

    // offset is used to move to *exactly* the right place, since I'm using
    // padding on my example, I need to subtract the amount of padding to
    // the offset.  Try removing this to get a good idea of the effect
	var offset = parseInt((horizontal ? 
        $container.css('paddingTop') : 
        $container.css('paddingLeft')) 
        || 0) * -1;

    var scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.left', 
        next: 'img.right',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onBefore: beforeProc,
		
        onAfter: trigger, // our final callback

        offset: offset,

        // duration of the sliding effect
        duration: 500,

        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'swing',

        // trigger event
        event: 'mouseover'
    };

    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#wrapper').serialScroll(scrollOptions);

    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $.localScroll(scrollOptions);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);
});
			$(document).ready(function(){
				
				//Full Caption Sliding (Hidden to Visible)
				$('.boxgrid.captionfull').hover(function(){
					$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
				}, function() {
					$(".cover", this).stop().animate({top:'150px'},{queue:false,duration:300});
				});
				
			});
