/* Copyright 2000 Adobe Systems. You may copy, modify, and distribute
*  this file, if you include this notice & do not charge for the distribution.
*  This file is provided "AS-IS" without warranties of any kind, including any
*  implied warranties.
*
*  Author:  Glen H. Gersten
*
*
*  This script will perform various manipulations on SVG elements including:
*  fill color changes, stroke width changes, stroke color changes,
*  showing hidden elements, and hiding visible elements.
*
*  To use these functions, this script will need to be sourced into the base document.
*
*  To source this file into an SVG document, use syntax similar to the following:
*	<script xlink:href="events.js" language="JavaScript"></script>
*
*  To source this file into an HTML document, use syntax similar to the following:
*	<script src="events.js" language="JavaScript"></script>
*
*
*  To actually use the functions, you must do the following in the SVG:
*	1. Make sure the element being manipulated has been assigned an id.
*	2. Add event handlers such as onmouseover, onmouseout, or onclick to
*	    the element which will trigger the change.
*	3. Make sure the right arguments are supplied to the function.
*
*  An example of how to change the color of a rectangle called "box" would be:
*	onmouseover="elemColor(evt, 'box', '#336699')"
*/




//////////////////////////////
// Declare Global Variables //
//////////////////////////////
var SVGDoc = null


// Make sure we're using the correct SVG object on the page
//   - there can be more than 1 sourced element
//
function getObj(mouseEvent) {
	SVGDoc = mouseEvent.getTarget().getOwnerDocument();
}



////////////////////////////////
// SVG Manipulation Functions //
////////////////////////////////

// change the fill color of an element
function elemColor(mouseEvent, elemName, value) {
	// get the proper SVG object
	getObj(mouseEvent);

	// check for AI converted spaces
	elemName = spaceTrans(elemName);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle();

	// perform the fill color change
	thisElem.setProperty('fill', value);
}


// change the stroke width of an element
function elemStrokeWidth(mouseEvent, elemName, value) {
	// get the proper SVG object
	getObj(mouseEvent);

	// check for AI converted spaces
	elemName = spaceTrans(elemName);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle()
	
	// perform the stroke width change
	thisElem.setProperty('stroke-width', value);
}


// change the stroke color of an element
function elemStrokeColor(mouseEvent, elemName, value) {
	// get the proper SVG object
	getObj(mouseEvent);

	// check for AI converted spaces
	elemName = spaceTrans(elemName);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle()
	
	// perform the stroke color change
	thisElem.setProperty('stroke', value);
}


// show an element - note: these work with the display property, not visibility
function elemShow(mouseEvent, elemName) {//window.alert(elemName);
	// get the proper SVG object
	getObj(mouseEvent);

	// check for AI converted spaces
	elemName = spaceTrans(elemName);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle();
	
	// make the element visible
	thisElem.setProperty('display', 'inline');
}


// hide an element - note: these work with the display property, not visibility
function elemHide(mouseEvent, elemName) {
	// get the proper SVG object
	getObj(mouseEvent);

	// check for AI converted spaces
	elemName = spaceTrans(elemName);
	
	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle();
	
	// hide the element
	thisElem.setProperty('display', 'none');
}


// translate spaces into equivalent AI exported space string
function spaceTrans(stringIn) {
	var result = "";
	for (var i = 0; i < stringIn.length; i++) {
		if (stringIn.charAt(i) == " ") {
			result += "_x0020_";
		} else {
			result += stringIn.charAt(i);
		}
	}
	return result;
}

// change the filter effect of an element
function elemFilter(mouseEvent, elemName, value) {
	// get the proper SVG object
	getObj(mouseEvent);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle();

	// perform the filter effect change
	thisElem.setProperty('filter', value);
}

function elemOpacity(mouseEvent, elemName, value) {
	// get the proper SVG object
	getObj(mouseEvent);

	// get the element we want to change
	var thisElem = SVGDoc.getElementById(elemName).getStyle();

	// perform the filter effect change
	thisElem.setProperty('opacity', value);
}

