// function hideAnnouncement(announcement_created_at) {
//   setCookie(announcement_created_at, 'hidden');
//   $("announcement").fade();
// }

function load_map(field_to_show,google_address) {
	var geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(google_address,function(point) {
			if (point) { 
				var map = new GMap2(document.getElementById(field_to_show));
				map.addControl(new GSmallZoomControl());
				map.addControl(new GMapTypeControl());
				map.setCenter(point, 15); 
				var marker = new GMarker(point); 
				map.addOverlay(marker); }
			} );
	}
}


var SWFUploader = {	
	resize_image: function(img, options ) {
		this.options = options || {};

		var img_width = img.offsetWidth;
		var img_height = img.offsetHeight;
		var img_aspect_ratio = Math.round((img_width / img_height) * 100) / 100;

		var max_width = this.options['max_width'] || 120;
		var max_height = this.options['max_height'] || 90;
		var max_aspect_ratio = Math.round((max_width / max_height) * 100) / 100;

		var new_img_width = 0;
		var new_img_height = 0;
		var new_aspect_ratio = 0;

		// if no resize needed
    if (img_width < 120 && img_height < 90) {
            new_img_width = img_width;
            new_img_height = img_height; 

		// if wider
		} else if (img_aspect_ratio > max_aspect_ratio) {
			new_img_width = max_width;
			new_img_height = Math.round(new_img_width / img_aspect_ratio);

		// if taller
		} else if (img_aspect_ratio < max_aspect_ratio) {
			new_img_height = max_height;
			new_img_width = Math.round(new_img_height * img_aspect_ratio);

		// equal
		} else {
			new_img_width = max_width;
			new_img_height = max_height;
		}

		img.style.width = new_img_width + "px";
		img.style.height = new_img_height + "px";
		new_aspect_ratio = Math.round((new_img_width / new_img_height) * 100) / 100;
	}	
}

var Cookie = {
	set: function(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=/";
	},

	get: function(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;
	},

	destroy: function(name) {
		createCookie(name,"",-1);
	}	
}

SWFUploader.ToggleInput = Class.create();
Object.extend(Object.extend(SWFUploader.ToggleInput.prototype, Abstract.prototype), {
	initialize: function(element, text){
		this.element = $(element);
		this.text = text;
		Event.observe(this.element, 'focus', this.toggleInput.bindAsEventListener(this) );
		Event.observe(this.element, 'blur', this.toggleInput.bindAsEventListener(this) );						
	},
	
	toggleInput: function(event){
		if (event.type == 'focus'){
			this.element.value = (this.element.value == this.text) ? '' : this.element.value;
		} else if (event.type == 'blur'){
			this.element.value = (this.element.value == '') ? this.text : this.element.value;								
		}
	}
	
});



