
	var surveyQuestion = false;
  var timetracking = new Date();
		
	$(document).ready(function() {
	
    if($.cookie('survey_taken'))
    {
      $('#survey_inquiry').hide();
    }
    else
    {
      $("a[href^='http']").click(loadExternalLink);
      $("area[href^='http']").click(loadExternalLink);
      
      if(!$.cookie('visit_time')) 
      {
        $.cookie('visit_time', timetracking.getTime());
      }
      else
      {
        if(!$.cookie('survey_taken'))
        {            
          setInterval(checkForAsking, 500);
        }
      }
    }
	});
	function loadExternalLink()
	{
      if(!$.cookie('survey_taken'))
        openSurveyWindow();
	}
	function openSurveyWindow()
	{
    if(!$.cookie('survey_taken'))
    {
      window.open('http://www.surveygizmo.com/s3/626003/WVI-org-Visitor-Survey','surveywindow','width=620,height=600,scrollbars=1');
      $.cookie('survey_taken', 1,{ expires: 360});
    }
	}
	
	function checkForAsking()
	{
    if(!surveyQuestion)
    {      
      if(timetracking.getTime() - $.cookie('visit_time') > 28000)
      {
        $('#survey_inquiry').show();
        $('#survey_inquiry').animate({
        bottom: '0px'
        }, 600);
        surveyQuestion = true;
      }
    }
	}
	
	function resetQuestion()
	{ 
    $.cookie('visit_time', timetracking.getTime() + 650000);
    $('#survey_inquiry').hide();
    $.cookie('survey_taken', null);     
    $('#survey_inquiry').css('bottom','-147px');
	}
	function endQuestion()
	{
    $('#survey_inquiry').hide();
    $.cookie('survey_taken', 1,{ expires: 360}); 
    $.cookie('visit_time', null);
    $('#survey_inquiry').css('bottom','-147px');
	}
