function newXMLObject(){
	var xmlHttp;
	try{ xmlHttp=new XMLHttpRequest(); } catch (e){
	try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){
	try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){
	alert("Your browser doesn't support AJAX. Application aborted.");
	return false; } } }
	return xmlHttp;
}

var date = new Date();
var browser = navigator.appName;
var version = navigator.appVersion;
var step = 1;
var active = 0;

var win_w;
var win_h;


if (typeof window.innerWidth != 'undefined'){
     win_w = window.innerWidth,
     win_h= window.innerHeight
}
else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0){
      win_w = document.documentElement.clientWidth,
      win_h= document.documentElement.clientHeight
}
else{
      win_w = document.getElementsByTagName('body')[0].clientWidth,
      win_h = document.getElementsByTagName('body')[0].clientHeight
}

function GetScroll(){
	this.iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

	if( typeof window.pageXOffset != 'undefined'){
		this.left = window.pageXOffset;
		this.top = window.pageYOffset;
	}
	else{
		this.left = iebody.scrollLeft;
		this.top = iebody.scrollTop;
	}
}


function locationReplace(url){
	window.location.replace(url);
}

function openGalleryImage(folder,file,no){
	var request = newXMLObject();
	var url = "/_includes/display_gallery.php?";
	url = url + date.getDate() + date.getTime() + "|";
	url = url + folder + "|";
	url = url + file + "|";
	url = url + no + "|";
	url = url + window.location;
	
	request.onreadystatechange=function(){
		if(request.readyState==4){
		document.getElementById("zoomarea").innerHTML = request.responseText;
        }
	}
	
	request.open("GET",url,true);
	request.send(null);
}

function contentReady(id) {
	YAHOO.util.Event.onAvailable(id, this.handleOnAvailable, this); 
}

function attachCloser(){
	var close = document.createElement("div");
	var style = document.createAttribute("class");
	style.nodeValue = "scms_closer_container";
	close.setAttributeNode(style);
	
	var link = document.createElement("a");
	var css = document.createAttribute("class");
	css.nodeValue = "scms_popup_closer";
	link.setAttributeNode(css);
	var href = document.createAttribute("href");
	var loc = window.location.toString();
	href.nodeValue = loc.replace(/#/g,"")+"#";
	link.setAttributeNode(href);
	var click = document.createAttribute("onclick");
	click.nodeValue = "return false;";
	link.setAttributeNode(click);
	link.innerHTML = "schlie&szlig;en";
	close.appendChild(link);
	return close;
}

function openPopup(elm){
	var scroll = new GetScroll;
	var div = document.createElement("div");
	var id = document.createAttribute("id");
	id.nodeValue = "scms_popup_area";
	div.setAttributeNode(id);
	var style = document.createAttribute("style");
	var center = (win_w/2);
	style.nodeValue = "opacity:0.1; width:0px; height:0px; overflow:hidden; left:"+center+"px; top:"+scroll.top+"px;";
	div.setAttributeNode(style);
	var parts = elm.href.split("?");
	var param = parts[1].split("__");
	var img = document.createElement("img");
	img.src = "_dta/image/load_image.php?"+parts[1];
	var sub = document.createElement("div");
	var sub_css = document.createAttribute("class");
	sub_css.nodeValue = "scms_popup_sub";
	sub.setAttributeNode(sub_css)
	var sub_style = document.createAttribute("style");
	sub_style.nodeValue = param[3]+"px;";
	sub.setAttributeNode(sub_style);
	var closer = attachCloser();
	sub.appendChild(closer);
	sub.appendChild(img);
	div.appendChild(sub);
	document.body.appendChild(div);
	closer.addEventListener("click",function(){
		document.body.removeChild(document.getElementById("scms_popup_area"));
	},false);
	
	active = window.setInterval(function(){grow("scms_popup_area");},0.01);
}

function grow(idx){
	var elm = document.getElementById(idx);
	var w = parseInt(elm.style.width);
	var h = parseInt(elm.style.height);
	var l = parseInt(elm.style.left);
	var o = parseFloat(elm.style.opacity);
	if(w < win_w){
		elm.style.width = (w + 30)+"px";
		elm.style.left = (l - 15)+"px";
	}
	if(h < win_h){
		elm.style.height = (h + 30)+"px";
	}
	
	if(o < 0.9){
		elm.style.opacity = (o + 0.02);
	}
	
	if(w = win_w && h == win_h){
		window.clearInterval(active);
		active = 0;
	}
}

