// dropdown menu
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

$(document).ready(function() {

		// set curor to pointer on courses (IE cant handle :hover correctly)
		$("a[id^='show_pointer']").each(function(i) {

			var $this	= $(this);

			$this.mouseover(function(){
				$this.css({'cursor' : 'pointer'});
			});
		});

		// submenu
		$("span[id^='sidebarsub']").each(function(i) {

			var $this	= $(this);
			var subid	= $this.attr("id");

			// set mouseover link color (since IE6 doesnt support :hover)
			$this.mouseover(function(){
				$this.css({'color' : '#dc614d'});
			});

			// set mouseout link color (since IE6 doesnt support :hover)
			$this.mouseout(function(){
				$this.css({'color' : '#1570bd'});
			});

			// set slide effect
			$this.click(function(j) {

				// set cookie state for side menu
				if ($("ul#x" + subid).css("display") != "none") {
					// open -> closed (delete cookie)
					$.cookie(subid, null);
				} else {
					// closed -> open (set cookie)
					$.cookie(subid, 'open', {expires: 1});
				}

				$("ul#x" + subid).slideToggle();
			});

			// set initial state of menu
// too loud in IE, do it from PHP instead
/*
			if ($.cookie(subid) != null) {
				$("ul#x" + subid).show();
			}
*/
		});

		// poll meters
		$("img[id^='poll_id']").each(function(i) {

			var $this	= $(this);
			var pollid	= $this.attr("id");
			var pollval	= $("input#x" + pollid).val();

			// max animation width is 196 pixels
			var newwidth = 196 * pollval;

			if (0 < newwidth) {
				newwidth = Math.ceil(newwidth / 100);
			}

			$("img#" + pollid).animate({ width: newwidth + "px" }, { queue:false, duration: 2000 });
		});

		// load accordion (start page)
		var tmpAcc = document.getElementById("basic-accordian");
		if (null != tmpAcc)
			new Accordian('basic-accordian',5,'header_highlight');


		// moushikomi form
		$("input[id^='moushikomig']").each(function(i) {

			var $this	= $(this);
			var myId	= $this.attr("id");

			// open sections
			if ($("#status_" + myId).val() == "open") {
				// open by default. add check
				this.checked = true;
			} else {
				// hide
				$("#x" + myId).css({'display':'none'});
			}

			// register click
			$this.click(function(){

				var checkbox = this;

				$("#x" + myId).slideToggle("slow", function(){

					// remove class selection if check is removed (on animation finish)
					if (!checkbox.checked)
						$("#reset_" + myId)[0].checked = true;
				});
			});

		});

/*
		jQuery('#moushi_classes').accordion({
			autoheight: false,
			active: 9
		});
*/

/*
		// taiken form classes
		var taiken = document.getElementById('taiken_form');
		if (null != taiken) {

			// for group 1 (membership classes)
			$(".g1").click(function(i) {
				$(".g2").each(function(j){
					var $this = $(this);
					if ($this[0].checked) {
						if ($this[0].value != '0') {
							var radio_btn = $("#g1default");
							radio_btn[0].checked = true;
							alert("「会員制英会話」と「女性英会話」同時に受講出来ません。\n会員制英会話を受講したい場合、女性英会話を外してください");
						}
					}
				});
			});

			// for group 2 (female classes)
			$(".g2").click(function(i) {
				$(".g1").each(function(j){
					var $this = $(this);
					if ($this[0].checked) {
						if ($this[0].value != '0') {
							var radio_btn = $("#g2default");
							radio_btn[0].checked = true;
							alert("「女性英会話」と「会員制英会話」同時に受講出来ません。\n女性英会話を受講したい場合、会員制英会話を外してください");
						}
					}
				});
			});

		}
*/

/*
		// load google map
		var tmpMap	= document.getElementById("map");
		if (null != tmpMap)
			loadGmap(tmpMap);
*/
});

function loadGmap(mapObj) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(mapObj);
		map.addControl(new GLargeMapControl());

		// start point for map
		map.setCenter(new GLatLng(43.0601, 141.3551), 17);

		var icon = new GIcon();
		icon.image = 'graphics/map_logo.gif';
		icon.iconSize = new GSize(137, 47);
		icon.iconAnchor = new GPoint(68, 47);

		var latlng = new GLatLng(43.0597, 141.35666);

		var marker = new GMarker(latlng, icon);

		GEvent.addListener(marker, "click", function() {
		map.setCenter(new GLatLng(43.0601, 141.3551), 17);
		});

		map.addOverlay(marker);
	}
}
/*
function initMenu() {
$('#menu ul').hide();
$('#menu ul:first').show();
$('#menu li a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#menu ul:visible').slideUp('normal');
checkElement.slideDown('normal');
return false;
}
}
);
}
*/

