/* This one time, Luke Giuliani wrote a switch on an enum that either cured cancer, saved Africa from famine, or achieved world peace.
 * There was user error when it got deployed, so it just wrote this code instead as backup.
 */

$(function(){

	$.easing.def = "easeOutCirc";

	$('.js_rotate_container').panels({
		speed: 500,
		resize_vertical : true,
		els : {
			container : '.js_rotate_container',
			slider : '.js_rotate_slider',
			panels : '.js_rotate_panel',
			menu_items : '.js_rotate_menu a' //there used to be a comma here
		}
	});

	$('.js_create_columns').columns();
	

// clicks
	$('.js_scroll_to').click(function(e) {
		var go_to = $(e.currentTarget).attr('href');
		$.scrollTo(go_to, 550, {
			offset: 0,
			onAfter:function(){}
		});
	});
	
	$('#fade_images_1').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '388px'
	});

	$('#fade_images_2').innerfade({
		speed: 1000,
		timeout: 8000,
		type: 'sequence',
		containerheight: '388px'
	});
	

	graffi_maps.init();
	
});

// adapted from
// http://code.google.com/apis/maps/documentation/javascript/examples/icon-complex.html
var graffi_maps = {
	
	/**
	 * Data for the markers consisting of a name, a LatLng and a zIndex for
	 * the order in which these markers should display on top of each
	 * other.
	 */
	stores: [
		['GRAFFI / Sentrum', 63.432703,10.398746, 1],
		['GRAFFI / Solsiden', 63.433834,10.412261, 2]
	],

	
	init: function() {
		
		var myOptions = {
			zoom: 15,
			center: new google.maps.LatLng(63.433702,10.403856),
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			scrollwheel : false
		};
		
		var map = new google.maps.Map(document.getElementById("map_canvas"),
																	myOptions);

		this.setMarkers(map, this.stores);
	},

	setMarkers: function(map, locations) {
		// Add markers to the map

		// Marker sizes are expressed as a Size of X,Y
		// where the origin of the image (0,0) is located
		// in the top left of the image.

		// Origins, anchor positions and coordinates of the marker
		// increase in the X direction to the right and in
		// the Y direction down.
		var image = new google.maps.MarkerImage('design/images/gmaps/beachflag.png',
				// This marker is 20 pixels wide by 32 pixels tall.
				new google.maps.Size(20, 32),
				// The origin for this image is 0,0.
				new google.maps.Point(0,0),
				// The anchor for this image is the base of the flagpole at 0,32.
				new google.maps.Point(0, 32));
		var shadow = new google.maps.MarkerImage('design/images/gmaps/beachflag_shadow.png',
				// The shadow image is larger in the horizontal dimension
				// while the position and offset are the same as for the main image.
				new google.maps.Size(37, 32),
				new google.maps.Point(0,0),
				new google.maps.Point(0, 32));
				// Shapes define the clickable region of the icon.
				// The type defines an HTML &lt;area&gt; element 'poly' which
				// traces out a polygon as a series of X,Y points. The final
				// coordinate closes the poly by connecting to the first
				// coordinate.
		var shape = {
				coord: [1, 1, 1, 20, 18, 20, 18 , 1],
				type: 'poly'
		};
		for (var i = 0; i < locations.length; i++) {
			var loc = locations[i];
			var myLatLng = new google.maps.LatLng(loc[1], loc[2]);
			var marker = new google.maps.Marker({
					position: myLatLng,
					map: map,
					shadow: shadow,
					icon: image,
					shape: shape,
					title: loc[0],
					zIndex: loc[3]
			});
		}
	}
}
