//onload
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

//getElementsByClassName
function getElementsByClassName(classname,tag){
	if(!tag) tag = "*";
	var anchs =  document.getElementsByTagName(tag);
	var total_anchs = anchs.length;
	var regexp = new RegExp('\\b' + classname + '\\b');
	var class_items = new Array();

	for(var i=0;i<total_anchs;i++){
		var this_item = anchs[i];
		if(regexp.test(this_item.className)) class_items.push(this_item);
	}
	return class_items;
}

//flash draw
function flashDraw(src,w,h,wmode,id){ 
	var altContent;
	switch(id){
		case 'main':
			altContent = '';
			break;
		default:
			altContent = 'Flash Contnents';
			break;
	}

	if(!wmode) wmode = 'window';
	else if(wmode == 'w') wmode = 'window';
	else if(wmode == 't') wmode = 'transparent';
	else if(wmode == 'o') wmode = 'opaque';
	else if(wmode == 'd') wmode = 'direct';	//for flash10
	else if(wmode == 'g') wmode = 'gpu';	//for flash10

	var str= '' +
		'<object  id="' + id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://get.adobe.com/flashplayer/" width="' + w + '" height="' + h + '">' +
			'<param name="movie" value="' + src + '" />' +
			'<param name="quality value=high" />' +
			'<param name="menu" value="false" />' +
			'<param name="allowScriptAccess" value="always" />' +
			'<param name="allowFullScreen" value="false" />' +
			'<param name="wmode" value="'+ wmode +'" />' +
			'<!--[if !IE]>-->' +
				'<object id="' + id + '2"  type="application/x-shockwave-flash" data="' + src + '" width="' + w + '" height="' + h + '" style="-moz-outline-style:none;">' +
				'<param name="quality value=high" />' +
				'<param name="menu" value="false" />' +
				'<param name="allowScriptAccess" value="always" />' +
				'<param name="allowFullScreen" value="false" />' +
				'<param name="wmode" value="'+ wmode +'" />' +
			'<!--<![endif]-->' +
				altContent +
			'<!--[if !IE]>-->' +
				'</object>' +
			'<!--<![endif]-->' +
		'</object>';
	document.write(str);
}


function mainVisualRandomImg(){
	mv = document.getElementById("mainFlash");
	rn = Math.floor(Math.random() * 3) + 1;
	mv.style.backgroundImage = "url('../img/main/mainVisual"+rn+".jpg')";
}

function mainNewArticleEvent(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("mainNewArticle")) return false;

	var newAtc = document.getElementById("mainNewArticle");
	var atcHead = newAtc.getElementsByTagName("h4");
	var atcList = newAtc.getElementsByTagName("ol");

	atcHead[0].getElementsByTagName("a")[0].onmouseover = function(){
		atcList[0].style.display = 'block';
		atcList[1].style.display = 'none';
		atcHead[0].style.backgroundPosition = '0 0';
		atcHead[1].style.backgroundPosition = '-48px -25px';
		return false;
	}
	atcHead[1].getElementsByTagName("a")[0].onmouseover = function(){
		atcList[0].style.display = 'none';
		atcList[1].style.display = 'block';
		atcHead[0].style.backgroundPosition = '0 -25px';
		atcHead[1].style.backgroundPosition = '-48px 0';
		return false;
	}

	//keyboard access
	atcHead[0].getElementsByTagName("a")[0].onfocus = function(){
		atcList[0].style.display = 'block';
		atcList[1].style.display = 'none';
		atcHead[0].style.backgroundPosition = '0 0';
		atcHead[1].style.backgroundPosition = '-48px -25px';
		return false;
	}
	atcHead[1].getElementsByTagName("a")[0].onfocus = function(){
		atcList[0].style.display = 'none';
		atcList[1].style.display = 'block';
		atcHead[0].style.backgroundPosition = '0 -25px';
		atcHead[1].style.backgroundPosition = '-48px 0';
		return false;
	}
}
