AudioPlayer.setup("/js/player.swf", { 
	width: 238,
	transparentpagebg: "yes",
	initialvolume: 100,
	loader: '91C3BD'
});

var geocoder;
geocoder = new google.maps.Geocoder();
function geocode(address) {
  geocoder.geocode({'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
    	//$('#latitudefield').val(results[0].geometry.location.y);
			//$('#longitudefield').val(results[0].geometry.location.x);
			//$('#locationform').submit();
			//alert(results[0].geometry.location);
			//alert(results[0].geometry.location.lat());
			top.location.href = "/locations/?location="+address+"&latitude="+results[0].geometry.location.lat()+"&longitude="+results[0].geometry.location.lng();
    } else {
      // "Geocode was not successful for the following reason: " + status;
    }
  });

}


$(document).ready(function() {
	
	$('#locationform').unbind('submit').submit(function() {
		var address = $('#locationfield').val();
		geocode(address);
		//alert(address);
		return false;
	});
	
	$('#searchTerms').focus(function() {
		if (this.value == 'Enter search terms...')
		{ this.value = ''; }
	}).blur(function() {
		if (this.value == '')
		{ this.value = 'Enter search terms...'; }
	});
	
	$('.labelfill').each(function() {
		var title = $(this).attr('title');
		$(this).addClass('placeholder').val(title);
		$(this).focus(function() {
			if($(this).hasClass('placeholder')) {
				$(this).val('').removeClass('placeholder');
			} else {
				//$(this).addClass('placeholder').val(title);
			}
		});
	});
	
  if($('#headerimgs').length) {
		var loaded = 0;
		for(x in photos) {
			$('<img />').attr('src', '/img/'+photos[x].image).load(function() {
				if(loaded>1)
				{
					rotate();
				}
				loaded++;
				
			});
		}
	}
	
	$('#menu-item-56 a, #menu-item-57 a').attr('target', '_blank');
	
	$('.aplayer').each(function() {
		AudioPlayer.embed($(this).attr('rel'), {soundFile: $(this).attr('href')});
	});
	
	$('.menu-item-56 a, .menu-item-57 a').attr('target', '_blank');
	
	var mh = 175;
	$('.event').each(function() {
		var entry = $(this).find('.entry')
		var h = $(entry).height();
		var expand = $(this).find('.expand');
		if(h<mh) {
			$(expand).hide();
		} else {
			$(entry).css('height', mh+'px').attr('rel', h);
			$(expand).click(function() {
				if($(entry).height()==mh)
				{
					$(entry).animate({
						height: $(entry).attr('rel')
					}, 500);
					$(this).text('Read Less...');
				} else {
					$(entry).animate({
						height: mh
					}, 500);
					$(this).text('Read More...');
				}
				
				return false;
			});
		}
	});
});


