//
//  Survey Popout Script
//
//    Usage:  You need 3 nested divs.  The outer is simply a wrapper div, to provide
//			control over looks.  The second layer (nested div) has the height and width
//			changes applied (i.e. this div gets expanded from a small box to a wide and tall
//			one).  The third div, nested two deep, has the fade effect.  These divs are statically
//			named at this point, using the names in the script below.  The script could be 
//			modified to allow for dynamic div naming.  
//
//			Call showSurvey() to display the survey.
//			Call hideSurvey() to hide it.  
//  		- These functions can be applied to whatever links or activators you'd like.





var wrapperHTML = '';	// wrapperDiv.innerHTML;

function showSurvey(e)
{
	wrapperHTML = $('wrapperDiv').innerHTML;
	$('divSurvey').style.border = '1px solid #d4001a';
	//$('wspace').style.display = 'block';
	
	//first, change the wrapper div's height to 500
	$('wrapperDiv').style.height = '500';
	
	//now, check to see if there are more than 200 px between the click and the bottom of the page
	//if there is less than 200px, scroll down by 200
	if (f_clientHeight() - e.clientY < 200) {
		window.scrollBy(0, 200);
	}
	
	
	surveyH = new fx.Height('divSurvey' , {duration: 400});
	surveyW = new fx.Width('divSurvey' , {duration: 400, onComplete: showInner});
	
	$('aSurvey').style.display = 'none';
	
	surveyH.custom(15, 500);
	surveyW.custom(140, 720);

	//$('surveyIframe').focus();
}

function showInner()
{	
	$('innerSurveyDiv').style.display = 'block';
	slowhigh($('surveyIframe'));
	//surveyO.custom(0,1);
	//$('wspace').style.display = 'none';
	$('wrapperDiv').style.height = '500px';
}

function hideSurvey()
{
	$('innerSurveyDiv').style.display = 'none';
	
	surveyWclose = new fx.Width('divSurvey' , {duration: 400, onComplete: function(){
			$('aSurvey').style.display = 'block';
			$('wrapperDiv').innerHTML = wrapperHTML;
			$('wrapperDiv').style.height = '20px';
			//$('wspace').style.display = 'none';
		}
	});
	
	surveyH.custom(500, 15);
	surveyWclose.custom(720, 140);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

//BEGIN OPACTIY EFFECT HERE


/***********************************************
* Gradual Highlight image script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var baseopacity=30

function slowhigh(which2){
imgobj=which2
browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
imgobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}
