// Deeplake js

window.onload = function() {
	//setTimeout('newsticker(0)',500);
}

var max = 2;
if(cookieVal('clearstream_ticker')){
	max = cookieVal('clearstream_ticker');
}
var op_in;
var op_out;
var li_id;
var elem_li;


function newsticker(id){
	var ul;
	if(ul = document.getElementById('newstickerul')){
		var elems = ul.getElementsByTagName('li');
		
		li_id = id;	
		elem_li = elems[li_id];	
		elem_li.style.display = "inline";
		elem = elem_li.getElementsByTagName('a')[0];
		
		op_in = new ColorTween(elem.style,'color',Tween.regularEaseOut,'333333','ffffff',1);
		op_out = new ColorTween(elem.style,'color',Tween.regularEaseOut,'ffffff','333333',1);
	//	op_in = new OpacityTween(elem,Tween.regularEaseOut,0,100,1);
	//	op_out = new OpacityTween(elem,Tween.regularEaseOut,100,0,1);
		op_in.start();
		op_in.onMotionFinished = function(){
			setTimeout('fadeout()',5000);
			//console.log(elem.style.color);
		}
	}
}

function fadeout(){
	if(li_id < max){
		li_id++;
	} else {
		li_id = 0;
	}
	op_out.start();
	op_out.onMotionFinished = function(){
		elem_li.style.display = "none";
		setTimeout('newsticker(li_id)',500);
		//console.log(elem.style.color);
	}
}

function textSize(s){
	var b = document.getElementsByTagName('body')[0];
	switch(s){
		case '0':
			b.style.fontSize = "0.7em";
			break;
		case '1':
			b.style.fontSize = "0.9em";
			break;
		case '2':
			b.style.fontSize = "1em";
			break;
		default:
			b.style.fontSize = "0.7em";
			break;
	}
	cookieMaker('deeplaketextsize',s);
}

function initTextSize(){
	if(c=cookieVal('deeplaketextsize')){
		textSize(c);
	}
}

function cookieMaker(myName,textsize){
	document.cookie=myName+'='+textsize+'; path=/';
}

function cookieVal(cookieName){
	var thisCookie=document.cookie.split("; ");
	if(thisCookie.length>0){
		for (cook=0; cook<thisCookie.length; cook++){
			if (cookieName==thisCookie[cook].split("=")[0]){
				return thisCookie[cook].split("=")[1];
			}
		}
	}
}



// slideshow fix
if(document.addEventListener){window.addEventListener("load", fixsafari, false); }else 
if(document.attachEvent){window.attachEvent("onload", fixsafari);}

function fixsafari(){
	initTextSize();
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("safari") != -1){ 
		theObjects = document.getElementsByTagName("object");
		for (var i = 0; i < theObjects.length; i++) {
			if(theObjects[i].parentNode.className == "duoflash"){	
				for (j=0;j<theObjects[i].childNodes.length;j++){
					if(theObjects[i].childNodes[j].name=="Src"){
						var data=theObjects[i].childNodes[j].value;
					}
				}
			if(data.match(/slideshow.swf/i)){
				var height=theObjects[i].height;
				var width=theObjects[i].width;
				var classid=theObjects[i].classid;
				var codebase=theObjects[i].codebase;
				var htmlData = theObjects[i].parentNode.innerHTML;
				var newHtml='<object data="'+data+'" width="'+width+'" height="'+height+'" classid="'+classid+'" codebase="'+codebase+'" >  <param name="AllowFullScreen" value="true" /> <param name="WMode" value="Opaque" /></object>';
				var newObject=theObjects[i].parentNode;
				newObject.innerHTML=newHtml;
			}
			}
		}
	}
}


function dl_boxed(theli,direction){
	if (window.XMLHttpRequest) {
		var ie6 = false;
	} else {
		var ie6 = true;
	}
	if(ie6){
		if(direction > 0){
			switch(theli.className){
				case "first":
					var bg = "#f0a460 url('/images/site_bits/dl_boxed_top_hover.gif') no-repeat left top";
					break;
				case "last":
					var bg = "#f0a460 url('/images/site_bits/dl_boxed_btm_hover.gif') no-repeat left bottom";
					break;
				default:
					var bg = "#f0a460";
					break;
			}
			theli.style.background = bg;		
		} else {
			theli.style.background = '';
		}
	}
}


//---------- Diagram stuff ----------//
var cache = new Array();
var cachepath = '';

function deeplakeGetText(path){
	var url = window.location.href;
	var mystr = /_duoEdit/;
	var mysearch = url.search(mystr);
	if(mysearch == -1){
		cachepath = path.replace("/","");
		if(!cache[cachepath]){
			var myConn = new XHConn();
			myConn.connect("/duocms/diagram/output/"+cachepath+"/", "POST", '', deeplakeGetTextOutput);
		} else {
			deeplakeSetText();
		}
	}
}

function deeplakeGetTextOutput(data){
	var data=data.responseText;
	cache[cachepath] = data;
	deeplakeSetText();
}

function deeplakeSetText(){
	var div = document.getElementById('diagramtext');
	div.innerHTML = '';
	div.innerHTML = cache[cachepath];
}


//============================================================================================
/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
if(document.getElementById('statusbar')){
	var oldStatusBackground=document.getElementById('statusbar').style.backgroundImage;
}
function XHConn(){
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone) {
  	if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();
    try {
    	//before load, set statusbar to loading icon
    	if(document.getElementById('statusbar')){
    		document.getElementById('statusbar').style.backgroundImage="url(/duocms-resources/icons/loading2.gif)";
    	}
    		
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete){
        	//after loaded set statusbar back to old background
        	if(document.getElementById('statusbar') && oldStatusBackground){
	    		document.getElementById('statusbar').style.backgroundImage=oldStatusBackground;
    		}else if(document.getElementById('statusbar')){
    			document.getElementById('statusbar').style.backgroundImage='';
    		}
        	
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


