function monthlyArchives(value){
	var path = 'http://'+location.hostname+'/white/';
	if(value != ''){
		location.href = path+value+'/index.html';
	}
	return false;
}

function commentSubmit(){
	var commentPath = 'http://'+location.hostname+'/admin/mt-comments.cgi';

	var usrName = $("#comment-author").val();
	var usrMail = $("#comment-email").val();
	var usrText = $("#comment-text").val();
	var alert = '';
	var albg = '#FFE5FF';

	if(usrName == ''){
		alert += 'お名前が入力されていません\n';
		$("#comment-author").css('background-color',albg);
	}
	if(usrMail == ''){
		alert += 'メールアドレスが入力されていません\n';
		$("#comment-email").css('background-color',albg);
	}
	if(usrText == ''){
		alert += 'コメントが入力されていません\n';
		$("#comment-text").css('background-color',albg);
	}

	if(alert != ''){
		window.alert(alert);
		return false;
	}else{
		document.comments_form.action = commentPath;
		document.comments_form.method = 'POST';
		document.comments_form.submit();
	}
}

function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");

		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

function galleryload(){
	var listPath = 'http://'+location.hostname+'/white/galleryList.xml';
	var IDArr = new Array();
	var labelArr = new Array();
	var thumbArr = new Array();
	var linkArr = new Array();
	var count = new Number();
	var list = new Array();
	var result = '';

	shuffle = function(list) {
		var i = list.length;

		while (--i) {
			var j = Math.floor(Math.random() * (i + 1));
			if (i == j) continue;
			var k = list[i];
			list[i] = list[j];
			list[j] = k;
		}
		return list;
	},

	listDisplay = function(){
		list = shuffle(list);

		for(var i=0;i<count;i++){
			var k = list[i];
			result += '<li><a href="'+linkArr[k]+'"><img src="'+thumbArr[k]+'" alt="'+labelArr[k]+'" title="'+labelArr[k]+'" class="thumb-img" width="56" height="56" /></a></li>';
			//result += '<li><a href="'+linkArr[i]+'"><img src="'+thumbArr[i]+'" alt="'+labelArr[i]+'" title="'+labelArr[i]+'" class="thumb-img" width="56" height="56" /></a></li>';
		}

		$("#gallery-list").html(result);

	},

	listLoad = function(XML){
		$(XML).find("Img").each(function(){
			IDArr.push($(this).find("ID").text());
			labelArr.push($(this).find("Label").text());
			thumbArr.push($(this).find("Thumbnail").text());
			linkArr.push($(this).find("PermaLink").text());
			list.push(count);
			count++;
		});

		listDisplay();
	}

	$.get(listPath,{},listLoad);
}

function flvLoad(ID){
	var listDB = 'http://'+location.hostname+'/white/videoList.xml';
	var entryID = '';
	var file = '';
	var pre = '';
	var label = '';

	videoPlay = function(){
		var tagged = document.getElementById('white-video');
		if(tagged){
			var flashvars = {
				file:file, 
				autostart:"false",
				image:pre,
				skin:"http://www.monoglobe.jp/common/player/skin.swf"
			}
			var params = {
				allowfullscreen:"true", 
				allowscriptaccess:"always"
			}
			var attributes = {
				id:"player1",
				name:"player1"
			}
		
			swfobject.embedSWF("http://www.monoglobe.jp/common/player/player.swf", "white-video", "456","342", "9.0.115", false, flashvars, params, attributes);
		
			$("#white-video-comment").html(label);
		}
	},

	listLoad = function(XML){
		var Count = new Number(0);

		$(XML).find("Movie").each(function(){
			if($(this).find("ID").text() == ID){
				entryID = $(this).find("ID").text();
				file = $(this).find("File").text();
				pre =  $(this).find("Pre").text();
				label = $(this).find("Label").text();
				Count++;
			}
		});
		if(Count == 1){
			videoPlay();
		}
	}

	jQuery.get(listDB,function(XML){
		listLoad(XML);
	});
}

function getParam(){
	var vP = '';
	var sc = new Array();
	sc = document.getElementsByTagName('script');
	var pReg = new RegExp('globalFunctions\.js\?.{4,}$');
	var nReg = new RegExp('^[0-9]');

	for(i=0;i<sc.length;i++){
		var p = sc[i].getAttribute('src');
		if(p && p.match(pReg)){
			var usr = p.split('?');
			vP = decodeURI(usr[1].slice(usr[1].indexOf('=')+1));
			if(vP.match(nReg)){
				flvLoad(vP);
			}
		}
	}
}

jQuery.event.add(window,"load",function(){
	smartRollover();
	galleryload();
	getParam();
});

