/*  Survey Fly-in Javascript.  Created by AgencyQ 2011. */

var pauseTillClose=10000 //pause time (3000=3 seconds)
var glidespeed=50 //customize glide speed in pixels per frame.

var curobjindex=0

function actualstyle(el, cssproperty){
	if (el.currentStyle)
		return el.currentStyle[cssproperty]
	else if (window.getComputedStyle){
		var elstyle=window.getComputedStyle(el, "")
		return elstyle.getPropertyValue(cssproperty)
	}
}

function collectElementbyClass(){
	var classname="survey-glidetext"
	glidearray=new Array()
	var inc=0
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname)
			glidearray[inc++]=alltags[i]
		}
if (glidearray.length > 0 && checkCookie() == 1) {
            setCookie("SurveyNoExpand", "1", "100");
			glideOpen();
			setTimeout("glideClose();", pauseTillClose);
		}
}
    
function glideOpen() {
	glidetimerOpen=setInterval("glideOpenInterval()",50)	
}

function glideOpenInterval(){
	if (parseInt(actualstyle(glidearray[curobjindex], "right"))<-50){
		glidearray[curobjindex].style.right=parseInt(actualstyle(glidearray[curobjindex], "right"))+50+"px";
	}		
	else{
		glidearray[curobjindex].style.right=0;
		clearInterval(glidetimerOpen);
	}	
}

function glideClose(){
	glidetimerClose=setInterval("glideCloseInterval()",50);
	}

function glideCloseInterval(){
	if (parseInt(actualstyle(glidearray[curobjindex], "right"))> -169){
		glidearray[curobjindex].style.right=parseInt(actualstyle(glidearray[curobjindex], "right"))+-50+"px";
	}
	else{
		clearInterval(glidetimerClose);
	}
}

function setCookie(c_name, value, exdays)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : ";Path=/;expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for(i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if(x==c_name)
		{
			return unescape(y);
		}
	}
}

function checkCookie()
{
	var SurveyNoExpand = getCookie("SurveyNoExpand");
	if (SurveyNoExpand != null && SurveyNoExpand == 1) {
	    return false;
	}
	else {
	    return true;
	}
}

if (window.addEventListener)
	window.addEventListener("load", collectElementbyClass, false)
else if (window.attachEvent)
	window.attachEvent("onload", collectElementbyClass)
else if (document.getElementById)
	window.onload=collectElementbyClass
