// JavaScript Document
var map = null;
var geocoder = null;
var mapReveal;

var mover;

var spinnerImg = new Asset.images(['images/spinner.gif']);

var scroll;


function showDesignedBy(){
	var dialogue;
	var req = new Request.JSON({  
			method: 'post',  
			url: 'index.php',  
			data: {
				'ajaxAction' : 'showDesignedBy'
			},  
			onRequest: function(){
				dialogue = new MavDialog.Alert({
							'force': true,
							'title': 'Engineering and Design: ',
							'message': '<img src="images/spinner.gif" border="0" align="absmiddle" class="spinner"> Loading...',
							'draggable': true,
							'width' : 540
						});
			},
			onSuccess: function(response) {
				if(response.status==1){
					dialogue.setMessage(response.content);
				} 
			},
			evalScripts: true
		}).send();		
}


function displayShowInfo(venue_name, venue_url, address, date) {
	var mdialog = new MavDialog.Alert({
							'force': true,
							'title': venue_name + ", " + date,
							'message': '<div id="map_canvas" style="width:500px;height:500px;"></div>',
							'draggable': true,
							'width' : 600,
							onShow : function(){
								initializeGmap();
								mapReveal = new Fx.Reveal($('map_canvas'), {duration: 2000});
								mapReveal.reveal();
								mapShowInfo(venue_name, venue_url, address);
							}
						});
}
function initializeGmap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2($("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		map.setMapType(G_NORMAL_MAP);
		var mapControl = new GLargeMapControl();
		map.addControl(mapControl);
		var mapTypeControl = new GMapTypeControl ();
		map.addControl(mapTypeControl);
        geocoder = new GClientGeocoder();
      }
}
function mapShowInfo(venue_name, venue_url, address, date) {
		console.log(address);
      if (geocoder) {
        geocoder.getLocations(
          address,
          function(response) {
            map.clearOverlays();
			if (!response || response.Status.code != 200) {
				alert("Sorry, we were unable to geocode that address");
			 } else {
				place = response.Placemark[0];
				point = new GLatLng(place.Point.coordinates[1],
									place.Point.coordinates[0]);
				marker = new GMarker(point);
				map.addOverlay(marker);
				
				marker.openInfoWindowHtml("<strong>" + venue_name + "</strong><br /><a href='" + venue_url + "' target='_blank'>" + venue_url+ "</a><br />" + place.address + "<br />");
				
			
			  }
          }
        );
      }
  }
  
 function openPresskit(){
	var dialogue;
	var req = new Request.JSON({  
			method: 'post',  
			url: 'index.php',  
			data: {
				'ajaxAction' : 'openPresskit',
				'presskit_password' : $('presskit_password').value
			},  
			onRequest: function(){
				dialogue = new MavDialog.Alert({
							'force': true,
							'title': 'Presskit: ',
							'message': '<img src="images/spinner.gif" border="0" align="absmiddle" class="spinner"> Authenticating ...',
							'draggable': true,
							'width' : 540
						});
			},
			onSuccess: function(response) {
				if(response.status==1){
					dialogue.setMessage(response.content);
				} 
			},
			evalScripts: true
		}).send();	 
 }
 
 


window.addEvent('scroll',function() {
if($('credits_div_right')){						  
  $('credits_div_right').unpin();
	$('credits_div_right').position({
		  position : 'topRight',
		  edge: 'topRight',
		  offset: {y:(window.getSize().y - $('credits_div_right').getSize().y)}
	  });

	$('credits_div_right').pin();
	
	$('credits_div_left').unpin();
	$('credits_div_left').position({
		  position : 'topLeft',
		  edge: 'topLeft',
		  offset: {y:(window.getSize().y - $('credits_div_left').getSize().y)}
	  });

	$('credits_div_left').pin();
	
	
	$('menu_pointer').unpin();
	$('menu_pointer').position({
		  position : 'topRight',
		  edge: 'topRight',
		  offset: {y:5, x:-5}
	  });
	$('menu_pointer').pin();

								  
	if(window.getScroll().y < 100){
		$('menu_pointer').fade('in');
	} else {
		$('menu_pointer').fade('out');
	}
}
});
 
window.addEvent('domready', function() {
	var historyHeight = $('history_div').getComputedSize().height;
	//mapReveal = new Fx.Reveal($('map_canvas'), {duration: 2000});
	//mapReveal.dissolve();

									 
	var historyAccordion = new Accordion($$('.history_header'), $$('.history_content'), {
			display: -1,
			alwaysHide: true,
			onActive : function(toggler, element){
				toggler.setStyle('overflow', 'green');				
		 		var myFx = new Fx.Scroll(window).start(window.getScroll().x, element.getParent().getPosition().y);
			},
			onBackground : function(toggler, element){
				toggler.setStyle('color', 'black');				
			}
		});

	
	var myAccordion = new Accordion($$('.section_header'), $$('.section_content'), {
			display: -1,
			alwaysHide: true,
			onActive : function(toggler, element){
					$('history_div').setStyle('height', historyHeight);
					$('history_div').setStyle('overflow', 'auto');	
		 			var myFx = new Fx.Scroll(window).start(window.getScroll().x, element.getParent().getPosition().y);
				
				
					
			},
			onBackground : function(toggler, element){

			}
			
		});
	
	

	
	  new SmoothScroll({  duration:700  }, window); 
	scroll =  new Fx.Scroll(window,  { wait:  false, duration: 2500, transition:  Fx.Transitions.Quad.easeInOut  }); 
	
	$('menu_pointer').addEvent('click',function(){
		scroll.toElement('menu_anchor'); 	
	});
	
	
   var winScrollFx = new Fx.Scroll(window, {wheelStops : false});
   winScrollFx.set(0,0);
   
});


