$(function(){
	handleDown = false;
	$('div.cycle').cycle();
	$('div.cycle_page').cycle({next:'#right_control', prev:'#left_control', timeout:5500, after:Gallery_After});
	$('div.cycle_slide').cycle({ fx:'fade', speed:1000, timeout:6000 });
	$('div#frame_pic').cycle({timeout:5000 });
	$('#text_block').jScrollPane({showArrows:false});
	$('form.validate').validationEngine();
	$('.lightbox').lightBox();
	//$('#results').jScrollPane();
	
	function Gallery_After() {
		//$('#callout').html(this.title);
	}
	
	function Nav_Over() {
		var cur = $(this).attr('class');
		var items = $('#subs ul.' + cur).html();
		$('#subnav ul').css('top', '-50px').html(items).animate({top:0}, 300);
		//$('#subnav ul').html(items);
		
	}
	
	function Nav_Out() {
		
	}
	
	$('#nav ul li').hoverIntent(Nav_Over, function(){});
	
	$('#coords a.tip').live('mouseover', function() {
		//$('#map div.tooltip').remove();
		var pos = $(this).position();
		var left = pos.left - 5;
		var top = pos.top - 5;
		$('#map').append('<div class="tooltip" style="left:' + left + 'px;top:' + top + 'px;"><p>' + $(this).attr('header') + '</p>' + $(this).attr('miles') + ' miles from Aliana</div>');
	}).live('mouseout', function() {
		$('#map div.tooltip').remove();
	});
	
	$('#legend ul li span').live('click', function() {
		var b = $(this).attr('class');
		var coords = $('#all_coords div.' + b).html();
		$('#map #img').css('background', 'url(/images/map/' + b + '.png) no-repeat');
		$('#coords').html(coords);
	});
		
	$('#map map area').mouseover(function() {
		var c = $('#neighborhood_info div.' + $(this).attr('id')).html();
		$('#legend div.roll_info').html(c);
	});
	
	$('#clicks h3').click(function() {
		$('img.overlay').remove();
		var file = $(this).attr('class');
		//$('#map #overlay').html('<img src="/images/interactive_map/' + file + '" />');
		$('#map').append('<img src="/images/interactive_map/' + file + '" class="overlay" />');
	});
	
	$('img.back').click(function() {
		history.go(-1);
	});
	
	$('div#title').mouseleave(function() {
		var items = $('#subs ul#active_subnav').html();
		$('#subnav ul').html(items);
	});
	
	$('#title #logo').mouseenter(function() {
		$(this).css('background', 'url(/images/logo_over.png) no-repeat');
	});
	
	$('#title #logo').mouseleave(function() {
		$(this).css('background', 'url(/images/logo.png) no-repeat');
	});
	map_stat = '';
	orig_legend = $('#legend').html();
	$('.switch a').click(function() {
		$('#map #img').css('background-image', 'none');
		if(map_stat == 'new') {
			map_stat = 'orig';
			var c = $('#map').attr('orig');
			$('#map').css('background', c);
			$('#legend').html(orig_legend);
			
		}
		else {
			map_stat = 'new';
			var c = $('#map').attr('new');
			$('#map').css('background', c);
			$('#legend').html(orig_legend);
			var new_legend = $('#new_legend').html();
			$('#legend').html(new_legend);
		}
	});
	
});
