//// *********************************** ////
//// State of California master template ////
////             Version 1.20            ////
////       Last Updated 03/23/2007       ////
////                                     ////
//// Add your own Department-specific    ////
//// scripts here.                       ////
//// *********************************** ////

// selectSearch - If you are not using DTS site search you may delete lines 10-to-25
// Choose between the statewide search and your own local site search.
//

function selectSearch() { 
	if (document.getElementById("control").which[0].checked) {
	  document.getElementById("ca_form").q.value = document.getElementById("search").value;
	  document.getElementById("ca_form").submit();
	} else {
		// Change the 'q' to the parameter your search engine uses for its text field
	  document.getElementById("local_form").q.value = document.getElementById("search").value;
	  document.getElementById("local_form").submit();
	}
  return false;
}

// End of selectSearch javascript

var serpLocation = "/serp.html"; // Location of your search engine results page (SERP)

// addLoadEvent by Simon Willison
// Adds a handler to an event without over-riding other handlers
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

// get URL parameter
function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}



// Switch between the statewide search and local site search forms.
var replaceSearchRadioButtons = {
	init: function() {

		var headSearchElement = document.getElementById("head_search");
		if (headSearchElement){
			headSearchElement.className = headSearchElement.className.replace("javascript_off", "javascript_on"); // Enable the styles that we want to apply only when javascript is enabled
		}

		if (document.getElementById("local_form")) {
			document.getElementById("search_local_textfield").setAttribute("autocomplete","off");
			document.getElementById("local_form").action = serpLocation;
			document.getElementById("local_form").cof.value = "FORID:10";
		}
		if (document.getElementById("ca_form")) {
			document.getElementById("search_ca_textfield").setAttribute("autocomplete","off");
			document.getElementById("ca_form").action = serpLocation;
			document.getElementById("ca_form").cof.value = "FORID:10";
		}
		if (document.getElementById("head_srch_local") && document.getElementById("head_srch_ca")) {
			document.getElementById("head_srch_local").onclick = replaceSearchRadioButtons.setRadioImages; // add event handlers to the radio buttons
			document.getElementById("head_srch_ca").onclick = replaceSearchRadioButtons.setRadioImages;

			var param_cx = unescape(gup('cx'));
			var titleElement = document.getElementById("serp_title");
			if (param_cx) { // is this a serp?
				if (param_cx == "001779225245372747843:mdsmtl_vi1a") { // statewide search?
					document.getElementById("head_srch_ca").checked = true;
					if (titleElement)
						titleElement.innerHTML = "Statewide Search Results";
				} else {
					if (titleElement)
						titleElement.innerHTML = "Local Search Results";
				}
			}

			replaceSearchRadioButtons.setRadioImages(); // set initial state of background images
		}
	},
	setRadioImages: function() { // set images to match radio buttons
		
		if (document.getElementById("head_srch_local").checked && document.getElementById("ca_form").className == "") {
			document.getElementById("search_local_textfield").value = document.getElementById("search_ca_textfield").value; // copy the text field value
			document.getElementById("ca_form").className = "hidden"; // hide the statewide search form
			document.getElementById("local_form").className = ""; // show the local search form
		}

		if (document.getElementById("head_srch_ca").checked && document.getElementById("local_form").className == "") {
			document.getElementById("search_ca_textfield").value = document.getElementById("search_local_textfield").value;
			document.getElementById("local_form").className = "hidden";
			document.getElementById("ca_form").className = "";
		}
	}
}
addLoadEvent(replaceSearchRadioButtons.init);




// Carousel script

var Carousel = {
	isMouseBtnPressed: 0, // Is the mouse button being pressed?
	currentSpeed: 0, // current carousel speed
	minimumSpeed: 2, // minimum speed
	maximumSpeed: 30, // maximum speed
	hitTheBrakes: 0, // Did the user move the mouse off the arrow?
	scrollThis: null, // the "caro_images2" element
	scrolldelay: null, // timer ID

	// This function updates the position of the "caro_images2" element. It calls itself
	// recursively during movement.
	caroScroll:function (sDirection) {
		var iDirection = (sDirection == "Left") ? 1 : -1; // Left arrow moves in positive direction, right arrow negative

		if (Carousel.isMouseBtnPressed && !Carousel.hitTheBrakes) { // "!Carousel.hitTheBrakes" needed in case user clicks and drags off arrow
			Carousel.currentSpeed += iDirection; // Accelerate
			if (Math.abs(Carousel.currentSpeed) > Carousel.maximumSpeed) // Are we exceeding the speed limit?
				Carousel.currentSpeed = iDirection * Carousel.maximumSpeed; // Set speed to maximum
		} else { // mouseup or mouseout
			Carousel.currentSpeed -= iDirection; // Decelerate
			if (iDirection == 1) { // Left arrow
				if (Carousel.currentSpeed < Carousel.minimumSpeed) { // too slow?
					if (Carousel.hitTheBrakes) { // mouse out?
						Carousel.currentSpeed = 0; // come to a stop
					} else {
						Carousel.currentSpeed = Carousel.minimumSpeed; // set speed to minimum
					}
				}
			} else { // Right arrow
				if (Carousel.currentSpeed > -Carousel.minimumSpeed) { // too slow?
					if (Carousel.hitTheBrakes) { // mouse out?
						Carousel.currentSpeed = 0; // come to a stop
					} else {
						Carousel.currentSpeed = -Carousel.minimumSpeed; // set speed to minimum
					}
				}
			}
		}

		if (iDirection == 1) { // left arrow
			if (parseInt(Carousel.scrollThis.style.left) < 0) { // not at the left edge?
				updatePosition();
			} else { // we're at the left edge
				document.getElementById("caro_left").style.backgroundPosition = '-40px 0px'; // grey left arrow
			}
		} else { // right arrow
			if ( ( document.getElementById("caro_images1").offsetWidth - parseInt(Carousel.scrollThis.style.left) ) < Carousel.scrollThis.offsetWidth ) { // not at the right edge?
				// (width of container) - (position of scroller) < (full width of the content)
				updatePosition();
			} else { // we're at the right edge
				document.getElementById("caro_right").style.backgroundPosition = '-102px 0px'; // grey right arrow
			}
		}

		function updatePosition() {
			document.getElementById("caro_left").style.backgroundPosition = '-9px 0px'; // blue left arrow
			document.getElementById("caro_right").style.backgroundPosition = '-71px 0px'; // blue right arrow
			Carousel.scrollThis.style.left=parseInt(Carousel.scrollThis.style.left) + Carousel.currentSpeed + 'px'; // Update position of scrollThis
			if (Carousel.currentSpeed) {
				clearTimeout(Carousel.scrolldelay); // fix problem where user moves mouse quickly from one arrow to the other
				Carousel.scrolldelay = setTimeout('Carousel.caroScroll("' + sDirection + '")',30); // scrolls every __ milliseconds
			}
		}
	},

	// This function inserts the arrows.  It is called on page load.
	initialize:function () {
		if (document.getElementById && document.getElementById("carousel")) { // Make sure browser supports getElementById and div "carousel" exists

			// Check to see if CSS is enabled
			var elementCaroRight = document.getElementById("caro_images1");
			if (elementCaroRight.currentStyle) { // for IE
				var styleCaroRight = elementCaroRight.currentStyle["position"];
			}
			else if (window.getComputedStyle) { // for FF
				var styleCaroRight = document.defaultView.getComputedStyle(elementCaroRight,null).getPropertyValue("position");
			}
			if (styleCaroRight == "relative") { /* CSS is enabled */

				var filenameArrows = "images/carousel/carousel.png";

				if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ // Check for IE
					var ieversion=new Number(RegExp.$1)
					if (ieversion <= 6){
						filenameArrows = "images/carousel/carousel.gif"; // IE6 doesn't support transparent png, so use gif
					}
				}

				Carousel.scrollThis = document.getElementById("caro_images2");
				Carousel.scrollThis.style.left = "0px";

				document.getElementById("caro_images1").style.overflow="hidden"; /* Hide the scrollbars */

				document.getElementById("caro_left").style.background = 'transparent url(' + filenameArrows + ') -40px 0px no-repeat'; // left arrow starts grey
				document.getElementById("caro_left").style.width = '23px';
				document.getElementById("caro_left").style.height = '50px';

				document.getElementById("caro_right").style.background = 'transparent url(' + filenameArrows + ') -71px 0px no-repeat'; // right arrow starts blue
				document.getElementById("caro_right").style.width = '23px';
				document.getElementById("caro_right").style.height = '50px';

			}
		}
	}
}

addLoadEvent(Carousel.initialize);

// -->



