// JavaScript Document

	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}
	
	function changeImage (img) {
		img.src="../assets/images/survey/closeOver.gif";
	}
				
	function changeBack (img) {
		img.src="../assets/images/survey/close.gif";
	}

	$().ready(function() {
		if (readCookie('survey') != 'shown'){ // if we can't find a cookie saying that we've already shown the popup
			createCookie('cookieTest','1',0); // set a cookie
			var testResults = readCookie('cookieTest'); // attempt to read cookie

			if (testResults == '1'){ // if we can read cookies
				//preload mouse over image
				image01 = new Image();
				image01.src = "assets/images/survey/closeOver.gif";

				var close1=function(hash) { hash.w.fadeOut("slow",function(){ hash.o.fadeOut("fast"); }); };
				var open1=function(hash) { hash.o.fadeIn("fast",function(){ hash.w.fadeIn("slow"); }); };

				createCookie('survey', 'shown', 365);
				
				$('#dialog').jqm({overlay:50, onHide: close1, onShow: open1});
				$('#dialog').jqmShow();
			}
		}
	});
