//namespace 
Crealern.DropIn = {}; 

/* Specify display mode		1) "always"- This makes the fade-in box load each time the page is displayed
2) "oncePerSession"- This uses cookies to display the fade-in box only once per browser session */
Crealern.DropIn.displayMode = "always";
//specify source of iframe
Crealern.DropIn.iFrameSrc = "newsLetter.html";

Crealern.DropIn.dropInWindowLeft = (document.getElementsByTagName("html")[0].offsetWidth-500)/2;
Crealern.DropIn. dropInWindowTop = 10; //set top position of box (in px)
Crealern.DropIn.dropInSpeed = 20; //set speed of drop animation (larger=faster)
Crealern.DropIn.dropInWindowPanel;
Crealern.DropIn.dropInWindow;
Crealern.DropIn.dropStart;
Crealern.DropIn.iframe;		

Crealern.DropIn.ie=document.all;
Crealern.DropIn.dom=document.getElementById;

Crealern.DropIn.initializeDropInWindow = function(iframeSrc) {
	if (!Crealern.DropIn.dom && !Crealern.DropIn.ie) { return; }
	if(!document.getElementById("DropInWindowPanel")) { return; }
	
	
	Crealern.DropIn.dropInWindowPanel = document.getElementById("DropInWindowPanel");
	Crealern.DropIn.dropInWindow = document.getElementById("DropInWindow");
	
	Crealern.DropIn.iframe = document.createElement("IFRAME");
	Crealern.DropIn.iframe.setAttribute("id", "DropInIFrame");
	Crealern.DropIn.iframe.setAttribute("src", Crealern.DropIn.iFrameSrc);
	Crealern.DropIn.iframe.setAttribute("frameBorder", "0");
	Crealern.DropIn.iframe.setAttribute("width", 500);
	Crealern.DropIn.iframe.setAttribute("height", 550);
	Crealern.DropIn.iframe.setAttribute("scrolling", "no");

	if(Crealern.DropIn.dropInWindow.getElementsByTagName("iframe")[0]){
		Crealern.DropIn.dropInWindow.removeChild(dropInWindow.getElementsByTagName("iframe")[0]);
	}
	Crealern.DropIn.dropInWindow.appendChild(Crealern.DropIn.iframe);				
	
	Crealern.DropIn.dropInWindow.height = Crealern.DropIn.dropInWindow.offsetHeight;
	Crealern.DropIn.dropInWindowPanel.style.height = parseInt(Crealern.DropIn.dropInWindow.height)+"px";
	
	Crealern.DropIn.dropInWindow.style.top = Crealern.DropIn.dropInWindow.height*(-1) + "px";
	Crealern.DropIn.dropInWindowPanel.style.left = Crealern.DropIn.dropInWindowLeft + "px";
	Crealern.DropIn.dropInWindowPanel.style.top = Crealern.DropIn.dropInWindowTop + "0px";
	Crealern.DropIn.dropInWindowPanel.style.visibility = "visible";
	
	setTimeout("Crealern.DropIn.dropStart = setInterval('Crealern.DropIn.dropIn()',50)",8000);
};

Crealern.DropIn.dropIn = function() {
	if (parseInt(Crealern.DropIn.dropInWindow.style.top)<0) {
		Crealern.DropIn.dropInWindowPanel.style.top = Crealern.DropIn.dropInWindowTop + "px";
		Crealern.DropIn.dropInWindow.style.top = parseInt(Crealern.DropIn.dropInWindow.style.top) + Crealern.DropIn.dropInSpeed + "px";
	}
	else {	
		clearInterval(Crealern.DropIn.dropStart); 
		Crealern.DropIn.dropInWindow.style.top=0;
	}
};

Crealern.DropIn.closeDropInWindow = function() {
	//if (window.Crealern.DropIn.dropStart) { clearInterval(Crealern.Crealern.DropIn.dropInWindowCrealern.dropStart); }	
	Crealern.DropIn.dropInWindowPanel.style.visibility="hidden";
};

Crealern.DropIn.getCookie = function (Name){
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) { end = document.cookie.length; }
			returnvalue=unescape(document.cookie.substring(offset, end));
		}
	}
	return returnvalue;
};

//do dropdown if person is subscribed; cookie is set in php in newsLetterConform.php
if(Crealern.DropIn.getCookie("hasNewsletter") == "") {
	if ((Crealern.DropIn.displayMode=="oncePerSession" && Crealern.DropIn.getCookie("dropInWindow")) == "" || Crealern.DropIn.displayMode=="always") {
		Crealern.addEvent (window, "load",  Crealern.DropIn.initializeDropInWindow);
		if (Crealern.DropIn.displayMode == "oncePerSession") { document.cookie = "dropInWindow=yes"; }	
	}
}

