$(document).ready(function(){
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.boxgrid.slidedown').hover(function(){
		$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});
	//Horizontal Sliding
	$('.boxgrid.slideright').hover(function(){
		$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	//Diagnal Sliding
	$('.boxgrid.thecombo').hover(function(){
		$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
	}, function() {
		$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
	});
	//Partial Sliding (Only show some of background)
	$('.boxgrid.peek').hover(function(){
		$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});
	//Full Caption Sliding (Hidden to Visible)
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'260px'},{queue:false,duration:160});
	});
	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});
	});
});

function flashSet() {
var flashvars = {
};
var params = {
	menu: "false",
	scale: "noScale",
	allowFullscreen: "false",
	allowScriptAccess: "always",
	bgcolor: "#FFFFFF"
};
var attributes = {
	id:"Studio"
};
swfobject.embedSWF("Studio.swf", "videoImage", "306", "250", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}
flashSet();

/**********************************************************************************************************************
 *	メニュー画像きりかえ
 **********************************************************************************************************************/
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

$(document).ready(function() {
	$('li a')
	.css( {backgroundPosition: "-20px 35px"} ) //デフォルト時、背景画像を横-20px、縦35pxに指定。
	.mouseover(function(){
	$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
	//マウスオーバー時に縦位置94pxに0.5秒かけて移動
	})
	.mouseout(function(){
	$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
	//マウスアウト時に横位置40px、縦位置35pxに2秒かけて移動
	$(this).css({backgroundPosition: "-20px 35px"})
	//移動完了後、元の位置に戻す
	}})
	})
});

/**********************************************************************************************************************
 *	ロード中画像表示
 **********************************************************************************************************************/
function LoadingMsg(imgPath){
    if(self.attachEvent || self.addEventListener){ var wimg = new Image();
        var PTop = '35%';
        var msgs ='Now Loading...';
        wimg.src = imgPath;
        document.write('<div id="Loadouter" style="top:',PTop,';position: absolute; width:95%; z-index: 100; color:#9999cc; text-align:center;"><table bgColor="white" cellpadding="10" cellspacing="0" id="Loadinner" style="margin:auto; border:1px solid #dcdcdc; font-size: 13px; text-align:left;"><tr><td align="center">',msgs,'</td></tr><tr><td><img src="',wimg.src,'" border=0></td></tr></table></div>');
        function by(id){ if(document.getElementById){ return document.getElementById(id).style; }; if(document.all){ return document.all(id).style ; }}
        function addEv(obj, type, func){ if(obj.addEventListener){ obj.addEventListener(type, func, false); }else{ if(obj.attachEvent) obj.attachEvent('on' + type, func); }}
        addEv(window, 'load', function(){by('Loadouter').display = 'none';});
    }
}

/**********************************************************************************************************************
 *	都道府県から市区町村SelectBox設定
 **********************************************************************************************************************/
function selectChangeCity(currentId, childId, selected){
	//	var url = 'xmlGet.php';
	var url = 'xml/city.xml';
	new Ajax.Request(url, { method:"get",onComplete : function(req){set_select_City(currentId, childId, selected, req);}});
}
function set_select_City(currentId, childId, selected, httpObj){
	var xml = httpObj.responseXML;
	var childLength = document.getElementById(childId).options.length;

	if(!xml) {
		for ( i=0 ; i <= childLength ; i++ ){
			document.getElementById(childId).options[0]=null;
		}
		document.getElementById(childId).options[0] = new Option("----",'');
		selectChangeTown(childId, "TOWNAREA", '');
	}
	else {
		for ( i=0 ; i <= childLength ; i++ ){
			document.getElementById(childId).options[0]=null;
		}

		var objItems = xml.getElementsByTagName("data");

		var cnt = -1;
		for (var loop = 0; loop < objItems.length; loop++) {
			if (objItems[loop].getElementsByTagName("PREF_ID")[0].firstChild.nodeValue == selected) {
				cnt++;
				var name = objItems[loop].getElementsByTagName("name")[0].firstChild.nodeValue;
				var value = objItems[loop].getElementsByTagName("value")[0].firstChild.nodeValue;
				if (cnt == 0) {
					selectChangeTown(childId, "TOWNAREA", value);
				}
				document.getElementById(childId).options[cnt] = new Option(name,value);
			}
		}
	}
}

/**********************************************************************************************************************
 *	市区町村からタウンエリアSelectBoxの設定
 **********************************************************************************************************************/
function selectChangeTown(currentId, childId, selected) {
	DD = new Date();
	Hours = DD.getHours();
	Minutes = DD.getMinutes();
	Seconds = DD.getSeconds();
	var url = 'xml/townByCity.xml?'+Hours+Minutes+Seconds;
	new Ajax.Request(url, { method:"get",onComplete : function(req){set_select_Town(currentId, childId, selected, req);}});
}
function set_select_Town(currentId, childId, selected, httpObj){
	var xml = httpObj.responseXML;
	var childLength = document.getElementById(childId).options.length;

	if(!xml) {
		for ( i=0 ; i <= childLength ; i++ ){
			document.getElementById(childId).options[0]=null;
		}
		document.getElementById(childId).options[0] = new Option("----",'');
	}
	else {
		for ( i=0 ; i <= childLength ; i++ ){
			document.getElementById(childId).options[0]=null;
		}

		document.getElementById(childId).options[0] = new Option("----",'-1');

		var objItems = xml.getElementsByTagName("data");
		var cnt = 0;
		for (var loop = 0; loop < objItems.length; loop++) {
			if (objItems[loop].getElementsByTagName("CITY_ID")[0].firstChild.nodeValue == selected) {
				cnt++;
				var name = objItems[loop].getElementsByTagName("name")[0].firstChild.nodeValue;
				var value = objItems[loop].getElementsByTagName("value")[0].firstChild.nodeValue;
				document.getElementById(childId).options[cnt] = new Option(name,value);
			}
		}
	}
}
