$(document).ready( function(){
	
	//$("noscript p").css("opacity","0.0").css("height","0");// javascript の警告を非表示	
	
	var detail = $("#detailWrapper");
	
  $("div.detailSource").css("display","none");
		var api= $("div.scrollable").scrollable({
			api: true,
			items:".items",
			item:"div.ico",
			size:6
		});
		
   $("div.scrollable").navigator();
	
	 $("#image_wrap img").click(function(){
		 var current = api.getClickIndex();
		// alert( current );
		 var nextIconObj = api.getItems().eq(current+1).find("a");
		 
		 nextIconObj.click();
		// api.move( nextIconObj );
   });
	 
	//$(".items div a").click(function() {
	$("div.items div.ico a").click(function() {
		var url = $(this).attr("href");
		
		$(this).parent().click();// スクロールのため。
		var detailSource = $(this).attr("rel");
		// get handle to element that wraps the image and make it semitransparent
		var wrap  = $("#image_wrap").fadeTo("medium", 0.1);
		var wrapD = $("#detailWrapper").fadeTo("medium",1);
		// the large image from flickr
		var img = new Image();
		wrapD.children().remove();
		var source = $("div#"+detailSource).clone();
		wrapD.append(source.children());
		img.onload = function() {
			wrap.fadeTo("fast", 1);
			wrap.find("img").attr("src", url);
		};
	
		// begin loading the image from flickr
		img.src = url;
	  //window.location.hash = $(this).attr("name");
		return false;
		
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();
	
	// assign a click event to the exposed element, using normal jQuery coding
//	var defaultCaptionColor = detail.css("color");
	
	$("div#image_wrap img").mouseover(function() {
	
		// perform exposing for the clicked element
		$(this).expose({
			api: true	
			//color:#000,
			//opacity: 0.5
			}).load();
		//detail.css("color","#fff");
	}).mouseout(function() {
		$(this).expose({api: true}).close();
	//	detail.css("color",defaultCaptionColor );
	});
	
	
	
	
	
	
	
});

$(window).load(function(){
	// ハッシュがあるとき。name属性で検索してクリック
	if (window.location.hash != '') {
		 // setTimeout(function(){
		var hashStr = window.location.hash;
		var ancStr = hashStr.replace("#", "");
		var te = "a[name='photo-" + ancStr + "']";
		//alert(te);
		
		//alert( targetItemAnc);
		$(te).click();
		//},1500);
	}	
	setTimeout($.unblockUI, 1500);
	
});
