/* =============================================================================
Description:
	A custom show/hide function - similar to "ibm-twisty", but with:
	- a custom trigger (default settings uses [+]/[-] instead of blue arrows
		used by ibm-twisty)
	- triggers and texts can be customized (i.e. translated) by changing values
		in jQuery.fn.itmCommonShowHide.config within your page (as inline code,
		but this has to be put after the link to this JS file)
	- the whole section head clickable

Author:
	Jan Mac/Slovakia/IBM

Version:
	- v1.1, 2009-03-02:
		- added 'config', allowing better customization/localization
		- query string detection was rewritten (switched to RegExp)
		- formatted code to fit 80 lines, added a few extra comments
	- v1.0, 2009-02-25: initial release into production

Requires:
	//www.ibm.com/common/js/ibmcommon.js
	
Default location:
	//www.ibm.com/itsolutions/uk/js/itmcommon-show-hide.js

	Please do not link directly to the default location outside of
	ibm.com/itsolutions/uk - create a local copy of the script instead.

Sample usage:
	<p class="itm-show-hide-head"><a href="#divId">Trigger_text</a></p>
	<div id="divId" class="itm-show-hide-body">
		<p>ShowHide_Text</p>
	</div>

Documentation available at:
	http://www-03preprod.ibm.com/software/uk/itsolutions/_dev/code-base/
		projects/itmcommon.js/show-hide/
============================================================================= */

jQuery.fn.extend({itmCommonShowHide:function()
{jQuery("p.itm-show-hide-head>a").each(function(){var anchorPattern=new RegExp("#(.*)");var currentAnchorHref=jQuery(this).attr("href");var targetDivId=currentAnchorHref.substring(currentAnchorHref.search(anchorPattern)+1);var divIdPattern=new RegExp("(.*)\?(.*)"
+jQuery.fn.itmCommonShowHide.config.queryControlParam
+"="
+"([^&]*)("
+jQuery.fn.itmCommonShowHide.config.queryControlParamIdSeparator
+"?)"
+targetDivId
+"(["
+jQuery.fn.itmCommonShowHide.config.queryControlParamIdSeparator
+"&]?)"
+"(.*)");if(!divIdPattern.test(window.location.href))
{jQuery(this).attr("title",jQuery.fn.itmCommonShowHide.config.titleShow);if(jQuery.fn.itmCommonShowHide.config.useTriggers)
{if(jQuery.fn.itmCommonShowHide.config.triggersPos=="before")
jQuery(this).prepend("<span class=\"itm-show-hide"
+"-trigger\">"
+jQuery.fn.itmCommonShowHide.config.triggersShow
+"</span> ");else if(jQuery.fn.itmCommonShowHide.config.triggersPos=="after")
jQuery(this).after(" <span class=\"itm-show-hide-trigger"
+" ibm-item-note\">"
+jQuery.fn.itmCommonShowHide.config.triggersShow
+"</span>");}}
else
{jQuery(this).attr("title",jQuery.fn.itmCommonShowHide.config.titleHide);if(jQuery.fn.itmCommonShowHide.config.useTriggers)
{if(jQuery.fn.itmCommonShowHide.config.triggersPos=="before")
jQuery(this).prepend("<span class=\"itm-show-hide"
+"-trigger\">"
+jQuery.fn.itmCommonShowHide.config.triggersHide
+"</span> ");else if(jQuery.fn.itmCommonShowHide.config.triggersPos=="after")
jQuery(this).after(" <span class=\"itm-show-hide-trigger"
+" ibm-item-note\">"
+jQuery.fn.itmCommonShowHide.config.triggersHide
+"</span>");}}});if(jQuery.fn.itmCommonShowHide.config.triggersMonospace)
jQuery("p.itm-show-hide-head>a>span.itm-show-hide-trigger").each(function()
{jQuery(this).css("font-family","monospace");jQuery(this).css("font-size","small");});jQuery("p.itm-show-hide-head a").each(function()
{if(jQuery.fn.itmCommonShowHide.config.useTriggers&&jQuery.fn.itmCommonShowHide.config.triggersPos=="before")
jQuery(this).addClass("ibm-feature-link");jQuery(this).bind("click",{anchorObj:this},function(e)
{e.preventDefault();jQuery().itmCommonShowHideToggle(e.data.anchorObj)})});jQuery("div.itm-show-hide-body").each(function()
{var divIdPattern=new RegExp("(.*)\?(.*)"
+jQuery.fn.itmCommonShowHide.config.queryControlParam
+"="
+"([^&]*)("
+jQuery.fn.itmCommonShowHide.config.queryControlParamIdSeparator
+"?)"
+jQuery(this).attr("id")
+"(["
+jQuery.fn.itmCommonShowHide.config.queryControlParamIdSeparator
+"&]?)"
+"(.*)");if(!divIdPattern.test(window.location.href))
if(jQuery.fn.itmCommonShowHide.config.animateOnLoad)
jQuery(this).slideUp();else
jQuery(this).toggle();});var focusAnchorPattern=new RegExp("#(.*)");var currentLocation=window.location.href;var focusDivId=currentLocation.substring(currentLocation.search(focusAnchorPattern)+1);jQuery("div#"+focusDivId).focus();},itmCommonShowHideToggle:function(el)
{var targetDivId=el.href;targetDivId=targetDivId.substring(targetDivId.indexOf("#")+1);if(targetDivId)
{if(jQuery("div#"+targetDivId).css("display")=="none")
{jQuery("div#"+targetDivId).slideDown();jQuery(el).attr("title",jQuery.fn.itmCommonShowHide.config.titleHide);if(jQuery.fn.itmCommonShowHide.config.useTriggers)
jQuery(el).parents("p.itm-show-hide-head").find("span.itm-show-hide-trigger").text(jQuery.fn.itmCommonShowHide.config.triggersHide);}
else
{jQuery("div#"+targetDivId).slideUp();jQuery(el).attr("title",jQuery.fn.itmCommonShowHide.config.titleShow);if(jQuery.fn.itmCommonShowHide.config.useTriggers)
jQuery(el).parents("p.itm-show-hide-head").find("span.itm-show-hide-trigger").text(jQuery.fn.itmCommonShowHide.config.triggersShow);}}}});jQuery.fn.itmCommonShowHide.config={animateOnLoad:true,useTriggers:true,triggersPos:"before",triggersShow:"[+]",triggersHide:"[-]",triggersMonospace:true,queryControlParam:"showsections",queryControlParamIdSeparator:":",titleShow:"Expand section",titleHide:"Hide section"}
jQuery(function(){jQuery().itmCommonShowHide();});