var posts,currentNoOfPosts=10;
window.addEvent('domready',function(){
									
	/*	Find citations and add quotes */
	
		$$('cite').each(function(M,N){
		
			var tmp=M.get('html');
			var D=M.getCoordinates();
			M.setStyles({'width':D.width-22,'height':D.height-22});
			M.empty();
			new Element('img',{'src':'/wp-content/themes/altamodabridal/images/interface/quote-top.jpg','width':43,'height':39,'alt':'Quote','class':'noBorder','styles':{'position':'absolute','margin-top':-17,'margin-left':-5}}).injectInside(M);
			new Element('img',{'src':'/wp-content/themes/altamodabridal/images/interface/quote-bottom.jpg','width':43,'height':39,'alt':'Quote','class':'noBorder','styles':{'position':'absolute','margin-top':D.height-44,'margin-left':D.width-60}}).injectInside(M);
			new Element('div',{'html':tmp,'styles':{'width':D.width-22,'height':D.height-22}}).injectInside(M);
		
		});
		
	/*	If this is a listings, adjust 'older' button */
	/*
		showPosts(5);
		if($('olderPostsBtn')) $('olderPostsBtn').addEvent('click',function(){showPosts(currentNoOfPosts+10);});
	*/
	/*	Show Google Map */
	
		if($('googleMap')) initializeGoogleMap();
		
	/*	Adjust height */
	
		adjustHeights();
		heightInterval=adjustHeights.periodical(1000);
		
	/*	Adjust header bg for IE 6 */
	
		if(Browser.Engine.trident&&Browser.Engine.version<5){
			
			var w=window.getCoordinates();
			var newWidth=w.width-30;
			$('headerBg').setStyle('width',newWidth);
			
			$$('.brideThumb').each(function(M,N){M.setStyles({'padding-right':0,'padding-left':5,'width':110});});
			
		}

	/*	Contact form  */
	
		if($('contactForm')) $('contactForm').addEvent('submit',function(){checkForm();return false;});

});
/*
function showPosts(A){
	
	currentNoOfPosts=A;
	
	if($('nav')){
			
		posts=$$('.postItem');
		posts.each(function(M,N){
		
			if(N<currentNoOfPosts) M.setStyle('display','');
			else M.setStyle('display','none');
		
		});
	
		if($('olderPostsBtn')&&A>=posts.length) $('olderPostsBtn').destroy();
		var newCenterD=$('center').getCoordinates();
		
		adjustHeights();
		
	}
	
}
*/
var timesUpdated=0,heightInterval;
function adjustHeights(){
	
	var leftD=$('left').getCoordinates();
	var centerD=$('center').getCoordinates();
	var rightD=$('sidebar').getCoordinates();
	
	var minHeight=leftD.height;
	if(centerD.height>minHeight) minHeight=centerD.height;
	if(rightD.height>minHeight) minHeight=rightD.height;
	
	$('sidebar').setStyle('height',minHeight-91);
	$('sidebarAddress').setStyle('margin-top',minHeight-$('sidebarAddress').getCoordinates()['height']-90);
	
	timesUpdated++;
	if(timesUpdated>10) $clear(heightInterval);
	
}

/*	Google Maps API */

var map;
var directionsPanel;
var directions;

function initializeGoogleMap(A){
	
	$('googleMap').empty();
	$('googleDirections').empty();
	map = new GMap2($('googleMap'));
	map.addControl(new GLargeMapControl());
	directionsPanel=$('googleDirections');
	directions = new GDirections(map,directionsPanel);
	geocoder = new GClientGeocoder();
	geocoder.getLatLng('637 E. 500 S. Salt Lake City, UT 84102',function(point){
		map.setCenter(point, 13);
		var marker = new GMarker(point);
		map.addOverlay(marker);
	});
	var mapControl=new GMapTypeControl();
	map.addControl(mapControl);

	$('directionsRight').getElements('a').each(function(M,N){
	
		M.addEvent('click',function(){
			
			directions.load("from: "+this.get('text')+" to: 637 E. 500 S. Salt Lake City, UT 84102");
			$('googleDirections').setStyle('display','block');
			adjustHeights();
			
		});
	
	});
	
	$('getDirectionsBtn').addEvent('click',function(){
	
		if($('zipBox').value!=''){
			
			directions.load("from: "+$('zipBox').value+" to: 637 E. 500 S. Salt Lake City, UT 84102");
			$('googleDirections').setStyle('display','block');
			adjustHeights();
			
		}
	
	});
	if(A) directions.load(A);
	
}


/*	Form checker */

function checkForm(){
	
	if($('name').value.trim()==''||$('email').value.trim()==''||$('phone').value.trim()==''||$('message').value.trim()==''){
		
		alert('Please provide all fields');
		return;
		
	}
	
	$('contactForm').submit();
	
}
