// window
function winOpen(Aurl,Aname,Awidth,Aheight,Atoolbar,Alocation,Astatus,Ascroll,Amenu,Aresize){
 Astr = "width=" + Awidth;
 Astr+= ",height=" + Aheight;
 if(Atoolbar)Astr+= ",toolbar";
 if(Alocation)Astr+= ",location";
 if(Astatus)Astr+= ",status";
 if(Ascroll)Astr+= ",scrollbars";
 if(Amenu)Astr+= ",menubar";
 if(Aresize)Astr+= ",resizable";
 window.open(Aurl,Aname,Astr);
}
function winClose() {
window.close();
}


// Mouse over
(function(onLoad) {
	try {
		window.addEventListener('load', onLoad, false);
	} catch (e) {
		window.attachEvent('onload', onLoad);
	}
})(function() {
	var tags = ["img","input"];
	for( var i=0, len=tags.length; i<len; i++ ) {
		var over = function() { this.src = this.src.replace('_d.', '_h.'); };
		var out  = function() { this.src = this.src.replace('_h.', '_d.'); };
		var el = document.getElementsByTagName(tags[i]);
		for (var j=0, len2=el.length; j<len2; j++) {
			var attr = el[j].getAttribute('src');
			if (!el[j].src.match(/_d\./)&&attr) continue;
			el[j].onmouseover = over;
			el[j].onmouseout  = out;
		}
	}
});



// Slider
$(document).ready(function() {
 
	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".image_area").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
 
		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});


// uchinoko menu
$(function() {  
	$(".backnumber dd:not(.open)").hide();
	$(".backnumber dt").click(function() {
		$(".backnumber dd:visible").slideUp("slow");
		if(!$($(this).next()).is(':visible')) {
			$(this).next().slideDown("slow");
		}
		return false;
	});
});


// uchinoko change image
$(document).ready(function (){
    if($('#photo')){
       
        $('ul#list img').each(function(i){
            var myhref = $(this).attr('src').replace("IMAGES_S","IMAGES_L");
            var myalt = $(this).attr('alt');
            var myheight = 380;
            var mywidth = 570;
            var imgs = $("<img></img>").attr({
                  'src': myhref,
                  'title': myalt,
                  'class': 'change',
                  'alt': myalt,
                  'id': 'view-'+i,
                 'height':myheight,
                  'width':mywidth
            });
            imgs.css({
                position:'absolute',
                top:'26px',
                left:'59px'
            });
            imgs.hide();
            $('#view').append(imgs);
            $(this).click(function(){
                $('#view').css({
                    'width': mywidth,
                    'height': myheight
                });
                $('#view img').hide();
                $('#view-'+i).fadeIn();
            });
        });
    }
});


// usanews tab
$(function(){
			$("ul.tab_navi li a").focus(function(){
				$(this).blur();
			});
})
$(function(){
				if(0 < $("a.selected img").size()){
					$("a.selected img").attr("src",$("a.selected img").attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_on$2"));
					$("#tab_box div:not("+$("ul.tab_navi li a.selected").attr("href")+")").hide();
				}

				$("ul.tab_navi li a").click(function(){
					var name1=$("ul.tab_navi li a.selected").attr("href");
					$("a.selected img").attr("src",$("a.selected img").attr("src").replace(/^(.+)_on(\.[a-z]+)$/,"$1$2"));
					$("ul.tab_navi li a").removeClass("selected");
					$(this).addClass("selected");
					$("img",this).attr("src",$("img",this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/,"$1$2"));
					$("img",this).attr("src",$("img",this).attr("src").replace(/^(.+)(\.[a-z]+)$/,"$1_on$2"));
					$(name1).slideUp(500,function(){
							var name2=$("ul.tab_navi li a.selected").attr("href");
							$(name2).slideDown(500);
				});
				return false;
			})
})
$(function(){
		   $("ul.tab_navi a").mouseover(function(){
				var className = $(this).attr('class');
				if(className!='selected'){
					$("img",this).attr("src",$("img",this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))									
				}
				}).mouseout(function(){
				var className2 = $(this).attr('class');
				if(className2!='selected'){
						$("img",this).attr("src",$("img",this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/,"$1$2"))
				}
			})
})


// omikuji
$(function() {
	$("#omikuji p.img01").click(function() {

		$('#omikuji p.img01').fadeOut(500,function(){
			$('#omikuji p.img02').fadeIn(500).fadeOut(500,function(){
				$('#omikuji p.img03').fadeIn(500).fadeOut(500,function(){
					$('#omikuji p.img02').fadeIn(500).fadeOut(500,function(){
						$('#omikuji p.img03').fadeIn(500).fadeOut(500,function(){
							$('#omikuji p.img04').fadeIn(2000).fadeOut(3000,function(){
								$('#omikuji p.img05').fadeIn(3000,function(){
									$('#omikuji p.txt01').fadeIn(500,function(){
										$('#omikuji p.txt02').fadeIn(500,function(){
											$('#omikuji p.txt03').fadeIn(500,function(){
												$('#omikuji p.txt04').fadeIn(1000)
											})
										})
									})
								})
							})
						})
					})
				})
			})
		})

/*
		$('#omikuji img.img01').fadeOut(500);

		$('#omikuji img.img02').delay(500).fadeIn(500).fadeOut(500);

		$('#omikuji img.img03').delay(1500).fadeIn(500).fadeOut(500);

		$('#omikuji img.img02').delay(2500).fadeIn(500).fadeOut(500);

		$('#omikuji img.img03').delay(3500).fadeIn(500).fadeOut(500);
*/
		return false;
	});
});

// kumatube next
$(function(){
	$(".read_open_close").click(function(){
		$(this).hide();
		$(this).next().slideToggle(600);
	});
});


// gallery contact
$(function() {  
	$(".contact table:not(.open)").hide();
	$(".contact h4.switch2").click(function() {
		if(!$($(this).next()).is(':visible')) {
			$(this).next().slideDown("slow");
			$("#switch2").attr("value", "1");
		} else {
			$(this).next().slideUp("slow");
			$("#switch2").attr("value", "0");
		}
		return false;
	});
	$(".contact h4.switch3").click(function() {
		if(!$($(this).next()).is(':visible')) {
			$(this).next().slideDown("slow");
			$("#switch3").attr("value", "1");
		} else {
			$(this).next().slideUp("slow");
			$("#switch3").attr("value", "0");
		}
		return false;
	});
});

