/* -----------------------------------------------------------
Copyright: ©22008 Terra Firma Design & Consulting. All Rights Reserved.
Author: Brian Getting
Company: Terra Firma Design & Consulting
URL: http://www.terra-firma-design.com
----------------------------------------------------------- */
var imgs = new Array();
var current = 0;
var timing = 10000;
var slideshow = [
	['sentry.jpg', 'Sentry in Lincoln Beach', '<strong>Pavement Striping</strong> - Sentry in Lincoln Beach.'],
	['driveway.jpg', 'Newport home driveway', '<strong>Asphalt Services</strong> - Newport home driveway.'],
	['asphalt.jpg', 'Siletz home driveway', '<strong>Asphalt Services</strong> - Siletz home driveway.'],
	['coating.jpg', 'Road District', '<strong>Crack Filling</strong> - Filling cracks on a road.'],
	['grading.jpg', 'Road preparation', '<strong>Grading Services</strong> - Road preparation.'],
	['lighthouse.jpg', 'Yaquina Head lighthouse', '<strong>Seal Coating</strong> - Yaquina Head lighthouse'],
	['striping.jpg', 'Tillamook Sporting Goods', '<strong>Pavement Striping</strong> - Tillamook Sporting Goods.'],
	['sealcoating.jpg', 'State Police', '<strong>Seal Coating</strong> - State Police.']
];


Global = {
  adjustTextarea: function(e) {
  	textArea = $(Event.element(e));
  	if (textArea.value.length > textAreaThreshold) {
  		textArea.morph('height:'+expandedTextAreaHeight+'px;', {duration:0.2});
  	} else {
  		textArea.morph('height:'+defaultTextAreaHeight+'px;', {duration:0.2});
  	}
  },
  
  setup: function() {
    Global.externalLinks();
		if ($('map')) Map.initialize();
		if ($('frame')) Slideshow.initialize();
  },
  
  externalLinks: function() {
    external_links = $$('a[rel=external]');
    external_links.each(function(l) {
      l.writeAttribute('target', '_blank');
    })
  }
}

Map = {
  initialize: function() {
    if (GBrowserIsCompatible()) {
  		var map = new GMap2(document.getElementById("map"));
			var location = new GLatLng(44.818619, -124.063307);
			var description = "<div id=\"map-info\"><p><strong>Allen &amp; Sons Total Lot Maintenance</strong><br />PO Box 1322<br />Depoe Bay, OR<br />97341</p><p>541-574-8257<br /><a href=\"http://maps.google.com/maps/place?cid=4771372145062294066&q=Allen%2B%26%2BSons%2BNewport%2BOR\">Submit a Review</a></p></div>"
  		map.addControl(new GSmallMapControl());
  		map.setCenter(location, 8);
  		marker = new GMarker(location);
	  	map.addOverlay(marker);
			map.openInfoWindow(location, description);
  	}
  }
}

Slideshow = {
	
	initialize: function() {
		frameTarget = $('frame');
		frameContent = '';
		slideshow.each(function(s, index) {
			frameContent += '<div class="rotator" style="display:none;"><img src="images/' + slideshow[index][0] + '" width="424" height="290" alt="' + slideshow[index][1] + '" /><p>' + slideshow[index][2] + '</p></div>';
		});
		frameTarget.update(frameContent);
		imgs = $$('div.rotator');
		imgs[current].show();
		setTimeout(Slideshow.transition,timing);
	},
	
	transition: function() {
		nextIndex = current < imgs.length - 1 ? current + 1 : 0;
		imgs[current].fade({duration:1});
		imgs[nextIndex].appear({duration:1});
		current = current < imgs.length - 1 ? current + 1 : 0;
		setTimeout(Slideshow.transition,timing);
	}
}

Event.observe(window, 'dom:loaded', Global.setup);