// JavaScript Document
var flagVisible=0;
var newdiv;


function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}
function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.appendChild) {
		var strNewWindowAlert = "";
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (/\bnew\-win\b/.test(link.className)) {	
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);


//manage div
function showDiv(id,width,height,url){
	if(flagVisible) {hideDiv();}
	
	newdiv = document.createElement('div');
  newdiv.setAttribute('id',id);	
	document.body.appendChild(newdiv);
	
	newdiv.style.position = "absolute";
	newdiv.style.left='-1500px';          
  newdiv.style.top='-1500px'; 
  newdiv.style.background = "#fff";
	newdiv.style.overflow = "hidden";
	newdiv.style.border = "solid 1px #ddd";
	
	newdiv.innerHTML='<img src="images/loading.gif" alt="" id="loading" />';
	
	if(width) {
   newdiv.style.width = width+'px';
 	}
 	if(height) {
   newdiv.style.height = height+'px';
	}
	
	ajaxLoader(url,id); 
 	centerDiv(id,width,height);	
	flagVisible=1;
	refreshlocation(id,width,height);
}

function hideDiv(id){
		document.body.removeChild(newdiv);
		flagVisible=0;
}

function centerDiv(id,myWidth,myHeight){
		var suffix="";
		if(FIND(id).style.left.indexOf('px')>=0){
			suffix="px";
		}
		FIND(id).style.left=Math.floor((returnWindowSize('width')-myWidth)/2)+suffix;
		FIND(id).style.top=Math.floor(returnWindowSize('height')/2-(myHeight/2))+getTop()+suffix;
}

function returnWindowSize(dim) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(dim == 'width') return myWidth;
	if(dim == 'height') return myHeight;
}
function getTop(){
		if (navigator.appName == "Netscape") {
			return window.pageYOffset;
		}
		else {
			return (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
		}
}
function refreshlocation(id,myWidth,myHeight){
		if(flagVisible){
			centerDiv(id,myWidth,myHeight);
		} else {
			if(!flagVisible) {
				if(st1) clearTimeout(st1);
				return;
			}
		}
		st1=setTimeout(function(){refreshlocation(id,myWidth,myHeight)},10);
}

function ajaxLoader(url,id) {
  if (document.getElementById) {
			
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
      }
    }
    x.open("http://www.dastudio.biz/GET", url, true);
    x.send(null);
  }
}

var bobexample=new switchcontent("switchgroup1", "div") //Limit scanning of switch contents to just "div" elements
bobexample.setStatus('<img src="images/opencq8.png" /> ', '<img src="images/closedy2.png" /> ')
bobexample.setColor('darkred', 'black')
bobexample.setPersist(true)
bobexample.collapsePrevious(true) //Only one content open at any given time
bobexample.init()