if (typeof(lw_timeout) == 'undefined') lw_timeout = 30;
if (typeof(isie6) == 'undefined') isie6 = false;
var div;

var Survey = {
	showLw: function() {
		myLightWindow = new lightwindow({'overlay': {'opacity': 0.7, image : '/i/lightwindow/black.png', presetImage : '/i/lightwindow/black-70.png'}});
		myLightWindow.activateWindow({href: '/survey/popup/', title: '', author: '', width: 720, height: 500, activeGallery: true});
		if ( (Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) ) {
			$('lightwindow_close').setStyle({'top':'-8px', 'right':'-8px'});
		}
		$('lightwindow_title_bar_close_link').observe('click', function (event) {
		  Survey.setCookie('sawdays_survey_complete','later',1); parent.myLightWindow.deactivate();
		});
	},
	lwTimeout: function() {
		if (Survey.getCookie('sawdays_survey_complete') == "" ) {
			setTimeout(Survey.showLw, lw_timeout*1000);
		}
	},
	initLightwindow: function() {
		Event.stopObserving(window, 'load', lightwindowInit);
		Event.observe(window, 'load', Survey.lwTimeout, false);
	},
	setCookie: function(c_name, value, expiredays) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString()) + "; path=/; domain=sawdays.co.uk";
	},
	getCookie: function(c_name) {
		if (document.cookie.length > 0) {
			c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
				c_start = c_start + c_name.length + 1;
				c_end = document.cookie.indexOf(";", c_start);
				if (c_end == -1) c_end = document.cookie.length;
				return unescape(document.cookie.substring(c_start, c_end));
			}
		}
		return "";
	},
	doSurveyMid: function() {
		$$('.survey-mid').each(function(e) { e.setStyle({'display':'block'}); });
		$$('.survey-start').each(function(e) { e.setStyle({'display':'none'}); });
		
		if ( !(Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) ) {
			
			parent.myLightWindow.options.dimensions.external.height = parent.myLightWindow.dimensions.viewport.height - 20;
			parent.myLightWindow.options.dimensions.external.width = 720;

			originalWidth = 720;
			originalHeight = parent.myLightWindow.dimensions.viewport.height - 30;
			if(originalHeight > 1000) {
				originalHeight = 1000;
			}

			var r = ((100 / parent.$('lightwindow_contents').offsetHeight) * (originalHeight - 40));
			var r2 = ((100 / $('survey-iframe').offsetHeight) * ((originalHeight - 40) - 220));
			var r3 = ((100 / (parent.$('lightwindow_contents').offsetHeight)) * (originalHeight-55));
			var r4 = ((100 / parent.$('lightwindow_contents').offsetHeight) * (originalHeight - 100));

			new Effect.Scale(parent.$('lightwindow_contents'), r, {scaleFrom:100, scaleX:false, scaleFromCenter:true, duration: 0.5});
			new Effect.Scale($('survey-iframe'), r2, {scaleFrom:100, scaleX:false, scaleFromCenter:true, duration: 0.5 });
			new Effect.Scale($('lw-popup'), r3, {scaleFrom:100, scaleX:false, scaleFromCenter:true, duration: 0.5 });
			new Effect.Scale($('survey-mid'),r4, {scaleFrom:100, scaleX:false, scaleFromCenter:true, duration: 0.5 });
			
		} 

	},
	doSurveyEnd: function() {
		
		$$('.survey-start').each(function(e) { e.setStyle({'display':'none'}); });
		$$('.survey-mid').each(function(e) { e.setStyle({'display':'none'}); });
		$$('.survey-end').each(function(e) { e.setStyle({'display':'block'}); });
		
		parent.Survey.setCookie('sawdays_survey_complete','yes',365);

		if ( !(Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) ) {
			parent.myLightWindow.options.dimensions.external.height = 515;
			parent.myLightWindow.options.dimensions.external.width = 720;

			originalWidth = 720;
			originalHeight = 515;

			var r = ((100 / parent.$('lightwindow_contents').offsetHeight) * (originalHeight - 14));
			var r3 = ((100 / (parent.$('lightwindow_contents').offsetHeight)) * (originalHeight - 0));

			new Effect.Move(parent.$('lightwindow_contents'), { x: 0, y: 0, mode: 'absolute' });
			new Effect.Scale(parent.$('lightwindow_contents'), r, {scaleFrom:100, scaleX:false, scaleFromCenter:false, duration: 0.5});
			new Effect.Scale($('lw-popup'), r3, {scaleFrom: 100, scaleX:false, scaleFromCenter:true, duration: 0.5 });
			new Effect.Scale($('survey-mid'),r, {scaleFrom: 100, scaleX:false, scaleFromCenter:true, duration: 0.5 });

		}
	
	}
}

