/*
var points = [];
var markers = [];
var namedmarkers = [];
var namedmarkers_html = [];
var mapPolygons = new Array();
var counter = 0;
*/
jQuery.noConflict();

function getDirections(address) {
	jQuery('#direction_form_to_addr').html(address);
	jQuery('#destination_holder').attr('value',address);
	jQuery('#directions_form_holder').slideDown('normal');
	jQuery('#direction_form_from_addr').focus();
}

function clickMapInfo(id) {
	namedmarkers[id].openInfoWindowHtml(namedmarkers_html[id]);
	return false;
}

function startLoading(message) {
	if(!message) {
		message = 'Loading...';
	}
	var loadingdiv = jQuery('div').html(message).addClass('flashmessage').addClass('loading');
	jQuery('.flashmessage_holder').html(loadingdiv);
	jQuery('.flashmessage').slideDown("slow");
//	setTimeout("jQuery('.flashmessage').slideUp('normal')",6000);
}

function showMessage(message,type) {
	var loadingdiv = jQuery('div').html(message).addClass('flashmessage').addClass(type);
	jQuery('.flashmessage_holder').html(loadingdiv);
	jQuery('.flashmessage').slideDown("slow");
	setTimeout("jQuery('.flashmessage').slideUp('normal')",6000);
}


jQuery(document).ready(
	function() {
		if(jQuery('#myGallery').length > 0) {
			var myGallery = new gallery($('myGallery'), {
				timed: false,
				showInfopane: false,
				lightbox: true
			});
			var mylightbox = new Lightbox();
		}
		if(typeof(comment_type) != 'undefined') {
		if(comment_type == 'listing' && jQuery('#comments_holder').length > 0) {
			jQuery.get(base_dir+'/comment.php',{ajax:'view',type:comment_type,external_id:comment_external_id},
				function(data) {
					jQuery('#comments_holder').html(data).slideDown('normal');
				}
			);
		}
		}
		// This makes checkboxes look right in IE
		if(jQuery.browser.msie) {
			jQuery('input[@type=checkbox]').addClass('checkbox');
			jQuery('input[@type=radio]').addClass('checkbox');
		}
	}
);

// Here is the dreamweaver js
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// End dreamweaver js

function getArticles(pagenum,lim) {
	var orderby = jQuery('#sortdate').val();
	var catid = jQuery('#article_category_id').val();
	var arc = '';
	var arctype = '';
	if(typeof(archive) != 'undefined') {
		arc=archive;
	}
	if(typeof(archive_type) != 'undefined') {
		arctype = archive_type;
	}
	jQuery.get(base_dir+'/data/articles.php',{page: pagenum, sort: orderby, category: catid, limit: lim,archive:arc,type:arctype},
		function(data) {
			jQuery('#articles_holder').html(data);
		}
 	);
}

function getBlogs(pagenum,lim) {
	var orderby = jQuery('#sortdate').val();
	var catid = jQuery('#article_category_id').val();
	var arc = '';
	var arctype = '';
	if(typeof(archive) != 'undefined') {
		arc=archive;
	}
	if(typeof(archive_type) != 'undefined') {
		arctype = archive_type;
	}
	jQuery.get(base_dir+'/data/blog.php',{page: pagenum, sort: orderby, category: catid, limit: lim,archive:arc,type:arctype},
		function(data) {
			jQuery('#articles_holder').html(data);
		}
 	);
}

function addComment(typeid,extid) {
	jQuery.get(base_dir+'/comment.php',{ajax:'edit',type:typeid,external_id:extid},
		function(data) {
			jQuery('#comments_holder').prepend(data);
			jQuery('#addcomment').hide();
			jQuery('#comment_edit').slideDown('normal');
		}
	);
}

function saveComment() {
	var nameid = jQuery('#comment_name').val();
	var emailid = jQuery('#comment_email').val();
	var textid = jQuery('#comment_text').val();
	var phrase = jQuery('#comment_phrase').val();
	jQuery.post(base_dir+'/comment.php',
		{
			ajax:'save',
			type:comment_type,
			external_id:comment_external_id,
			name:nameid,
			text:textid,
			email:emailid,
			comment_phrase:phrase
		},
		function(data) {
			jQuery('#comment_edit').remove();
			var d = jQuery(data);
			jQuery('#comments_holder').prepend(d);
			jQuery(d).slideDown('normal');
			jQuery('#addcomment').slideDown('normal');
		}
	);
}

function delComment(cid) {
	jQuery.get(base_dir+'/comment.php',
		{ajax:'delete',id:cid},
		function(data) {
			if(data == 'no') {
				alert('Could not delete comment.  Perhaps your login session has timed out.\nPlease go to the admin section and log in again.');
			} else {
				jQuery('#comment_'+data).slideUp('normal');
			}
		}
	);
}
