/* =======================================



 -----------------------------------------
	INDEX
 -----------------------------------------
	1.histListup open-close
	2.keywordSearch value

========================================== */

/* 1.histListup open-close
========================================== */

$(function(){
    $(".histListup p.menuTool a").click(function(){
    	var	parents = $(this).parent().parent().parent();
    	$(parents.find("div")).toggle();
    	return false;
    });
});

/* 2.keywordSearch value
========================================== */
$(function(){
	/*
	$("#keywordSearch input").val(function(){
		if(this.value == ""){
		$(this).val("検索キーワード");
		}
	});
	*/
	
	$("#keywordSearch input").focus(function(){
		if(this.value == "検索キーワード"){
			$(this).toggleClass('input_color', true);
			$(this).val("");
		}
	});
	$("#keywordSearch input").blur(function(){
		if(this.value == ""){
			$(this).toggleClass('input_color', false);
			$(this).val("検索キーワード");
		}
	});
});

/* 3.relatedUnit open-close
========================================== */

$(function(){
    $(".relatedUnit p.menuTool a").click(function(){
    	var	parents = $(this).parent().parent().parent();
    	$(parents.find("div")).toggle();
        return false;
    });
});


/* 4.queryTools open-close
========================================== */
$(function(){
    $(".queryTools .standardMenu p.toolHandle a").click(function(){
    	var	parents_sortTools = $(this).parent().parent().parent();
    	var	parents_toolHandle = $(this).parent().parent();
    	$(parents_sortTools.find("div.sortTools")).toggle();
    	$(parents_toolHandle.find("p.toolHandle")).toggle();
    	return false;
    });
});

/* 5.change src
========================================== */

var active_number = 0;

function changeSizeViewerTarget() {
	//change the size of Floating Display from the viewerTaget
	$('#floatingDisplay .detailDisplay').width(($('#floatingDisplay #viewer_taget').width()) + 260);
}

function changeModalImage(num){
	var changeSrc = $('#floatingDisplay .imageUnit .target_base p.image img').get(num).src;
	$("#floatingDisplay #viewer_target").attr("src", changeSrc);
	$("#floatingDisplay ul.thumbnail li.active").removeClass("active");
	$("#floatingDisplay ul.thumbnail li").eq(num).addClass("active");
	$("span.currentImage").text((num+1) + " / " + $("#floatingDisplay ul.thumbnail li").size());
	changeSizeViewerTarget();
}

$(document).ready( function() {
	
	//デフォルト表示のサムネイルを選択/表示切替
	$('.detailSec .thumbnail img').each(function(i){
		$(this).click( function() {
			var changeSrc = this.src;
			$(".detailSec #target").attr("src", changeSrc);
			$("ul.thumbnail li.active").removeClass("active");
			$("ul.thumbnail li#" + $(this).parent().parent().attr("id")).addClass("active");
			active_number = i;
			return false;
		});
	});
	
	//拡大表示のサムネイルを選択/表示切替
	$('#floatingDisplay .thumbnail img').click( function() {
		active_number = $('#floatingDisplay .thumbnail img').index(this);
		changeModalImage(active_number);
		return false;
		
	});
	
	//拡大画像open
	$('#openModalWindow').click(function(e) {
		e.preventDefault();
		$("#floatingDisplay").modal({persist:true,onClose:closeModalWindow});
		$('html,body').animate({ scrollTop: 0 }, 'fast');
		changeModalImage(active_number);
	});
	
	//拡大画像 次へ
	$('.viewerFlip #next_target').click(function(){
		active_number += 1;
		if($("#floatingDisplay ul.thumbnail li").size() <= active_number){
			active_number = 0;
		}
		changeModalImage(active_number);
		return false;
	});
	
	//拡大画像 戻る
	$('.viewerFlip #prev_target').click(function(){
		active_number -= 1;
		if(0 > active_number){
			active_number = $("#floatingDisplay ul.thumbnail li").size() -1;
		}
		changeModalImage(active_number);
		return false;
	});

	$('#floatingDisplay .detailDisplay').click(function(){
		return false;
	});
	
	//拡大画像close
	/* callback close function */
	function closeModalWindow(dialog) {
		dialog.data.fadeOut('fast', function(){
			dialog.container.hide('fast', function () {
				dialog.overlay.slideUp('fast', function () {
					$.modal.close();
				});
			});
		});
	}

	//拡大画像open
	function openModalWindow (dialog) {
		dialog.overlay.fadeIn('fast', function () {
			dialog.container.fadeIn('fast', function () {
				dialog.data.hide().slideDown('fast');
				changeSizeViewerTarget();
			});
		});
	}
});

/* 6.queryTools open-close
========================================== */
$(function(){
	$("td.refHandle a").click(function(){
			$(this).parent().find("a").toggle();
			$(this).parent().parent().next("tr[class='reference'").toggle();
			return false;
    });
});

/* 7.position fixed for IE6 to smoothing scroll
========================================== */
$('html').css({
    'background-image':'url(null)',
    'background-attachment':'fixed'
});

/* 8.pngFix
========================================== */
$(document).ready(function(){ 
    /*$(document).pngfix();*/
    $(document).pngFix()
});

$(document).ready(function(){ 
   if ((jQuery.browser.msie && jQuery.browser.version < 7)) { 
        $("#headWrap").bgiframe();
    }
});


