/* ------------------

Selaphe - a library of handy jquery/javascript functions

AUTHOR

Mark J. Nenadov (2011)
* Essex, Ontario
* Email: <marknenadov@gmail.com> 

LICENSING

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version

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, see <http://www.gnu.org/licenses/>. 

------------------ */

/* Is this tag pertaining to tables? */

function sIsTableElement(obj)
{
     if (obj.is('table') || obj.is('tr') || obj.is('td') || obj.is('th')) {
          return true;
     }
     return false;
}

/* Does the objects parent match this? */

function sDaddyIs(obj, tag_type)
{
     return obj.parent().is(tag_type)
}

/* add a class to an objects parent */

function sGiveDaddyClass(obj, class_name)
{
     obj.parent().addClass(class_name)
}

/* Does the objects parent's parent match this? */

function sGrandaddyIs(obj, tag_type)
{
     return obj.parent().parent().is(tag_type)
}

/* add a class to a parents parent */

function sGiveGrandaddyClass(obj, class_name)
{
     obj.parent().parent().addClass(class_name)
}

/* sSetBackgroundColor(obj, color)- set the background color of an object */

function sSetBackgroundColor(obj, color)
{
	obj.css({'background-color': color})
}

/* sSetSectionToggleHandlers(listOfTitles) -- sets section toggle click handlers
 
 Basically, you use this as follows:
 
	1. build your html. Give whatever element you want to be the section's hide/show
	   activator an id of titlegoeshere_details_hide and a title of titlegoeshere. Give 
	   whatever element you want to be the content that will be hidden or shown a class 
	   of titlegoeshere_details_hidel.

	   	ie:

		<a href='#'  id='introduction_details_toggle' title='introduction'>Introducing Our Product</a>
		<div class='introduction_details_hide'> Blah Blah Blah ... </div>

		<a href='#'  id='explanation_details_toggle' title='explanation'>Explaining Our Product</a>
		<div class='explanation_details_hide'> Blah Blah Blah ... </div>

		<a href='#'  id='conclusion_details_toggle' title='conclusion'>Concluding Thoughts</a>
		<div class='conclusion_details_hide'> Blah Blah Blah ... </div>



 	2. build an array of string titles and pass it to this function (in your jQuery .ready() function)

		ie: 
		
		var sections = Array("introduction", "explanation", "conclusion");
		sSetSectionToggleHandlers(sections);

	-  
 
 
 */

function sSetSectionToggleHandlers(listOfTitles)
{
	for (i=0; i<listOfTitles.length; i++) {
		$("." + listOfTitles[i] + "_details_hide").hide();
		$("#" + listOfTitles[i] + "_details_toggle").click(function(){
      			$("." + this.title + "_details_hide").toggle();
		});
	}
}	

/* Simple ok/cancel confirm dialog */

function sConfirm(label) 
{
     var agree = confirm(label);
     
     if (agree) {
         return true;
     }
     return false;
}

