$(window).load(function(){
	init_news();

});

var childOpen = false;
var window_obj = null;
var _now, _weekday, _monthname, _daynumber, _monthnumber,_year, _hour, _hour12, _ap, _min, _sec, _micro;

function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
function add_leading_zero(value){
  if (value < 10) {
  	return "0" + value;
  }
  else {
  	return "" + value;
  }
}
function set_date_vars(date_){
	_now=new Date();
	if (date_) {
		_weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		_monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		_daynumber = add_leading_zero(_now.getDate());
		_monthnumber = add_leading_zero(_now.getMonth() + 1);
		_year = "" + _now.getFullYear();
	}
	else { // time
		_hour12 = _now.getHours();
		_hour = add_leading_zero(_hour12);
		if (_hour12 > 12) {
			 _hour12 = _hour12 - 12;
			 _ap = 'PM';
			}
		else {
			 _ap = 'AM';
			}
		_hour12 = add_leading_zero(_hour12);
		_min = add_leading_zero(_now.getMinutes());
		_sec = add_leading_zero(_now.getSeconds());
		_micro = add_leading_zero(_now.getTime());
	}
}
//-----------------------------------------------------------------//
// Popup a new page in a window                                    //
//-----------------------------------------------------------------//

function popupWindow (winurl, winname, winfeatures, waitingMessage)
{
	// This launches a new window in the centre of the screen, and then
	// focuses it if window.focus() is supported.
    var now = new Date();
    var rand = now.getTime();
    winname += rand; // Make name unique
    childOpen = true;
	var amountdown  = 0;
	var amountright = 0;
	var t_H, t_W, w_Y, w_X;
	var a_T = "top=", a_L = "left=";
    window_obj = null; // This is necessary to avoid error: The callee (server [not server application]) is not available and disappeared
    if (winurl == null)  return;
	if (winfeatures == null) {
	  winfeatures = "height=480, width=510, resizable=2,scrollbars, screenY=" + amountdown + ",screenX=" + amountright;
	  t_W = 510;
	  t_H = 480;
	} else {
	  winfeatures = winfeatures.toLowerCase();
	  if( winfeatures.indexOf("width=") > -1 ) {
		  t_P = winfeatures.indexOf("width=")+6;
		  if( (winfeatures.indexOf(",",t_P)-t_P) > 0 ) {
			t_W = parseInt(winfeatures.substr(t_P, (winfeatures.indexOf(",",t_P)-t_P))); }
		  else {
			t_W = parseInt(winfeatures.substr(t_P)); }
	  } else {
		  winfeatures = "width=510, " + winfeatures;
		  		  t_W = 510 }

	  if( winfeatures.indexOf("height=") > -1 ) {
		  t_P = winfeatures.indexOf("height=")+7;
		  if( (winfeatures.indexOf(",",t_P)-t_P) > 0 ) {
			t_H = parseInt(winfeatures.substr(t_P, (winfeatures.indexOf(",",t_P)-t_P))); }
		  else {
			t_H = parseInt(winfeatures.substr(t_P)); }
	  } else {
		  winfeatures = "height=480, " + winfeatures;
		  t_H = 480; }

	}
        // Calculate top position of window
        if( winfeatures.indexOf("toolbar") > -1 )
          { w_Y = ((screen.height-80-t_H)/2); }
        else
          { w_Y = ((screen.height-40-t_H)/2); }

	w_X = ((screen.width-t_W)/2);

        // If top= is not supplied, plug in calculated value
	if( winfeatures.indexOf(a_T) == -1 ) { winfeatures = winfeatures + "," + a_T + w_Y; }

        // If left= is not supplied, plug in calculated value
	if( winfeatures.indexOf(a_L) == -1 ) { winfeatures = winfeatures + "," + a_L + w_X; }
    //
    // If a waiting message was passed in, pop up this window first
    if (arguments.length > 3)
      {
       window_obj = window.open("",winname,winfeatures);
       window_obj.document.write("<HTML><BODY BGCOLOR='Linen'><TABLE HEIGHT='100%' WIDTH='100%'><TR><TD VALIGN='MIDDLE' ALIGN='CENTER'><H1>" + waitingMessage + "<H1></TD></TR></TABLE></BODY></HTML>");
       window_obj.location = winurl;
      }
    else {
	  window_obj = window.open(winurl,winname,winfeatures);
      }
	//CenterWindow(window_obj, t_W, t_H);

	// Popups may fail if blocked by browser
  try {
   if (window_obj.opener == null){
       window_obj.opener = window;
     }
     window_obj.opener.name = "myparent";
     window_obj.focus();
  	 return;
      }
  catch (got_error) {
  	 alert ("Error encountered popping up detail window, popup windows may be blocked by your browser. Try changing your browser settings to allow popups.");
  	 return; // Element does not exist
      }
}
function window_handling()
{
}

function popup(url,width,height,page)
{
width = reduce_width_to_max(width);
height = reduce_height_to_max(height);
popupWindow(url+'&layout=nomenu', page,
               'height='+height+',width='+width+',resizable=2,scrollbars');
}

function popupImage(imageid,width,height,size)
{
// Width and Height reflect the image size, adjust for extra stuff
width = reduce_width_to_max(width + 50);
height = reduce_height_to_max(height + 70); // Allow for description
popupWindow('index.php?page=image_viewer&imageid='+imageid+'&imagesize='+size+'&layout=nomenu', imageid,
               'height='+height+',width='+width+',resizable=2,scrollbars');
}

function reduce_width_to_max(width)
{
var maxwidth = (screen.width > 0) ? (screen.width - 20) : 800;
if (width > 0 && width < maxwidth)
  return width;
else
  return maxwidth;
}

function reduce_height_to_max(height)
{
var maxheight = (screen.height > 0) ? (screen.height - 60) : 600;

if (height > 0 && height < maxheight)
  return height;
else
  return maxheight;
}
function handleError() {
	return true;
}

function updateLayer(lyr, html, only_if_exists)
{
//	alert(lyr+"="+html);
  if (arguments.length == 3) {
     if (only_if_exists){
     	if (!divExists(lyr)){
     		return;
     	}
     }
  }
  if (document.all || document.getElementById)
  {
    var p = lyr.indexOf('.');
    var id = p != -1 ? lyr.substring(lyr.lastIndexOf('.') + 1) : lyr;
    if (document.all)
    {
      document.all[id].innerHTML = html;
    }
    else
    {
      var l = document.getElementById(id);
      var r = document.createRange();
      r.selectNodeContents(l);
      r.deleteContents();

      var docFrag = r.createContextualFragment(html);
      l.appendChild(docFrag);
    }
  } else {
	//Netscape 4 stuff....
	document.layers[lyr].document.write(html);
	document.layers[lyr].document.close();
  }
}
function divExists(lyr)
{
    var p = lyr.indexOf('.');
    var id = p != -1 ? lyr.substring(lyr.lastIndexOf('.') + 1) : lyr;
    if (document.all){
      return ((typeof document.all[id] == 'undefined') ? false : true);
    }
    else {
      // Under netscape, we need try and catch to detect missing div
       try {
         var test = document.getElementById(id).style.visibility;
         return true; // Exists
         }
       catch (got_error) {
       	 return false; // Element does not exist
         }
      }
}
function correctPNGs()
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i];
	  var imgName = img.src.toUpperCase();
	  if (imgName.length > 9) {
	  	if (imgName.substring(imgName.length-9, imgName.length) == "TRANS.PNG")
	     {
	     correctPNG(img);
	     i = i-1;
	     }
      }
   }
}
function correctPNG(img)
   {
	 var imgID = (img.id) ? "id='" + img.id + "' " : "";
	 var imgClass = (img.className) ? "class='" + img.className + "' " : "";
	 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
	 var imgStyle = "display:inline-block;" + img.style.cssText;
	 if (img.align == "left") imgStyle = "float:left;" + imgStyle;
	 if (img.align == "right") imgStyle = "float:right;" + imgStyle;
	 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
	 img.outerHTML = strNewHTML;
   }
if (navigator.appName == "Microsoft Internet Explorer")
{
 window.attachEvent("onload", correctPNGs);
}

var directory_points=[]; var map_center={}; var map;


function init_news(){
	init_ticker();
	if (typeof tabberOptions == 'undefined') {
		tabberAutomatic();
	} else {
	  if (!tabberOptions['manualStartup']) {
		tabberAutomatic(tabberOptions);
	  }
	}
}

function init_map(){
	map = new GMap2(document.getElementById("state_map"),{mapTypes:[G_NORMAL_MAP]});
	map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(map_center.lat,map_center.long),5);
	jQuery.each(directory_points, function(i,data){
		var infoTabs; var options;
		options = new Object();
		options.title = data.city+" Attorneys and Lawyers";
		infoTabs = [
				new GInfoWindowTab("Website","<div style=\"width: 100%; height: 100%; text-align: center; display: table-cell; vertical-align: middle;\"><a href=\""+data.name+"\" style=\"line-height: 2em; font-size: 12pt; padding-top: 5px; text-align: center;\" target=\"_blank\">"+data.city+" Attorneys and Lawyers</a></div>"				)
			];
		add_info_marker(map,data.lat,data.long,infoTabs,false,options);
	});
	map.enableDoubleClickZoom();
}
function animator(currentItem) {
	  var distance = currentItem.height();
		+ parseInt(currentItem.css("padding-top"), 10)+ parseInt(currentItem.css("padding-bottom"), 10);
		+ parseInt(currentItem.css("margin-top"), 10)+ parseInt(currentItem.css("margin-bottom"), 10);
		;
		duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.015;
	  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
		currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
		try {
			animator(currentItem.parent().children(":first"));
		} catch(error) {}
	  });
	}
		function init_ticker() {

		var ticker = $("#ticker");

		ticker.css("overflow", "hidden");
		$('li#tabbertab a').click(function(){
			 animator(ticker.children(":first"));
		});
		 animator(ticker.children(":first"));
		ticker.mouseenter(function() {
		  ticker.children().stop();
		});
		ticker.mouseleave(function() {
		  animator(ticker.children(":first"));
		});
	  };
/*==================================================
  $Id: tabber.js,v 1.9 2006/04/27 20:51:51 pat Exp $
  tabber.js by Patrick Fitzgerald pat@barelyfitz.com
  Documentation can be found at the following URL:
  http://www.barelyfitz.com/projects/tabber/
  License (http://www.opensource.org/licenses/mit-license.php)
  Copyright (c) 2006 Patrick Fitzgerald
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  ==================================================*/
function tabberObj(argsObj)
{  var arg;
  this.div = null;
  this.classMain = "tabber";
  this.classMainLive = "tabberlive";
  this.classTab = "tabbertab";
  this.classTabDefault = "tabbertabdefault";
  this.classNav = "tabbernav";
  this.classTabHide = "tabbertabhide";
  this.classNavActive = "tabberactive";
  this.titleElements = ['h2','h3','h4','h5','h6'];
  this.titleElementsStripHTML = true;
  this.removeTitle = true;
  this.addLinkId = false;
  this.linkIdFormat = '<tabberid>nav<tabnumberone>';
  for (arg in argsObj) { this[arg] = argsObj[arg]; }
  this.REclassMain = new RegExp('\\b' + this.classMain + '\\b', 'gi');
  this.REclassMainLive = new RegExp('\\b' + this.classMainLive + '\\b', 'gi');
  this.REclassTab = new RegExp('\\b' + this.classTab + '\\b', 'gi');
  this.REclassTabDefault = new RegExp('\\b' + this.classTabDefault + '\\b', 'gi');
  this.REclassTabHide = new RegExp('\\b' + this.classTabHide + '\\b', 'gi');
  this.tabs = new Array();
  if (this.div) {
    this.init(this.div);
    this.div = null;
  }
}tabberObj.prototype.init = function(e)
{  var
  childNodes,
  i, i2,
  t,
  defaultTab=0,
  DOM_ul,
  DOM_li,
  DOM_a,
  aId,
  headingElement;

  if (!document.getElementsByTagName) { return false; }

  if (e.id) {
    this.id = e.id;
  }

  this.tabs.length = 0;

  childNodes = e.childNodes;
  for(i=0; i < childNodes.length; i++) {

    if(childNodes[i].className &&
       childNodes[i].className.match(this.REclassTab)) {


      t = new Object();


      t.div = childNodes[i];


      this.tabs[this.tabs.length] = t;
      if (childNodes[i].className.match(this.REclassTabDefault)) {
	defaultTab = this.tabs.length-1;
      }
    }
  }

  DOM_ul = document.createElement("ul");
  DOM_ul.className = this.classNav;


  for (i=0; i < this.tabs.length; i++) {
    t = this.tabs[i];
    t.headingText = t.div.title;

    if (this.removeTitle) { t.div.title = ''; }
    if (!t.headingText) {
      for (i2=0; i2<this.titleElements.length; i2++) {
	headingElement = t.div.getElementsByTagName(this.titleElements[i2])[0];
	if (headingElement) {
	  t.headingText = headingElement.innerHTML;
	  if (this.titleElementsStripHTML) {
	    t.headingText.replace(/<br>/gi," ");
	    t.headingText = t.headingText.replace(/<[^>]+>/g,"");
	  }
	  break;
	}
      }
    }
    if (!t.headingText) {
      t.headingText = i + 1;
    }

    DOM_li = document.createElement("li");
    t.li = DOM_li;

    DOM_a = document.createElement("a");
//    DOM_a.appendChild(document.createTextNode(t.headingText));
    DOM_a.innerHTML = t.headingText;
    DOM_a.href = "javascript:void(null);";
    DOM_a.title = t.headingText;
    DOM_a.onclick = this.navClick;
    DOM_a.tabber = this;
    DOM_a.tabberIndex = i;

    if (this.addLinkId && this.linkIdFormat) {

      aId = this.linkIdFormat;
      aId = aId.replace(/<tabberid>/gi, this.id);
      aId = aId.replace(/<tabnumberzero>/gi, i);
      aId = aId.replace(/<tabnumberone>/gi, i+1);
      aId = aId.replace(/<tabtitle>/gi, t.headingText.replace(/[^a-zA-Z0-9\-]/gi, ''));
      DOM_a.id = aId;
    }

    DOM_li.appendChild(DOM_a);

    DOM_ul.appendChild(DOM_li);
  }

  e.insertBefore(DOM_ul, e.firstChild);

  e.className = e.className.replace(this.REclassMain, this.classMainLive);

  this.tabShow(defaultTab);

  if (typeof this.onLoad == 'function') {
    this.onLoad({tabber:this});
  }
  return this;
};
tabberObj.prototype.navClick = function(event)
{  var
  rVal,
  a,
  self,
  tabberIndex,
  onClickArgs;
  a = this;
  if (!a.tabber) { return false; }
  self = a.tabber;
  tabberIndex = a.tabberIndex;
  a.blur();
  if (typeof self.onClick == 'function') {
    onClickArgs = {'tabber':self, 'index':tabberIndex, 'event':event};

    if (!event) { onClickArgs.event = window.event; }
    rVal = self.onClick(onClickArgs);
    if (rVal === false) { return false; }
  }
  self.tabShow(tabberIndex);
  return false;
};
tabberObj.prototype.tabHideAll = function()
{  var i;

  for (i = 0; i < this.tabs.length; i++) {
    this.tabHide(i);
  }
};
tabberObj.prototype.tabHide = function(tabberIndex)
{  var div;
  if (!this.tabs[tabberIndex]) { return false; }

  div = this.tabs[tabberIndex].div;

  if (!div.className.match(this.REclassTabHide)) {
    div.className += ' ' + this.classTabHide;
  }
  this.navClearActive(tabberIndex);
  return this;
};
tabberObj.prototype.tabShow = function(tabberIndex)
{
  var div;
  if (!this.tabs[tabberIndex]) { return false; }

  this.tabHideAll();

  div = this.tabs[tabberIndex].div;

  div.className = div.className.replace(this.REclassTabHide, '');

  this.navSetActive(tabberIndex);

  if (typeof this.onTabDisplay == 'function') {
    this.onTabDisplay({'tabber':this, 'index':tabberIndex});
  }
  return this;
};
tabberObj.prototype.navSetActive = function(tabberIndex)
{
  this.tabs[tabberIndex].li.className = this.classNavActive;
  return this;
};
tabberObj.prototype.navClearActive = function(tabberIndex)
{
  this.tabs[tabberIndex].li.className = '';
  return this;
};
function tabberAutomatic(tabberArgs)
{  var
    tempObj,
    divs,
    i;
  if (!tabberArgs) { tabberArgs = {}; }

  tempObj = new tabberObj(tabberArgs);


  divs = document.getElementsByTagName("div");
  for (i=0; i < divs.length; i++) {


    if (divs[i].className &&
	divs[i].className.match(tempObj.REclassMain)) {


      tabberArgs.div = divs[i];
      divs[i].tabber = new tabberObj(tabberArgs);
    }
  }

  return this;
}

// Add marker with info content
function add_info_marker(map,mlat,mlong,infoTabs,open,options){
  var marker = (arguments.length > 5) ? new GMarker(new GLatLng(mlat,mlong),options) : new GMarker(new GLatLng(mlat,mlong));
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowTabsHtml(infoTabs); }
  );
  GEvent.addListener(marker, "mouseover", function() {
    marker.openInfoWindowTabsHtml(infoTabs); }
  );
  map.addOverlay(marker);
  if (open) {
    marker.openInfoWindowTabsHtml(infoTabs);
  } else {
  	//check if there is a link in the infoTab
  	try {
  	  if (infoTabs[0].contentElem.getElementsByTagName('a').length<1){
		  GEvent.addListener(marker, "mouseout", function() {
			marker.closeInfoWindow(); }
		  );
  	  }
  	} catch (e) {}
  }
}


// Add non-info marker
function add_simple_marker(map,mlat,mlong,options){
  var marker = (arguments.length > 3) ? new GMarker(new GLatLng(mlat,mlong),options) : new GMarker(new GLatLng(mlat,mlong));
  map.addOverlay(marker);
}
// Version 0.2      the .copy() parameters were wrong
// version 1.0      added .show() .hide() .setContents() .setPoint() .setOpacity() .overlap


	try{
      function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
        // Mandatory parameters
        this.point = point;
        this.html = html;

        // Optional parameters
        this.classname = classname||"";
        this.pixelOffset = pixelOffset||new GSize(0,0);
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }
        this.percentOpacity = percentOpacity;
        this.overlap=overlap||false;
      }

      ELabel.prototype = new GOverlay();

      ELabel.prototype.initialize = function(map) {
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
        this.map_ = map;
        this.div_ = div;
        if (this.percentOpacity) {
          if(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=(this.percentOpacity/100);}
          if(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=(this.percentOpacity/100);}
          if(typeof(div.style.opacity)=='string'){div.style.opacity=(this.percentOpacity/100);}
        }
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
      }

      ELabel.prototype.remove = function() {
        this.div_.parentNode.removeChild(this.div_);
      }

      ELabel.prototype.copy = function() {
        return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
      }

      ELabel.prototype.redraw = function(force) {
        var p = this.map_.fromLatLngToDivPixel(this.point);
        var h = parseInt(this.div_.clientHeight);
        this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
        this.div_.style.top = (p.y +this.pixelOffset.height - h) + "px";
      }

      ELabel.prototype.show = function() {
        this.div_.style.display="";
      }

      ELabel.prototype.hide = function() {
        this.div_.style.display="none";
      }

      ELabel.prototype.setContents = function(html) {
        this.html = html;
        this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
        this.redraw(true);
      }

      ELabel.prototype.setPoint = function(point) {
        this.point = point;
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
        this.redraw(true);
      }

      ELabel.prototype.setOpacity = function(percentOpacity) {
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }
        this.percentOpacity = percentOpacity;
        if (this.percentOpacity) {
          if(typeof(this.div_.style.filter)=='string'){this.div_.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(this.div_.style.KHTMLOpacity)=='string'){this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.MozOpacity)=='string'){this.div_.style.MozOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.opacity)=='string'){this.div_.style.opacity=this.percentOpacity/100;}
        }
      }
	 } catch(e){}
function pan_to_selected(selfield,map){
  if (selfield.value == ''){
  	return false;
  }
  latlong = selfield.value.split(',');
  map.panTo(new GLatLng(latlong[0],latlong[1]));
  document.body.focus(); // Remove focus on Select field so mouse wheel does not scroll
}
function add_option(sel, val, txt) {
	var o = document.createElement('option');
	var t = document.createTextNode(txt);
	o.setAttribute("value",val);
	o.appendChild(t);
	sel.appendChild(o);
}

