/*
setting.js
Javascriptの長くなりそうな指定をまとめて記述
*/

//画像切替 From→http://archiva.jp/web/javascript/simple-showcase_2.html
// <![CDATA[

$(document).ready(function() {

var ypro_photo = {
	init: function(cname,pos){
		var wrap = this.getElementsByClass(cname);
		for(var i=0; i<wrap.length; i++){
			this.setup(wrap[i],pos,i);
		}
	},

	setup: function(wrap,pos,i){
		var links = wrap.getElementsByTagName('a');
		var bigWrap = document.createElement('p');
		var bigA = document.createElement('a');
		var bigImg = new Image();
//		var text =  document.createTextNode(links[0].title);
		
		
		if(pos == 'before'){
			var thumb = wrap.getElementsByTagName('p')[0];
			wrap.removeChild(thumb);
			wrap.appendChild(bigWrap);
			wrap.appendChild(thumb);
		} else { 
			wrap.appendChild(bigWrap);
		};
		

		var tmpTime = ( new Date() ).getTime();
		var tmpHref = links[0].href;
		var tmpTitle = links[0].title;
		tmpHref = tmpHref.replace( /small\//, "" );
		tmpHref = tmpHref.replace( /_s/, "" );

//		alert('tmpTime = '+tmpTime+'\n'+'tmpHref = '+tmpHref+'\n'+'tmpTitle = '+tmpTitle);

		bigWrap.className = "bigImg";
		bigImg.src = links[0].href;
		bigImg.alt = links[0].title;
		bigImg.setAttribute( "class", "ypro_plan_img" );
		bigA.setAttribute( "href", tmpHref );
		bigA.setAttribute( "title", tmpTitle );
		bigA.setAttribute( "id", "lightbox_" + i );
		bigA.appendChild(bigImg);
		bigWrap.appendChild(bigA);
//		bigWrap.appendChild(text);

		if( $( "#lightbox_" + i ).lightBox != undefined ){
			$( "#lightbox_" + i ).lightBox();
		}

		for(var jj=0; jj<links.length; jj++) {
			var thumb = new Image();
			thumb.src = links[jj].href;
			links[jj].onclick = function(){
//				ypro_photo.showImg(this,bigImg,bigA,text);
				ypro_photo.showImg(this,bigImg,bigA);
				return false;
			};
		}
	},
	
//	showImg: function(elm,bigImg,bigA,text){
	showImg: function(elm,bigImg,bigA){

		var tmpHref = elm.href;
		var tmpTitle = elm.title;
		if( tmpHref.indexOf( "/small/" ) < 0 ){
			var tmpIndexDot = tmpHref.lastIndexOf( "." );
			tmpHref = tmpHref.substring( 0, tmpIndexDot ) + "_s." + tmpHref.substring( tmpIndexDot + 1, tmpHref.length );
			var tmpIndexSlash = tmpHref.lastIndexOf( "/" );
			tmpHref = tmpHref.substring( 0, tmpIndexSlash ) + "/small/" + tmpHref.substring( tmpIndexSlash + 1, tmpHref.length );
		}

		bigImg.src = tmpHref;
		bigImg.alt = tmpTitle;
//		text.nodeValue = elm.title;

		tmpHref = elm.href;
		tmpHref = tmpHref.replace( /small\//, "" );
		tmpHref = tmpHref.replace( /_s/, "" );
		bigA.href = tmpHref;
		bigA.title = tmpTitle;

	},

	getElementsByClass: function(searchClass) {
		var classElements = new Array();
		var els = document.getElementsByTagName('div');
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');

		for (i = 0, j = 0; i < els.length; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

}

// window.addEventListener("DOMContentLoaded", function(){showcase.init('showcase')}, false);
// window.addEventListener("load", function(){showcase.init('showcase')}, false);
// window.attachEvent("onload", function(){showcase.init('showcase')});


window.onload = function(){ypro_photo.init('ypro_photo','before')};

// ]]>

});

/* 各ページ */
$(document).ready(function() {
	$("h3").hover(function(){
	$(this).css("cursor","pointer"); 
	},function(){
	$(this).css("cursor","default");
	});
	$("div.ypro_hidden").css("display","none");
	$("h3").click(function(){
	//$(this).next().slideToggle("slow");
	});

	$("#no_date").click(function(){
		if(this.checked){
			$("#s_year").attr('disabled', 'true');
			$("#s_month").attr('disabled', 'true');
			$("#s_day").attr('disabled', 'true');
		}else{
			$("#s_year").attr('disabled', '');
			$("#s_month").attr('disabled', '');
			$("#s_day").attr('disabled', '');
		}
	});
});

function TB_init(){
$("a.thickbox").click(function(event){
// stop default behaviour
event.preventDefault();
// remove click border
this.blur();
// get caption: either title or name attribute
var caption = this.title || this.name || "";
// get rel attribute for image groups
var group = this.rel || false;
// display the box for the elements href
TB_show(caption, this.href, group);
});
}

