/*------------------------------------- 
 function.js
 1.ロールオーバー
 2.ページ内スクロール
 3.セルフリンク
 4.隠れメニュー
 5.キャプション
-------------------------------------*/  

//1.ロールオーバー

function initRollOvers() {
	if (!document.getElementById){
		return;
	}
	
	var preLoads = new Array();
	var allImages = document.getElementsByTagName('img');

	for (var i = 0; i < allImages.length; i++) {		
		if (allImages[i].className == 'rollover') {
			var src = allImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var oSrc = src.replace(ftype, '_o'+ftype);

			//-- スワップ元、スワップ先画像の登録
			allImages[i].setAttribute('pSrc', src);
			allImages[i].setAttribute('oSrc', oSrc);

			//-- イメージのプリロード
			preLoads[i] = new Image();
			preLoads[i].src = oSrc;

			//-- イベントの設定
			allImages[i].onmouseover = function() {
				this.setAttribute('src', this.getAttribute('oSrc'));
			}
			allImages[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('pSrc'));
			}
		}
	}
}


//2.ページ内スクロール

// Easingの追加  
jQuery.easing.quart = function (x, t, b, c, d) {  
    return -c * ((t=t/d-1)*t*t*t - 1) + b;  
};  
  
/*------------------------------------- 
 ページ読み込み中 
-------------------------------------*/  
jQuery(document).ready(function(){  
  
//
// <a href="#***">の場合、スクロール処理を追加  
//
jQuery('a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = jQuery(this.hash);
            $target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
            if ($target.length) {  
                var targetOffset = $target.offset().top;
                jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
                return false;  
            }
        }
				});
});

function addOnload(func){
	if ( typeof window.addEventListener != "undefined" ){
		window.addEventListener( "load", func, false );
	}else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent( "onload", func );
	}else{
		if ( window.onload != null ){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
			oldOnload( e );
			window[func]();
		};
	}else
		window.onload = func;
	}
}
addOnload(initRollOvers);


//3.セルフリンク

$(document).ready( function() {
    $("#assist_nav a").each( function() {
        var url = document.URL.split("#");

        if ( this == url[0] || this + "index.html" == url[0]) {
            $(this).parent().addClass("current");
        }
    });
});

//

/*// 4.隠れメニュー

	$(function(){
	  $(".abajo").fixedTo({"posicion":"bottom","ancho":960,"alto":30,"ocultar":true});
	  $(".izquierda").fixedTo({
    	"posicion":"left",
		"ancho":360,
		"alto":70,
		"ocultar":true,
		"animar":true
	  });
 	 $(".especial").animate({"opacity":.9});
	});
	
//*/

// 5.キャプション
	$(document).ready(function () {

		// transition effect
		style = 'easeOutQuart';

		// if the mouse hover the image
		$('.photo').hover(
			function() {
				//display heading and caption
				$(this).children('.caption').stop(false,true).animate({bottom:0},{duration:200, easing: style});
				
			},

			function() {
				//hide heading and caption
				$(this).children('.caption').stop(false,true).animate({bottom:-70},{duration:200, easing: style});
			}
		);
    function move_image_overlay(object,side){
      jQuery(object).find('.go_left_button').hide();
      jQuery(object).find('.go_right_botton').hide();
      if(side == 'left'){
        if(!jQuery(object).children('ul').first().hasClass('active')){
          jQuery(object).children('ul.active').removeClass('active').prev().addClass('active');
        }
        jQuery(object).find('.go_right_botton').show();
      }
      else{
        if(side == 'right'){
          if(!jQuery(object).children('ul').last().hasClass('active')){
            jQuery(object).children('ul.active').removeClass('active').next().addClass('active');
          }
          jQuery(object).find('.go_left_button').show();
        }
      }
      if(jQuery(object).children('ul:first').hasClass('active')){
        jQuery(object).find('.go_left_button').hide();
      }
      if(jQuery(object).children('ul:last').hasClass('active')){
        jQuery(object).find('.go_right_botton').hide();
      }
    }
    jQuery('.media_content').each(function(){
      if(jQuery(this).children('ul').length <= '1'){
        jQuery(this).find('.go_left_button').hide();
        jQuery(this).find('.go_right_botton').hide();
      }
    });
   
    jQuery('.go_left_button').bind('click',function(){
      move_image_overlay(jQuery(this).parents('.media_content'),'left');
    });
    jQuery('.go_right_botton').bind('click',function(){
      move_image_overlay(jQuery(this).parents('.media_content'),'right');
    });

    jQuery('#change_captcha_image').bind('click',function(){
      jQuery('#captha_image').attr('src',"php-libs/securimage/securimage_show.php?"+Math.random());
    });
	});
//

// 6. ボックスリンク

$("div.photo li").click(function(){
  window.open($(this).find("a").attr("href"), '_blank');
  return false;
});

//

