function expand_Toggle_Panels() {
        var TDs = document.getElementsByTagName("TD");
        for (var no = 0; no < TDs.length; no++) {
            if (TDs[no].className == "TogglePanel_Heading") {
                TDs[no].parentNode.parentNode.rows.item(1).style.display = "";
                TDs[no].style.backgroundImage = "url(/images/exp.gif)";
            }
        }
        //Display the collapse link
        document.getElementById("Link_Expand_All").style.display = "none";
        document.getElementById("Link_Collapse_All").style.display = "";
    }

    function collapse_Toggle_Panels() {
        var TDs = document.getElementsByTagName("TD");
        for (var no = 0; no < TDs.length; no++) {
            if (TDs[no].className == "TogglePanel_Heading") {
                TDs[no].parentNode.parentNode.rows.item(1).style.display = "none";
                TDs[no].style.backgroundImage = "url(/images/col.gif)";
            }
        }
        document.getElementById("Link_Expand_All").style.display = "";
        document.getElementById("Link_Collapse_All").style.display = "none";
    }

/*
Plugin Name: Skinnytip Tooltips
Plugin URI: http://www.ebrueggeman.com/skinnytip
Description: Easy JavaScript tooltip generator for your pages and posts. 
Version: 1.03
Author: Elliott Brueggeman
Author URI: http://www.ebrueggeman.com
Please see readme.txt version for more information.
*/
/*
Note: Above version number pertains directly to the Wordpress plugin.
This file is Skinnytip Core Version: 2.0
*/
/*  Copyright 2008  Elliott Brueggeman  (email : ebrueggeman@gmail.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3. 

License on the web: http://www.gnu.org/licenses/gpl-3.0.txt

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
//Call mouse capture handler function on page load
captureMouse();

//CUSTOM VARS - Initialized below
var v_divname;
var v_text;
var v_title;
var v_xoffset;
var v_yoffset;
var v_backcolor;
var v_bordercolor;
var v_textcolor;
var v_titletextcolor;
var v_width;
var v_border;
var v_title_padding;
var v_content_padding;
var v_fontface;
var v_fontsize;
var v_titlefontsize;

//INTERNAL VARIABLES
var v_xcoordinate = 0;
var v_ycoordinate = 0;
var v_visible = 0;
var v_havemouse = 0;
var v_layer = null;

function tooltip(displaytext, title, commands) {
	//Reset variables for this tool tip
	init_tooltip();
	
	//Title and Text
	v_title=title;
	v_text=displaytext;
	
	//Parse commands if any
	parseCommands(commands);
	
	
	if (v_layer) { 
		v_layer=getLayer(v_divname); 
	}
	
	if (!(v_layer=createDivContainer())) { 
		return false;
	}

	mainMethod();
}

function init_tooltip() {
	
	v_divname = 'tiplayer';
	v_text = 'Default Text';
	v_title = '';
	
	//UI Variables
	v_xoffset = 15;
	v_yoffset = 15;
	v_backcolor = '#FFFFCC';
	v_bordercolor = '#FFCC66';
	v_textcolor = '#000000';
	v_titletextcolor = '#000000';
	v_width = 300;
	
	v_border = 2;
	v_title_padding = '1px';
	v_content_padding = '1px 3px';
	
	v_fontface = 'Arial, Helvetica, Sans-Serif';
	v_fontsize = 10;
	v_titlefontsize = 10;
	
	//SYSTEM VARIABLES
	v_visible = 0;
	v_layer = null;
}

function parseCommands(commands) {
	if (commands != null) {
		var comArray = commands.split(',');
		for (var i = 0; i < comArray.length; i++) {
			var args = comArray[i].split(':');
			eval('v_' + trimWhitespace(args[0]) + '="' + trimWhitespace(args[1]) + '"');
		}
	}
}

// Clears popups if appropriate
function hideTip() {
	if (v_visible == 1) {
		if (v_layer != null) {
			v_layer.style.visibility = 'hidden';
			v_visible = 0;
		}
	}
	return true;
}

function mainMethod() {	
	v_visible = 0;
	
	var html = makeHTML(v_text, v_title);	
	createPopup(html);
	
	//if we have mouse coordinates, position layer and make visible
	if (v_havemouse == 1) {	
		positionLayer();
		v_visible = 1;
		v_layer.style.visibility = 'visible';
	}
}

function makeHTML(text, title) {
	
	var container_style = 'width:' + v_width + 'px;';
	container_style += 'border:' + v_border + 'px solid ' + v_bordercolor + ';';
	container_style += 'background-color:' + v_backcolor + ';';
	container_style += 'font-family:' + v_fontface + ';';
	container_style += 'font-size:' + v_fontsize + 'px;';
	
	var title_style = 'background-color:' + v_bordercolor + ';';
	title_style += 'padding:' + v_title_padding + ';';
	title_style += 'color:' + v_titletextcolor + ';';
	
	var content_style = 'padding:' + v_content_padding + ';';
	content_style += 'color:' + v_textcolor + ';';
	
	var txt = '<div id="skinnytip_container" style="' + container_style + '">';
	if (title!=null && title.length>0) {
		txt += '<div id="skinnytip_title" style="' + title_style + '">' + title + '</div>';
	}
	txt += '<div id="skinnytip_content" style="' + content_style + '">' + text + '</div>';
	txt += '</div>';
	
	return txt;
}

//Positions popup according to mouse input
function positionLayer() {
	
	var placeX = 300;
	var placeY = 300;
	
	//get final placement
	placeX = horizontalPlacement();
	placeY = verticalPlacement();
	
	//Move the object
	v_layer.style.left = placeX + 'px';
	v_layer.style.top = placeY + 'px';
}

//called when the mouse moves
//sets mouse related variables
function mouseMoveHandler(e) {
	if (!e) {
		var e = window.event;
	}
	if (e.clientX) {
	 //if there is an x pos property
	 //GET MOUSE LOCATION
		v_xcoordinate = mouseX(e);
		v_ycoordinate = mouseY(e);	
		v_havemouse = 1;
	}
	if (v_visible == 1) { 
		positionLayer();	
	}
}

//get mouse x coordinate
function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX) {
		i = 0;
		if (document.documentElement.scrollLeft) i = document.documentElement.scrollLeft;
		else if (document.documentElement.scrollLeft) i = document.body.scrollLeft;
		return evt.clientX + i;
	}
	else return null;
}

//get mouse y coordinate
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY) {
		i = 0;
		if (document.documentElement.scrollTop) i = document.documentElement.scrollTop;
		else if (document.documentElement.scrollTop) i = document.body.scrollTop;
		return evt.clientY + i;
	}
	else return null;
}

//Set mouse handler
function captureMouse() {
	document.onmousemove = mouseMoveHandler;
}

//Creates the popup
function createPopup(input) {

	var popupwidth = v_width;
	var text;
	var zindex;
	
	text =  createBackLayer(popupwidth,zindex++);
	text += '<div style="position: absolute; top: 0; left: 0; width: ' + popupwidth + 'px; z-index: ' + zindex + ';">' + input + '</div>';
	
	if (typeof v_layer.innerHTML != 'undefined') {
		v_layer.innerHTML = text;
	} 
	
	//After writing html measure height of backlayer to set height of iframe
	var backlayer=self.document.getElementById("backdrop");
	var container=self.document.getElementById("skinnytip_container");
	backlayer.height = container.offsetHeight;
}

//Back layer prevents forms from showing through popups
function createBackLayer(width, Z) {
	//Create backdrop with 0 height
	return '<iframe id="backdrop" frameborder="0" scrolling="no" width="' + width + '" height="0" style="z-index: ' + Z + '; filter: Beta(Style=0,Opacity=0);"><p></iframe>';
}

//get horizontal box placement
function horizontalPlacement() {
	placeX = v_xcoordinate + v_xoffset;
	return placeX;
}

//get vertical box placement
function verticalPlacement() {
	return v_ycoordinate + v_yoffset;
}

// create the div container for popup content if it doesn't exist
function createDivContainer() {
	var divContainer = self.document.getElementById(v_divname);
	return divContainer;
}

function trimWhitespace(str) {  
	while(str.charAt(0) == (" ") ) {  
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " ) {  
		str = str.substring(0,str.length-1);
	}
	return str;
}


/*
Plugin Name: Skinnytip Tooltips
Plugin URI: http://www.ebrueggeman.com/skinnytip
Description: Easy JavaScript tooltip generator for your pages and posts. 
Version: 1.03
Author: Elliott Brueggeman
Author URI: http://www.ebrueggeman.com
Please see readme.txt version for more information.
*/
/*  Copyright 2008  Elliott Brueggeman  (email : ebrueggeman@gmail.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3. 

License on the web: http://www.gnu.org/licenses/gpl-3.0.txt

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
//function to hide/unhide image and link input areas
function skinnytip_manage_type() {
	var image = self.document.getElementById('skinnytip_type_image');
	var link = self.document.getElementById('skinnytip_type_link');
	var image_div = self.document.getElementById('skinnytip_image_div');
	var link_div = self.document.getElementById('skinnytip_link_div');

	if (image.checked) {
		image_div.style.display = 'block';
	}
	else {
		image_div.style.display = 'none';
	}
	
	if (link.checked) {
		link_div.style.display = 'block';
	}
	else {
		link_div.style.display = 'none';
	}
}

//function to hide/unhide advanced options area
function skinnytip_manage_advanced() {
	var advanced_on = self.document.getElementById('skinnytip_advanced_options_on');
	var advanced_off = self.document.getElementById('skinnytip_advanced_options_off');
	var advanced_div = self.document.getElementById('skinnytip_advanced_div');

	if(advanced_on.checked) {
		advanced_div.style.display = 'block';
	}
	else {
		advanced_div.style.display = 'none';
	}
}

//reset to default variables
function skinnytip_reset_advanced() {
	self.document.getElementById('skinnytip_width').value = '300';
	self.document.getElementById('skinnytip_border_width').value = '2';
	self.document.getElementById('skinnytip_title_padding').value = '1px';
	self.document.getElementById('skinnytip_text_padding').value = '1px 3px';
	self.document.getElementById('skinnytip_backcolor').value = '#FFFFCC';
	self.document.getElementById('skinnytip_titlecolor').value = '#000000';
	self.document.getElementById('skinnytip_textcolor').value = '#000000';
	self.document.getElementById('skinnytip_bordercolor').value = '#FFCC66';
}

//creates skinnytip code and displays in textarea
function skinnytip_manage_code() {
	var image_radio = self.document.getElementById('skinnytip_type_image');
	var link_radio = self.document.getElementById('skinnytip_type_link');
	var code_textarea = self.document.getElementById('skinnytip_code');
	var preview = self.document.getElementById('skinnytip_preview');
	var advanced_options = self.document.getElementById('skinnytip_advanced_options_on');
	var skinnytip_text = skinnytip_trim(self.document.getElementById('skinnytip_text').value);
	var skinnytip_title = skinnytip_trim(self.document.getElementById('skinnytip_title').value);
	var image = skinnytip_trim(self.document.getElementById('skinnytip_image').value);
	var link = skinnytip_trim(self.document.getElementById('skinnytip_link').value);
	var dest = skinnytip_trim(self.document.getElementById('skinnytip_link_dest').value);
	
	//adv options
	var skinnytip_width = skinnytip_trim(self.document.getElementById('skinnytip_width').value);
	var skinnytip_border_width = skinnytip_trim(self.document.getElementById('skinnytip_border_width').value);
	var skinnytip_title_padding = skinnytip_trim(self.document.getElementById('skinnytip_title_padding').value);
	var skinnytip_text_padding = skinnytip_trim(self.document.getElementById('skinnytip_text_padding').value);
	var skinnytip_backcolor = skinnytip_trim(self.document.getElementById('skinnytip_backcolor').value);
	var skinnytip_titlecolor = skinnytip_trim(self.document.getElementById('skinnytip_titlecolor').value);
	var skinnytip_textcolor = skinnytip_trim(self.document.getElementById('skinnytip_textcolor').value);
	var skinnytip_bordercolor = skinnytip_trim(self.document.getElementById('skinnytip_bordercolor').value);
	
	var code_base = '';
	
	if(image_radio.checked) {
		//using image
		code_base += '<img src="' + image + '" ';
	}
	else {
		//using link
		code_base += '<a href="' + dest + '" ';
	}
	
	var code = 'onMouseOver="return tooltip(\''+ skinnytip_text + '\'';
	
	if (skinnytip_title && skinnytip_title.length > 0) {
		code += ', \'' + skinnytip_title + '\'';
	}
	
	if (advanced_options.checked) {
		var has_advanced = false;
		var advanced_code = '';
		
		if (skinnytip_width.length > 0 && skinnytip_width != '300') {
			advanced_code += 'width:' + skinnytip_width + ',';
			has_advanced = true;
		}
		if (skinnytip_border_width.length > 0 && skinnytip_border_width != '2') {
			advanced_code += 'border:' + skinnytip_border_width + ',';
			has_advanced = true;
		}
		if (skinnytip_title_padding.length > 0 && skinnytip_title_padding != '1px') {
			advanced_code += 'title_padding:' + skinnytip_title_padding + ',';
			has_advanced = true;
		}
		if (skinnytip_text_padding.length > 0 && skinnytip_text_padding != '1px 3px') {
			advanced_code += 'content_padding:' + skinnytip_text_padding + ',';
			has_advanced = true;
		}
		if (skinnytip_backcolor.length > 0 && skinnytip_backcolor != '#FFFFCC') {
			advanced_code += 'backcolor:' + skinnytip_backcolor + ',';
			has_advanced = true;
		}
		if (skinnytip_titlecolor.length > 0 && skinnytip_titlecolor != '#000000') {
			advanced_code += 'titletextcolor:' + skinnytip_titlecolor + ',';
			has_advanced = true;
		}
		if (skinnytip_textcolor.length > 0 && skinnytip_textcolor != '#000000') {
			advanced_code += 'textcolor:' + skinnytip_textcolor + ',';
			has_advanced = true;
		}
		if (skinnytip_bordercolor.length > 0 && skinnytip_bordercolor != '#FFCC66') {
			advanced_code += 'bordercolor:' + skinnytip_bordercolor + ',';
			has_advanced = true;
		}
		
		if (has_advanced) {
		
			//remove last comma from advanced_code
			var len = advanced_code.length;
			if (advanced_code.substring(len-1,len) == ',') {
				advanced_code = advanced_code.substring(0, len-1);
			}
			
			//if no title, add as empty param, so we can set advanced options
			if (skinnytip_title.length == 0) {
				code +=", ''";
			}
		
			code += ', \'' + advanced_code +  '\'';
		}
	}
	
	code += ');"';
	code += ' onMouseOut="return hideTip();"';
	
	//output preview to preview widget
	preview.innerHTML = '<a href="#" ' + code + ' onClick="return false;"><strong>Preview this tooltip</strong></a>';
	
	//after preview, add code base back to code
	code = code_base + code + '>';
	
	//if we are making a link, close the link
	if(!image_radio.checked) {
		code += link + '</a>';
	}
	
	//output to textarea
	code_textarea.value = code;
}

//trim function to remove whitespace
function skinnytip_trim(str) {
	if (typeof(str) != 'undefined' && str.length > 0) {
		while (str.charAt(0) == (" ") ) {  
			str = str.substring(1);
		}
		while (str.charAt(str.length-1) == " " ) {  
			str = str.substring(0,str.length-1);
		}
	}
	return str;
}

//helper function to display instructions inside text input boxes
function skinnytip_manage_greyed_input(input, focus, default_value) {
	if (focus == 'true' && input.value == default_value) {
		input.value = '';
	}
	else if (focus == 'false' && input.value.length == 0) {
		input.value = default_value;
	}
}

