// JavaScript Document
$(function() {
	$('.row004 img').click(function(e) {
		//e.preventDefault();
	});
	$('.slide01 h2 a, .slide01 h3 a').each(function() {
		src = $(this).children('img').attr('src');
		
		bg_position = 'left top';
		//alert(bg_position);
		if(src) {
			src = src.replace(/.gif/, '1.gif');	
			if(src.match(/pages\/index\/images/)) {
				bg_position = 'left top';
			} else {
				bg_position = 'left 15px';
			}
		}
		//alert(bg_position);
		
		$(this)
		.css(
			{
				'background':'url(' + src + ')',
				'background-position':bg_position,
				'background-repeat':'no-repeat'
			}
		);
	});
	$('.slide01 h2, .slide01 h3').click(function(e) {
		
		e.preventDefault();
		
		
		if($(this).children().tagName == 'A') {
			offset = $(this).offset();
		
			offset_top = offset.top - 20;
			
			$('html, body').animate({'scrollTop':offset_top + 'px'});
				
		}
		
		if($(this).next('div').css('display') == 'block') {
			
			$(this).next('div').slideUp('slow',function() {
				
				$(this).prev().children('a').children('img').css({'opacity':'1'});		
			
			});
			
		} else {
			
			$(this).next('div').slideDown('fast');
			
			if($(this).siblings().find('iframe').length > 0) {
				
				no = $('iframe').index($(this).siblings().find('iframe'));
				src = $(this).siblings().find('iframe').attr('src');
				
				frames[no].location.href= src;
				
				
			}
			
			$(this).children('a').children('img').css({'opacity':'0'});
				
		}
	});
	$('.slide01 h2 a img, .slide01 h3 a img').mouseover(function(e) {
		
		$(this).css({'opacity':'0'});
	
	});
	
	$('.slide01 h2 a img, .slide01 h3 a img').mouseout(function(e) {
		
		var src;
		src = $(this).attr('src');
		
		if(src.match(/pages\/index\/images/)) {
			
			$(this).animate({'opacity':'1'}, 300);
			
		} else {
			
			if($(this).parent('a').parent().next().css('display') == 'block') {
			
				$(this).css({'opacity':'0'});	
			
			} else {
			
				$(this).animate({'opacity':'1'}, 300);
			
			}	
		}	
	});
	
	$('[href=print]').click(function(e) {
		e.preventDefault();
		
		no = $('[href=print]').index($(this));
		
		url = document.location.href;
		if(url.match(/\?/)) {
			para = '&';
		} else {
			para = '?';
		}
		
		//document.location.href=url + para + 'a=print&prints=' + no;
		window.open(url + para + 'a=print&prints=' + no);
			
	});
	
	$('.expand_collapse img').click(function(e) {
		e.preventDefault();
		if($(this).attr('class') == 'expand') {
			$('.box001').slideDown('fast');
			$('.slide01 h2 a img').css({'opacity':'0'});
			$('.slide01 h3 a img').css({'opacity':'0'});
			
			$('.slide01 iframe').each(function() {
				no = $('iframe').index($(this));
				src = $(this).attr('src');
				
				frames[no].location.href= src;
				
				
			});
			
		} else {
			
			$('.box001').slideUp('fast');
			$('.slide01 h2 img').css({'opacity':'1'});
		
		}
	});
	
	if(document.location.href.match(/&n3=/)) {
		url = document.location.href;
		plus2 = url.split("&n3=");
		array_count = plus2.length - 1;
		name_no = plus2[array_count];
		//alert(name_no);
		$('[name='+ name_no +']').parent().next().slideDown(function() {
			//alert(this.tagName);
			//alert($(this).parent()[0].tagName);
			offset = $(this).prev().offset();
			offset_top = offset.top;
			$('html, body').animate({'scrollTop':offset_top + 'px'});
		});
		
	}
	$('.ul02 img').click(function(e) {
		e.preventDefault();
		var ww, wh;
		ww = Number($('html').width() + $('html').scrollLeft());
		wh = Number($('html').height() + $('html').scrollTop());
		alert(ww + ' ' + wh);
		
		src = $(this).attr('src');
		src = src.replace(/\/s\//, '/l/');
		alert(src);
		//$('#popup_file').append($('img').attr('src', src));
		
		lefts = (Number(ww) - 800) * 0.5;
		//alert(ww - 800);
		tops = 200;
		//alert(lefts);
		$('#popup_file').css(
			{
				'position':'absolute',
				'top': tops + 'px',
				'left': lefts + 'px',
			}
		);
		
		$('#popup_bg').width(ww).height(wh).css({'opacity':'0.5'}).show();
		//$('#popup_bg').show();
		$('#popup_file').append('<img id="popup_main_image" src="' + src + '" width="800">');
		$('#popup_file').show();
	});
	
	$('.collapse2').click(function(e) {
		e.preventDefault();
		$(this).parents().each(function() {
			if($(this).attr('class')) {
				if($(this).attr('class') == 'box001') {
					$(this).slideUp('slow');
					
				}	
			}	
		});
	});
	$('#button_close2').click(function() {
		
	});
	$('#button_close').click(function() {
		alert('test');
		$('#popup_file').hide();
		$('#popup_bg').hide();
		$('#popup_main_image').attr('src','');
		$('#popup_main_image').remove();
	});
	
});

