$(document).ready(function(){					
	//Create Quick Menu: 
	qm_create(0,false,200,500,false,false,false,false,false);
	
	//Function to toggle dt's by clicking on dd's
	ddExpand('#faq');
	
	//Create Google Map
	if ($('#map').length != 0) {populateMap();};

	//Causes all links to external domains to open in a new window
	$("a[href^='http:']").not("[href*='dentra.com']").attr('target','_blank').addClass('external');
	
	imageControl();
	
});

Cufon.replace('#qm0 a.qmparent,.avenir,.more, h2.title, h2.title-small, h2.title-solution');

function ddExpand(e) {
	$(e).find('dd').hide();
	$(e).find('dt').css('cursor','pointer');
	$(e).find('dt').bind('click', function(){
		if ($(this).hasClass('opened')) {
			$(this).next('dd').slideUp('normal').end().removeClass('opened');
			return;
		};
		
		if($(e).find('dd').is(':animated') || $(this).next('dd').is(':visible')) {
			return false;			
		};
		$(this).next('dd').slideDown('normal').end().addClass('opened');		
	});
	$(e).find('.active').trigger('click');
};

function populateMap() {  
	var map = new GMap2(document.getElementById("map"));  
	map.setCenter(new GLatLng(47.624620, -122.307851), 12);  
	map.setUIToDefault();  
		
	var points = new Array(1);  

	points[1] = [47.624620,-122.307851,'<div class="infoContainer"><h2>Dentra</h2><p class="address">1818 E. Mercer St.<br />Seattle, WA 98112</p></div>'];  

	for(var i=1; i < points.length; i++) {  
			var point = new GLatLng(points[i][0],points[i][1]);  
			var windowInfo = points[i][2];  
			var marker = createMarker(point,windowInfo);  
			map.addOverlay(marker);
	}  
}  

function createMarker(point, overlayText) {  
	 var marker = new GMarker(point);  
	 GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(overlayText);});  
	 return marker;  
}

function imageControl() {
	
	var imageCount = 1;
	
	var images = $('.image-container').find('img');
	images.each( function(){
		$(this).attr("id","image-"+imageCount);
		imageCount ++;
		}	
	);
	imageCount = 1;
	images.hide();
	
	$("#image-"+imageCount).show();
	
	$("#next-image").bind('click', function () {
		$("#image-"+imageCount).fadeOut(1000);
		if (imageCount == images.length) {
			imageCount = 1;
		}
		else {
			imageCount ++;
		}
		$("#image-"+imageCount).fadeIn(1000);		
	});
	
	$("#prev-image").bind('click', function () {
		$("#image-"+imageCount).fadeOut(1000);
		if (imageCount == 1) {
			imageCount = images.length;
		}
		else {
			imageCount --;
		}
		$("#image-"+imageCount).fadeIn(1000);		
	});	
}