function navigateToURL(sel) {
	 if (sel.selectedIndex == -1 || sel.value == "dummy") return;
	 var opt = sel.options[sel.selectedIndex];
	 if (opt && opt.value)
			location.href = opt.value;
}

/**
* 折りたたみ式コンテンツを開く
*
* @param detailID
* オープンするコンテンツのID
* @param opener
* オープナーへの参照
*/
function openDetail(dID,opener){
	var img;
	
	document.getElementById(dID).style.display = "block";
	img = (dID == "works2009Detail" || dID == "works2005Detail") ? opener.firstChild.firstChild : opener;
	img.src = (img.src.match(/\/common\/img\/icon_plus.gif/)) ? "/common/img/icon_minus.gif" : "/common/img/icon_minus2.gif";
	img.alt = "詳細を隠す";
	opener.onclick = function(){
		closeDetail(dID,opener);
	};
}

function closeDetail(dID,opener){
	var img;
	
	document.getElementById(dID).style.display = "none";
	img = (dID == "works2009Detail" || dID == "works2005Detail") ? opener.firstChild.firstChild : opener;
	img.src = (img.src.match(/\/common\/img\/icon_minus.gif/)) ? "/common/img/icon_plus.gif" : "/common/img/icon_plus2.gif";
	img.alt = "詳細を表示";
	opener.onclick = function(){
		openDetail(dID,opener);
	};
}

function wo(target,w,h){
	window.open(String(target),"_blank","left=200,top=200,status,scrollbar,resizable,toolbar,menubar,location,width="+w+",height="+h);	
}

function createVideoContainer(videoId,type){
	var margin = 20;
	var boxW = 630 + margin*2;
	var boxH = 384 + margin*2;
	$('body').prepend('<div id="floatingVideoBoxWrapper"><div id="floatingVideoBoxBG"></div><div id="floatingVideoBox"></div></div>');
	$('#floatingVideoBoxBG').click(function(){
		$("#floatingVideoBoxWrapper").fadeOut("slow",function(){
			$(this).remove();
		});
	});
	$('#floatingVideoBoxWrapper').width("100%").height("100%").css("left",0).css("top",0);
	$('#floatingVideoBoxBG').width("100%").height("100%").css("left",0).css("top",0).css("opacity",0.8).fadeIn("slow");
	
	$('#floatingVideoBox').width(boxW).height(boxH).css("left",$(window).width()/2 - boxW/2).css("top",$(window).height()/2 - boxH/2).slideDown("slow",function(){
		switch(type){
			case "nicoVideo":
				$(this).append('<div style="padding:'+margin+'px;"><a id="video_'+videoId+'" rel="video" href="http://www.nicovideo.jp/watch/'+videoId+'">videoId</a></div>');
			break;
			case "youtube":
				$(this).append('<div style="padding:'+margin+'px;"><a id="video_'+videoId+'" rel="video" href="http://www.youtube.com/watch?v='+videoId+'">videoId</a></div>');
			break;
			default:
			break;
		}
		
		$("#video_"+videoId).createVideo();
	})
	
	$(window).resize(function(){
		$('#floatingVideoBox').css("left",$(window).width()/2 - boxW/2).css("top",$(window).height()/2 - boxH/2);
	});
}

function openNicoVideoWindow	(videoId){
	createVideoContainer(videoId,"nicoVideo");
	
	/*var w = window.open("/_blank.html","_blank","left=200,top=200,status,scrollbar,resizable,toolbar,menubar,location,width="+485+",height="+385);	
	w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
										+'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> '
										+'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" > '
										+'<head> '
										+'<style>*{margin:0; padding:0; color:#FFFFFF;}</style> '
										+'<title>'+videoId+'</title> '
										+'</head>' 
										+'<body> '
										+'<script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/'+videoId+'"></script>'
										+'</body> '
										+'</html>');*/
}

function openYoutubeVideoWindow (videoId){
	createVideoContainer(videoId,"youtube");
	
	/*var w = window.open("/_blank.html","_blank","left=200,top=200,status,scrollbar,resizable,toolbar,menubar,location,width="+425+",height="+344);	
	w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
										+'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> '
										+'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" > '
										+'<head> '
										+'<style>*{margin:0; padding:0; color:#FFFFFF;}</style> '
										+'<title>'+videoId+'</title> '
										+'</head>' 
										+'<body>'
										+'<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+videoId+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videoId+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>',
										+'</body>'
										+'</html>');*/
}

//swfobjectラッパー関数
var outputSWF = (function(){
	var num = 1;
	
	return function (url,w,h){
		var flashvars = {};
		var params = {wmode: "opaque" , allowFullScreen: "true"};
		var attributes = {};
		var ver = "10.0.0";
		var color = "#FFFFFF";
		var prefix = "blogEntrySWF";
		document.write('<div class="swfContainer"><div id="'+prefix+num+'"></div></div>');
		swfobject.embedSWF(url, prefix+num, w, h, ver, color, flashvars ,params , attributes );
		
		num++;
	};
})();

var outputSWFVideo = (function(){
	var num = 1;
	
	return function (url,w,h){
		var flashvars = {flvpath:url};
		var params = {wmode: "opaque" , allowFullScreen: "true"};
		var attributes = {};
		var ver = "10.0.0";
		var color = "#FFFFFF";
		var prefix = "flv";
		document.write('<div class="swfContainer"><div id="'+prefix+num+'"></div></div>');
		swfobject.embedSWF("/common/swf/player.swf", prefix+num, w, h, ver, color, flashvars ,params , attributes );
		
		num++;
	};
})();

//イベントリスナーラッパー
var addListener = (function() {
    if ( window.addEventListener ) {
        return function(el, type, fn) {
            el.addEventListener(type, fn, false);
        };
    } else if ( window.attachEvent ) {
        return function(el, type, fn) {
            var f = function() {
                fn.call(el, window.event);
            };
            el.attachEvent('on'+type, f);
        };
    } else {
        return function(el, type, fn) {
            el['on'+type] = fn;
        }
    }
})();


//サブコンテンツ部分のopenNewWindowIcon付きリンクの処理
function over(t){
	t.firstChild.style.textDecoration = "none";
}

function out(t){
	t.firstChild.style.textDecoration = "underline";
}

//IEのバージョンチェック
function getIEVersion(){
	var MSIE = "MSIE ";
	var UA = navigator.userAgent;
	
	if(UA.indexOf(MSIE) == -1) return 9999;
	
	var startPos = UA.indexOf(MSIE) + MSIE.length;
	var endPos = UA.indexOf(";",startPos);
	var version = Number(UA.slice(startPos,endPos));
	
	return version;
}

/* リンク切れの画像対応 */
$(function(){
	$(".entry img").each(function(){
		$(this).error(function(){
			$(this).attr({"src":"/common/img/img_notfound.png","width":100,"height":100})
		});
		$(this).attr("src",$(this).attr("src"));
	});
});

