// JavaScript Document


function scrollVertical(value, element, slider) {

	element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));

}

function showAddress(address, title) {

  geocoder.getLatLng(

    address,

    function(point) {

      if (!point) {

        alert(address + " not found");

      } else {

        map.setCenter(point, 13);

        var marker = new GMarker(point);

        map.addOverlay(marker);

        marker.openInfoWindowHtml(title+'<p>'+address+'</p>');

      }

    }

  );

}

function showAddress2(address, title) {

  geocoder.getLatLng(

    address,

    function(point) {

      if (!point) {

        alert(address + " not found");

      } else {

        map.setCenter(point, 13);

        var marker = new GMarker(point);

        map.addOverlay(marker);

        //marker.openInfoWindowHtml(title+'<p>'+address+'</p>');

      }

    }

  );

}

function getTerm() {
	if($('term_0') == null || $('term_0') == 'undefined' || $('term_0').innerHTML == '') {
		$('livesearch').innerHTML = 'It appears your location is not in our system. Perhaps try a larger town or city nearby. Once you see an acceptable location in this list click enter to see lawyers in your area.';
		$('livesearch').show();
		return false;
	}
	else {
		$('liveTerm').value=$('term_0').innerHTML;
		location.href="/Impaired_Driving_Lawyers/"+$('prov_0').innerHTML+"/"+escape($('term_0').innerHTML)+"/";
		return false;
		}
		return false;
}
function getTerm2() {
	if($('term_0') == null || $('term_0') == 'undefined' || $('term_0').innerHTML == '') {
		$('livesearch2').innerHTML = 'It appears your location is not in our system. Perhaps try a larger town or city nearby. Once you see an acceptable location in this list click enter to see lawyers in your area.';
		$('livesearch2').show();
		return false;
	}
	else {
		$('liveTerm2').value=$('term_0').innerHTML;
		
		location.href="/Criminal_Charges_Lawyers/"+$('prov_0').innerHTML+"/"+escape($('term_0').innerHTML)+"/";
		return false;
		}
		return false;
}

function showResult(searchTerm) {

	$('livesearch').show();
	new Ajax.Updater('livesearch', '/getCity.php?searchTerm='+searchTerm, { method: 'get' });		

}

function showResult2(searchTerm) {

	$('livesearch2').show();
	new Ajax.Updater('livesearch2', '/getCity.php?searchTerm='+searchTerm, { method: 'get' });		

}
function bookmark() {
	
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(document.title, location.href,"");
	} 
	else if( document.all ) { //MSIE
		window.external.AddFavorite( location.href, document.title);
	} 
	else {
		alert("Sorry, your browser doesn't support this");
	}
}
/**
* Lightbox
*
* This libary is used to create a lightbox in a web application.  This library
* requires the Prototype 1.6 library and Script.aculo.us core, effects, and dragdrop
* libraries.  To use, add a div containing the content to be displayed anywhere on 
* the page.  To create the lightbox, add the following code:
*
*	var test;
*	
*	Event.observe(window, 'load', function () {
*		test = new Lightbox('idOfMyDiv');
*	});
*	
*	Event.observe('lightboxLink', 'click', function () {
*		test.open();
*	});
*
*	Event.observe('closeLink', 'click', function () {
*		test.close();
*	});
*     
*/

var Lightbox = Class.create({
	open : function () {
		this._centerWindow(this.container);
		this._fade('open', this.container);
	},
	
	close : function () {
		this._fade('close', this.container);
	},
	
	_fade : function fadeBg(userAction,whichDiv){
		if(userAction=='close'){
			$("bg_fade").style.visibility="hidden";
			$("bg_fade").style.display="none";
			$("containerDiv").style.visibility="hidden";
			$("containerDiv").style.display="none";
			$("containerDiv2").hide();
			$("containerDiv2").hide();

		}else{
			new Effect.Opacity('bg_fade',
					   {duration:.5,
					    from:0,
					    to:0.5,
					    beforeUpdate:this._makeVisible,
					    afterFinish:this._showLayer(whichDiv)});
		}
	},
	
	_makeVisible : function makeVisible(){
		$("bg_fade").style.visibility="visible";
	},

	_makeInvisible : function makeInvisible(){
		$("bg_fade").style.visibility="hidden";
		$("bg_fade").style.display="none";
	},

	_showLayer : function showLayer(userAction){
		$(userAction).style.display="block";
	},
	
	_hideLayer : function hideLayer(userAction){
		$(userAction).style.display="none";
	},
	
	_centerWindow : function centerWindow(element) {
		var windowHeight = parseFloat($(element).getHeight())/2; 
		var windowWidth = parseFloat($(element).getWidth())/2;

		if(typeof window.innerHeight != 'undefined') {
			$(element).style.top = Math.round(document.body.offsetTop + ((window.innerHeight - $(element).getHeight()))/2)+'px';
			$(element).style.left = Math.round(document.body.offsetLeft + ((window.innerWidth - $(element).getWidth()))/2)+'px';
		} else {
			$(element).style.top = Math.round(document.body.offsetTop + ((document.documentElement.offsetHeight - $(element).getHeight()))/2)+'px';
			$(element).style.left = Math.round(document.body.offsetLeft + ((document.documentElement.offsetWidth - $(element).getWidth()))/2)+'px';
		}
	},
	
	initialize : function(containerDiv) {
		this.container = containerDiv;
		if($('bg_fade') == null) {
			var screen = new Element('div', {'id': 'bg_fade'});
			document.body.appendChild(screen);
		}
		new Draggable(this.container);
		this._hideLayer(this.container);
	}
});



