BenefulMap.closeGalleryListener = function()
{
	$("span.tour-close-button").click(function(event){
		event.preventDefault();
		BenefulMap.closeGallery();
	});
}

BenefulMap.closeGallery = function()
{
	$("#search-tour").fadeOut(300);
	$("#search-tour").cycle('stop');
	$("#results-sort").show();
	$("#tour-nav").hide();
}

BenefulMap.hideShowGallery = function()
{	
	var cookieValue = jQuery.cookie('dont-show-tour-gallery');
	if(cookieValue)
	{
		$("#tour-nav").hide();
	}else{
		$("#search-tour").fadeIn(3000);
		BenefulMap.slideshowGallery();	
	}
}

BenefulMap.initGalleryListener = function()
{
	/*sets all checkboxes to 'unchecked'*/
	$('input[class=dshow]').attr('checked', false);

	/*set or delete cookie*/
	$('input[class=dshow]').change(function(){
		if($(this).attr('checked')) {
		    var dscookie = $(this).attr("value");
		    var options = { expires: 365 };
		    $.cookie('dont-show-tour-gallery', dscookie, options);
		    $('input[class=dshow]').attr('checked', true)
		} else {
			$.cookie('dont-show-tour-gallery', null);
			$('input[class=dshow]').attr('checked', false);
		}
	});
	BenefulMap.hideShowGallery();
}

BenefulMap.slideshowGallery = function()
{
	if($.browser.msie){
		$("#results-sort").hide();	
	}
	
	$("span.tour-button").click(function(event){
		event.preventDefault();
	});
	
	$("#state3-button").click(function(event) {
		console.log($(this), " clicked");
		window.location = root + "Log-In/Create-Account/Default.aspx?reg=ww&update=true";
	});

	/*check for cookie, if it exists, do not start slideshow*/
	var cookieValue = ($.cookie('dont-show-tour-gallery'));
	
	if(cookieValue){
		$('#search-tour').cycle('stop');
	}else{
		$('#search-tour')
		.before('<div id="tour-nav">')
		.cycle({
			timeout: 9000,
			next: '.tour-button',
			speed: 700,
			pager: '#tour-nav'
		});
	}
}