/***************************************************************************
# File: lib_window_effects.js - JavaScript Window Effects
# Version: 1.2.1
***************************************************************************/

/**** Window Effects ****/
function WindowEffects()
{
	if(window.bjs_debugger_flag != undefined) // Ex: debugger call >> ob_win_eff.AddDebug("debug message here")
		this.debuggr = true;

	this.doc_kids = document.getElementsByTagName("*");
	this.doc_kids_a = document.getElementsByTagName("A");
	this.doc_kids_img = document.getElementsByTagName("IMG");
	
	this.slideshow_delay = 5000;
	this.slideshow_cnt = 0;
	this.slideshow_img_id = '';
	
	this.slide_increment = 175;
	this.slide_delay = 0;
	this.element_sliding_id = '';
	this.element_sliding_id_original_height = '';
	this.element_sliding_id_new_height = '';
	this.is_sliding = false;
	
	
	this.match_class_display_block = /display_block/;
	this.match_class_display_inline = /display_inline/;
	this.match_class_display_none = /display_none/;
	
	this.replace_class_display_block = "display_block";
	this.replace_class_display_inline = "display_inline";
	this.replace_class_display_none = "display_none";	
	
	this.replace_none = "";

	return this;
}

// Method -- Should we debug?
WindowEffects.prototype.AddDebug = function(in_line)
{
	if(ob_win_eff.debuggr)
		ob_win_bjs.AddItem(in_line);
}

// Method -- Init the Image rollovers
WindowEffects.prototype.RollOverInit = function()
{
	var match_class = "image_rollover";
	
	for(var i=0; i < ob_win_eff.doc_kids_img.length; i++)
	{
		if(ob_win_eff.doc_kids_img[i].className.match(match_class))
		{
			ob_win_eff.doc_kids_img[i].onmouseover = ob_win_eff.DoRollOvers;
			ob_win_eff.doc_kids_img[i].onmouseout = ob_win_eff.UndoRollOvers;
		}
	}
}
	// Method -- Do the image rollover
	WindowEffects.prototype.DoRollOvers = function()
	{
		var img_id = document.getElementById(this.id);
		
		original_img_name = this.id;
		original_img_name_reg = new RegExp(original_img_name, 'gi');
		replace_img_name = this.name;
		
		img_id.src = img_id.src.replace(original_img_name_reg, replace_img_name);
	}
		// Method -- Undo the image rollover
		WindowEffects.prototype.UndoRollOvers = function()
		{
			var img_id = document.getElementById(this.id);
			
			original_img_name = this.name;
			original_img_name_reg = new RegExp(original_img_name, 'gi');
			replace_img_name = this.id;
			
			img_id.src = img_id.src.replace(original_img_name_reg, replace_img_name);
		}


// Method -- Init the Image slideshow
WindowEffects.prototype.SlideShowInit = function()
{
	var match_class = "image_slideshow";
	ob_win_eff.slideshow_images = window.image_slideshow.split("|");
	
	for(var i=0; i < ob_win_eff.doc_kids_img.length; i++)
	{
		if(ob_win_eff.doc_kids_img[i].className.match(match_class))
		{
			ob_win_eff.slideshow_img_id = ob_win_eff.doc_kids_img[i].id;
			ob_win_eff.SlideShowGo();
		}
	}
}
	// Method -- Do the Image slideshow
	WindowEffects.prototype.SlideShowGo = function()
	{
		ob_win_eff.slideshow_cnt++;

		if(ob_win_eff.slideshow_cnt == ob_win_eff.slideshow_images.length)
			ob_win_eff.slideshow_cnt = 0;
		
		document.getElementById(ob_win_eff.slideshow_img_id).src = ob_win_eff.slideshow_images[ob_win_eff.slideshow_cnt];
		
		setTimeout("ob_win_eff.SlideShowGo()", ob_win_eff.slideshow_delay);
	}


// Method -- Get an elements height
WindowEffects.prototype.GetElementHeight = function(in_element)
{
	ob_win_eff.element_sliding_height = document.getElementById(in_element).offsetHeight;
}


// Method -- Init the anchor popups
WindowEffects.prototype.PopUpsInit = function()
{
	var match_class = "open_popup";
	for(var i=0; i < ob_win_eff.doc_kids_a.length; i++)
	{
		if(ob_win_eff.doc_kids_a[i].className.match(match_class))
			ob_win_eff.doc_kids_a[i].onclick = ob_win_eff.PopUpClick;
	}
}
	// Method -- Open the popup
	WindowEffects.prototype.PopUpClick = function()
	{
		if(this.rel == "normal")
		{
			new_window = window.open(this.href, 'newWin');
		}
		else
		{
			var win_dims = this.rel.split('x');
			window_options = 'toolbar=no,location=no,resizable=yes,scrollbars=yes,menubar=no,width=' + win_dims[0] + ',height=' + win_dims[1];
			new_window = window.open(this.href, 'newWin', window_options);
		}

		return false;
	}


// Method -- Init the Confirm clicks
WindowEffects.prototype.ConfirmClickInit = function()
{
	var match_class = "confirm_click";
	for(var i=0; i < ob_win_eff.doc_kids.length; i++)
	{
		if(ob_win_eff.doc_kids[i].className.match(match_class))
			ob_win_eff.doc_kids[i].onclick = ob_win_eff.ConfirmClick;
	}
}
	// Method -- Throw up the Confirm box
	WindowEffects.prototype.ConfirmClick = function()
	{
		if(confirm(this.title))
			return true;
		else
			return false;
	}


// Method -- Init the toggle clicks
WindowEffects.prototype.ToggleDisplayInit = function()
{
	var match_class = "toggle_display";
	for(var i=0; i < ob_win_eff.doc_kids.length; i++)
	{
		if(ob_win_eff.doc_kids[i].className.match(match_class))
			ob_win_eff.doc_kids[i].onclick = ob_win_eff.ToggleDisplay;
	}
}
	// Method -- Toggle the block content
	WindowEffects.prototype.ToggleDisplay = function()
	{
		var toggle_this = this.id.split(".");
		var toggle_this_switch_on = document.getElementById(toggle_this[0] + ".inline");
		var toggle_this_switch_off = document.getElementById(toggle_this[0] + ".none");
		var toggle_this_content = document.getElementById(toggle_this[0]);
				
		var match_inline = /inline/;
		var replace_inline = "inline";
		
		var match_none = /none/;
		var replace_none = "none";
		
		
		if(this.rel == "table-row")
		{
			var match_block = "table-row";
			var replace_block = "table-row";
		}
		else
		{
			var match_block = "block";
			var replace_block = "block";
		}
		

		if(toggle_this_switch_on.className.match("inline"))
		{
			toggle_this_switch_on.className = toggle_this_switch_on.className.replace(match_inline, replace_none);
			toggle_this_switch_off.className = toggle_this_switch_off.className.replace(match_none, replace_inline);
			toggle_this_content.className = toggle_this_content.className.replace(match_block, replace_none);
		}
		else
		{
			toggle_this_switch_on.className = toggle_this_switch_on.className.replace(match_none, replace_inline);
			toggle_this_switch_off.className = toggle_this_switch_off.className.replace(match_inline, replace_none);
			toggle_this_content.className = toggle_this_content.className.replace(match_none, replace_block);
		}

		return false;
	}


// Method -- Init the tabs
WindowEffects.prototype.ToggleTabsInit = function(in_current_tab_set)
{
	var match_class = in_current_tab_set;
	for(var i=0; i < ob_win_eff.doc_kids_a.length; i++)
	{
		if(ob_win_eff.doc_kids_a[i].className.match(match_class))
			ob_win_eff.doc_kids_a[i].onclick = ob_win_eff.ToggleTabs;
	}
}
	// Method -- Switch the tabs
	WindowEffects.prototype.ToggleTabs = function()
	{
		var match_current_tab = /tab_links_current/;
		var match_toggle_tabs = "toggle_tabs"
		var current_tab_class = "tab_links_current";
		var current_tab_split = this.id.split(".");
		var current_tab_block = document.getElementById(current_tab_split[0]);
		var current_tab_set = this.rel;

		// set clicked tab to be active and the others not
		for(var i=0; i < ob_win_eff.doc_kids_a.length; i++)
		{
			if(ob_win_eff.doc_kids_a[i].className.match(current_tab_set))
				ob_win_eff.doc_kids_a[i].className = ob_win_eff.doc_kids_a[i].className.replace(match_current_tab, ob_win_eff.replace_none);

			if(ob_win_eff.doc_kids_a[i].id == this.id)
			{
				ob_win_eff.doc_kids_a[i].className = ob_win_eff.doc_kids_a[i].className = ob_win_eff.doc_kids_a[i].className + " " + current_tab_class;
				ob_win_eff.doc_kids_a[i].blur();
			}
		}

		// Set all tab containers to be hidden
		for(var i=0; i < ob_win_eff.doc_kids.length; i++)
		{
			if(ob_win_eff.doc_kids[i].className.match(current_tab_set))
				ob_win_eff.doc_kids[i].className = ob_win_eff.doc_kids[i].className.replace(ob_win_eff.match_class_display_block, ob_win_eff.replace_class_display_none);
		}

		// Set current tab container to be visible
		current_tab_block.className = current_tab_block.className.replace(ob_win_eff.replace_class_display_none, ob_win_eff.replace_class_display_block);

		return false;
	}


// Method -- Init the drop down menu hovers
WindowEffects.prototype.SetMenuHoversInit = function(in_object)
{
	if(document.getElementById(in_object))
	{
		var li_hovers_tags = document.getElementById(in_object).getElementsByTagName('LI');
	
		for(var i=0; i < li_hovers_tags.length; i++)
		{
			if(li_hovers_tags[i].id)
			{
				var ul_blocks_tags = document.getElementById(li_hovers_tags[i].id).getElementsByTagName('UL');
	
				if(ul_blocks_tags.length == 1)
				{
					li_hovers_tags[i].onmouseover = ob_win_eff.SetMenuHoversHoverOn;
					li_hovers_tags[i].onmouseout = ob_win_eff.SetMenuHoversHoverOff;
				}
			}
		}
	}
}
	// Method -- Show the drop down
	WindowEffects.prototype.SetMenuHoversHoverOn = function()
	{
		var ul_blocks_tags = document.getElementById(this.id).getElementsByTagName('UL');
		ul_blocks_tags[0].className = "menu_hover_on";
	}
	
	// Method -- Hide the drop down
	WindowEffects.prototype.SetMenuHoversHoverOff = function()
	{
		var ul_blocks_tags = document.getElementById(this.id).getElementsByTagName('UL');
		ul_blocks_tags[0].className = "menu_hover_off";
	}


// Method -- Get any and all dimensions for the window and the page
WindowEffects.prototype.GetViewPort = function()
{
	ob_win_eff.window_x = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	ob_win_eff.window_y = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	ob_win_eff.scroll_y = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	ob_win_eff.scroll_y = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	ob_win_eff.page_x = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
	ob_win_eff.page_y = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}
	WindowEffects.prototype.SetElementHeight = function(in_element, in_height)
	{
		document.getElementById(in_element).style.height = in_height + "px";
	}




/***************************************/
/*** Code Below is under development ***/

WindowEffects.prototype.SlideContentInit = function(in_element)
{
	// ob_win_eff.AddDebug("Executing >> SlideContentInit");

	var match_class = "sliding_content";
	for(var i=0; i < ob_win_eff.doc_kids_a.length; i++)
	{
		if(ob_win_eff.doc_kids_a[i].className.match(match_class))
			ob_win_eff.doc_kids_a[i].onclick = ob_win_eff.SlideContentClick;
	}
}
	WindowEffects.prototype.SlideContentClick = function()
	{
		ob_win_eff.AddDebug("Executing >> SlideContentClick for this.id (" + this.id + ")");

		var slide_parts = this.id.split("."); // example_id.example_id_box.300
		ob_win_eff.element_sliding_id_original_height = document.getElementById(slide_parts[1]).offsetHeight;
		
		if(slide_parts[2] == "auto")
		{
			ob_win_eff.AddDebug("slide_parts[2] == auto");

			ob_win_eff.is_sliding = true;
			ob_win_eff.SlideContent(slide_parts[1], "up");
		}
		else
		{
			ob_win_eff.AddDebug("slide_parts[2] != auto");

			ob_win_eff.is_sliding = true;
			ob_win_eff.SlideContent(slide_parts[1], "down");
		}
	}


	// function doSlide(inSlideObject,whichWay)
	WindowEffects.prototype.SlideContent = function(in_element, in_slide_direction)
	{
		ob_win_eff.AddDebug("Executing >> SlideContent for in_element (" + in_element + ")");

		in_element_sliding_id = document.getElementById(in_element);
		ob_win_eff.AddDebug("in_element_sliding_id.style.height = " + in_element_sliding_id.style.height);

		if(ob_win_eff.is_sliding == true)
		{
			ob_win_eff.AddDebug("ob_win_eff.is_sliding == true");

			if(in_slide_direction == "down")
			{
				ob_win_eff.AddDebug("in_slide_direction == down");

				if(ob_win_eff.element_sliding_id_new_height < ob_win_eff.element_sliding_id_original_height)
				{
					in_element_sliding_id.style.height = ob_win_eff.element_sliding_id_new_height + "px";
					ob_win_eff.element_sliding_id_new_height = ob_win_eff.element_sliding_id_new_height + ob_win_eff.slide_increment;
					setTimeout('ob_win_eff.SlideContent("example_id_box", "down")', ob_win_eff.slide_delay);
				}
				else
				{
					ob_win_eff.is_sliding = false;
					in_element_sliding_id.style.height = ob_win_eff.element_sliding_id_original_height + "px";
				}
			}
			else
			{
				ob_win_eff.AddDebug("in_slide_direction != down");

				if(ob_win_eff.element_sliding_id_new_height > ob_win_eff.element_sliding_id_original_height)
				{
					in_element_sliding_id.style.height = ob_win_eff.element_sliding_id_new_height + "px";
					ob_win_eff.element_sliding_id_new_height = ob_win_eff.element_sliding_id_new_height - ob_win_eff.slide_increment;
					setTimeout('ob_win_eff.SlideContent("example_id_box", "up")', ob_win_eff.slide_delay);
				}
				else
				{
					ob_win_eff.is_sliding = false;
					in_element_sliding_id.style.height = ob_win_eff.element_sliding_id_original_height + "px";
					in_element_sliding_id.style.overflow = "auto";
				}
			}
		}
		
		ob_win_eff.AddDebug("ob_win_eff.is_sliding != true");
	
	}

