/* --- JavaScript --- */
/* ---- main.js ----- */
 
/* ============== */
/* === EVENTS === */
/* ============== */

/* === addEvent/removeEvent written by Dean Edwards (2005) with input from Tino Zijdel, Matthias Miller, Diego Perini: http://dean.edwards.name/weblog/2005/10/add-event/ === */
function addEvent( element, type, handler ) {
	if ( !element ) element = window;	// fix: sometimes element does not seem to exist, even though one is passed
	if ( element.addEventListener ) {
		element.addEventListener( type, handler, false );
	} else {
		// assign each event handler a unique ID
		if ( !handler.$$guid ) handler.$$guid = addEvent.guid++;
		// create a hash table of event types for the element
		if ( !element.events ) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[ type ];
		if ( !handlers ) {
			handlers = element.events[ type ] = {};
			// store the existing event handler (if there is one)
			if ( element[ "on" + type ] ) {
				handlers[ 0 ] = element[ "on" + type ];
			}
		}
		// store the event handler in the hash table
		handlers[ handler.$$guid ] = handler;
		// assign a global event handler to do all the work
		element[ "on" + type ] = handleEvent;
	}
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if ( element.removeEventListener ) {
		element.removeEventListener( type, handler, false );
	} else {
		// delete the event handler from the hash table
		if ( element.events && element.events[ type ] ) {
			delete element.events[ type ][ handler.$$guid ];
		}
	}
};

function handleEvent( event ) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent( (( this.ownerDocument || this.document || this ).parentWindow || window ).event );
	// get a reference to the hash table of event handlers
	var handlers = this.events[ event.type ];
	// execute each event handler
	for ( var i in handlers ) {
		this.$$handleEvent = handlers[ i ];
		if ( this.$$handleEvent( event ) === false ) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent( event ) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};
/* --- /addEvent/removeEvent --- */

function stopDefault( e ) {
	if ( e && e.preventDefault ) e.preventDefault();	// Prevent default browser action (W3C)
	else window.event.returnValue = false;					// IE version
	return false;
}

function normEvent( e ) {
	e = e || window.event;
	if ( !e.target ) e.target = e.srcElement;
	return e;
}

/* =============== */
/* === PRELOAD === */
/* =============== */

function preloadImage(src) {
	var img = new Image();
	img.src = src;
	return img.src;
}

/* =========== */
/* === BOM === */
/* =========== */

function queryString( q ) {
	var queryObj = {};
	var qString = window.location.search.substring( 1 );
	var qArray = qString.split( "&" );
	for ( var a = 0; a < qArray.length; a++ ) {
		var keyValue = qArray[ a ].split( "=" );
		queryObj[ keyValue[ 0 ] ] = keyValue[ 1 ] || "";	// fall back to empty string if no value is defined
	}
	if ( q && q.constructor == String ) return queryObj[ q ];
	else return queryObj;
}

/* =========== */
/* === DOM === */
/* =========== */

function domReady( f ) {
	if ( domReady.done ) return f();							// If DOM is already loaded, execute the function right away
	
	if ( domReady.timer ) {										// If wwe've already added a function
		domReady.ready.push( f );								// Add it to the list of functions to execute
	} else {
		addEvent( window, "load", isDOMReady );			// Attach an event for when the page finishes loading, just in case it finishes first.
		domReady.ready = [ f ];									// Initialize the array of functions to execute;
		domReady.timer = setInterval( isDOMReady, 13 );	// Check to see if the DOM is ready as quickly as possible
	}
}

function isDOMReady() {																										// Checks to see if the DOM is ready for navigation
	if ( domReady.done ) return false;																					// If we already figures out that the page is ready, ignore
	
	if ( document && document.getElementsByTagName && document.getElementById && document.body ) {	// Check to see if a number of functions and elements are able to be accessed
		clearInterval( domReady.timer );																					// If they're ready, we can stop checking
		domReady.timer = null;
		
		for ( var i = 0; i < domReady.ready.length; i++ ) domReady.ready[ i ]();							// Execute all functions that were waiting	
		domReady.ready = null;
		domReady.done = true;
	}
}

/* --- nodes --- */

function create( elem ) {
	return document.createElementNS ? document.createElementNS( 'http://www.w3.org/1999/xhtml', elem ) : document.createElement( elem );
}

function before( parent, before, elem ) {
	if ( elem == null ) {										// Check to see if no parent was provided
		elem = before;
		before = parent;
		parent = before.parentNode;
	}
	parent.insertBefore( checkElem( elem ), before );
}

function append( parent, elem ) {
	parent.appendChild( checkElem( elem ));
}

function checkElem( elem ) {
	return elem && elem.constructor == String ? document.createTextNode( elem ) : elem;	// if a string was provided, convert it into a text node
}

function remove( elem ) {
	if ( elem ) elem.parentNode.removeChild( elem );
}

function empty( elem ) {
	while ( elem.firstChild ) remove( elem.firstChild );
}

/* --- finding elements --- */
function id( name ) {
	return document.getElementById( name );	// -> HTML element
};

	/* === fix document.getElementById for IE - based on code by J. Max Wilson: http://www.sixteensmallstones.org/ie-javascript-bugs-overriding-internet-explorers-documentgetelementbyid-to-be-w3c-compliant-exposes-an-additional-bug-in-getattributes === */ 
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function( id ) {
	    if ( document.all ) {   // only override when document.all is supported (IE + Opera)
	
	        document.getElementById = function( id ) {
	            var elem = document.nativeGetElementById( id );
	            if ( !elem ) return null;
	            if ( elem.attributes['id'] && elem.attributes['id'].value == id ) return elem;							// make sure that it is a valid match on id
	
	            for ( var i = 1; i < document.all[ id ].length; i++ ) {															// otherwise find the correct element
	                if ( document.all[ id ][ i ].attributes[ 'id' ].value == id ) return document.all[ id ][ i ];
	            }
	        };
	    } else {    // otherwise change back to original
	        document.getElementById = document.nativeGetElementById;
	        document.nativeGetElementById = null;  																						// we don't need it anymore
	    }
	};
	document.getElementById();																													// run document.getElementById() once to let it rewrite itself
	/* --- /fix document.getElementById for IE --- */

function tag( name, elem ) {
	return ( elem || document ).getElementsByTagName( name );	// -> Array
};

function withClass( name, sel, sel2 ) {														// sel and sel2 are both optional and can be either an element or a tag (one of each)
	var haveClass = [];
	var regExp = new RegExp( "(^|\\s)" + name + "(\\s|$)" );								// allows for multiple class names
	var tagName = sel.constructor == String ? sel : sel2;
	var elem = sel.constructor == String ? sel2 : sel;
	var elements = ( elem || document).getElementsByTagName( tagName || "*" );		// use document if no element has been specified and get all elements if no tag name has been specified
	for ( var e = 0; e < elements.length; e++) {
		var element = elements[ e ];
		if ( hasClass( element, name )) haveClass[ haveClass.length ] = element;
	}
	return haveClass;																					// -> Array
};

function hasClass( elem, name ) {
	if ( !name && elem.className != "") return true;			// if no className has been specified any className will do | -> Boolean
	var regExp = new RegExp( "(^|\\s)" + name + "(\\s|$)" );	// allows for multiple class names
	if ( regExp.test( elem.className )) return true;			// -> Boolean
	return false;															// -> Boolean
};

function prev( elem ) {
	do {
		elem = elem.previousSibling;
	} while ( elem && elem.nodeType != 1 );
	return elem;
}

function next( elem ) {
	do {
		elem = elem.nextSibling;
	} while ( elem && elem.nodeType != 1 );
	return elem;
}

function first( elem ) {
	elem = elem.firstChild;
	return elem && elem.nodeType != 1 ? next( elem ) : elem;
}

function last( elem ) {
	elem = elem.lastChild;
	return elem && elem.nodeType != 1 ? next( elem ) : elem;
}


/* --- get/set attributes --- */
function attr( elem, attrib ) {															// attrib can be a String (get) or an Object (set)
	if ( attrib.constructor == String ) {
		name = validName( attrib );
		return elem[ name ] || elem.getAttribute( name ) || '';					// -> String (attribute value)
	}
	else if ( attrib.constructor == Object ) {
		for ( n in attrib ) {
			var value = attrib[ n ];
			name = validName( n );
			if ( name == "className" || name == "rel" || name == "rev" ) {
				addToAttr( elem, name, value );
			} else {
				elem[ name ] = value;														// do it quick if possible
				if ( elem.setAttribute ) 
				{	
					if (name == "type")
					{
						elem.type = value;
					}
					else
					{
						elem.setAttribute( name, value );		// XML fallback
					}
				}		// XML fallback
			}
		}
		return true;																			// -> Boolean (values are set)
	}
	function validName( name ) {
		return { 'for': 'htmlFor', 'class': 'className' }[ name ] || name;	// rename in case of 'for' or 'class' attribute
	};
	return '';																					// -> String (empty: attrib was neither a String or Object)
};

function addClass( elem, name ) {
	addToAttr( elem, "className", name );
}

function removeClass( elem, name ) {
	removeFromAttr( elem, "className", name );
}

function addToAttr( elem, attr, value ) {	// can be used for class, rel and rev attributes
	removeFromAttr( elem, attr, value );	// make sure there won't be any doubles
	elem[ attr ] += " " + value;
}

function removeFromAttr( elem, attr, value ) {									// can be used for class, rel and rev attributes
	var remain = [];
	var values = elem[ attr ].split(/\s+/);										// seperate class names (devided by one or more whitespaces)
	for ( var v = 0; v < values.length; v++ ) {
		if ( values[ v ] != value ) remain[ remain.length ] = values[ v ];
	}
	elem[ attr ] = remain.join( " " );
}

/* ============= */
/* === STYLE === */
/* ============= */

/* --- check for CSS support --- */
function cssSupport() {
	if ( !document.styleSheets ) return false;									// styleSheets object is not supported
	var css = document.styleSheets;
	for ( var s = 0; s < css.length; s++) {
		if ( s == 0 ) {
			if ( !( css[ 0 ].cssRules || css[ 0 ].rules )) return false;	// both methods (cssRules/rules) are not supported
		}
		if ( !css[ s ].disabled ) return true;										// at least one of the stylesheets is not disabled
	}
	return false;																			// stylesheets are all disabled or not supported at all
}


/* ================================== */
/* ============= CUSTOM ============= */
/* ================================== */

////////// INIT OVERLABEL //////////

/* --- overLabel --- place labels over corresponding form control --- */
/* --- based on http://www.alistapart.com/articles/makingcompactformsmoreaccessible/ ---*/
function initOverLabel() {
	var labels = withClass( "overLabel", "label" );
	if ( !labels ) return;
	
	for ( var l = 0; l < labels.length; l++ ) {
		var label = labels[ l ];
		if ( !label.htmlFor ) continue;
		
		var overControl = id( label.htmlFor );
		if ( !overControl ) continue;
		
		label.forControl = overControl;																												// make reference from label to corresponding control
		
		if ( overControl.value === "" ) addClass( overControl.parentNode, "inactive" );												// make sure label is only placed on top of control in case it has no value which is not always the case after a reload
		
		addEvent( overControl, "focus", function() { removeClass( this.parentNode, "inactive" )} );
		addEvent( overControl, "blur", function() { if ( this.value === "" ) addClass( this.parentNode, "inactive" )} );
		addEvent( label, "click", function() { this.forControl.focus()} );																// give focus to corresponding control (needed for Safari)
	}
	
	addClass( document.body, "jsLabelsOn" );	// add CSS hook																									// CSS hook to turn it on
}


////////// ADD JS BUTTONS //////////

function addJSbuttons() {
	if ( window.print ) addJSprint();
}

function addJSprint() {
	var printParent = id( "thisPage" );
	if ( !printParent || hasClass( printParent, "noPrint" ) ) return;
	
	var printLabel = languageObj.printPage || "Print";	// fall back to general "Print"
	
	var p = create( "p" );
	addClass( p, "printPage" );
	var printLink = create( "a" );
	attr( printLink, { "href": "#" } );
	append( printLink, printLabel );
	append( p, printLink );
	
	addEvent( printLink, "click", function( e ) {
		window.print();
		return stopDefault( e );
	});
	append( printParent, p );
	addClass( printParent, "jsPrint" );	// add CSS hook
}


///////////// INIT CLICKABLE ITEMS /////////////

/* --- clickableItems --- make entire itemes clickable --- */
function initClickableItems() {
	var items;
	
	// content section -|- add section for every clickable item type
	var content = id( "siteContent" );
	if ( content ) {
		items = withClass( "clickableItem", "li", content );
		if ( items && items.length > 0 ) clickAllOver( items );
	}
	// end content section
	
	// attentionBar section -|- add section for every clickable item type
	var content = id( "attentionBar" );
	if ( content ) {
		items = withClass( "clickableItem", "li", content );
		if ( items && items.length > 0 ) clickAllOver( items );
	}
	// end attentionBar section
	
	// passTypes section -|- add section for every clickable item type
	var content = id( "passTypes" );
	if ( content ) {
		items = withClass( "clickablePass", "td", content );
		if ( items && items.length > 0 ) clickAllOverPass( items );
	}
	// end passTypes section
}

/* --- clickAllOver --- */
function clickAllOver( elems ) {													// elem can be a single element or an array of elements
	var items = ( elems.constructor == Array ) ? elems : [ elems ];	// if elem is a single element, put it in an array

	for ( var i = 0; i < items.length; i++ ) {
		var item = items[ i ];
		
		item.getUrl = function() {
			var url = tag( "a", this )[0];
			return ( url ) ? url.href : false; 
		}
		
		item.url = item.getUrl();
		if ( !item.url ) return;
		
		addEvent( item, "click", function() { window.location.href = this.url } );
		addEvent( item, "mouseover", function() { addClass( this, "jsHoverItem" )} );
		addEvent( item, "mouseout", function() { removeClass( this, "jsHoverItem" )} );
		
		addClass( item, "jsClickable" );
	}
}

/* --- clickAllOverPass --- */
function clickAllOverPass( items ) {											// Array
	for ( var i = 0; i < items.length; i++ ) {
		var item = items[ i ];
		
		var range = [ item ];
		var nextCell = item;
		do {
			nextCell = next( nextCell );
			if ( nextCell ) range.push( nextCell );
		} while ( !hasClass( nextCell, "buyPass" ) );
		
		nextCell.getUrl = function() {
			var url = tag( "a", this )[0];
			return ( url ) ? url.href : false; 
		}
		
		item.url = nextCell.getUrl();
		if ( !item.url ) return;
		
		for ( var r = 0; r < range.length; r++ ) {
			var cell = range[ r ];
			
			cell.url = item.url;
			addClass( cell, "jsClickableCell" + r );
			
			addEvent( cell, "click", function() { window.location.href = this.url } );
			addEvent( cell, "mouseover", function() { hoverPass( this, true ) } );
			addEvent( cell, "mouseout", function() { hoverPass( this, false ) } );
		}
	}
}

function hoverPass( item, hovers ) {
	if ( hasClass( item, "jsClickableCell0" ) ) {
		var sibling1 = next( item );
		if ( sibling1 ) var sibling2 = next( sibling1 );
	} else if ( hasClass( item, "jsClickableCell1" ) ) {
		var sibling1 = prev( item );
		var sibling2 = next( item );
	} else {
		var sibling1 = prev( item );
		if ( sibling1 ) var sibling2 = prev( sibling1 );
	}
	if ( hovers ) {
		addClass( item, "jsHoverItem" );
		if ( sibling1 ) addClass( sibling1, "jsHoverItem" );
		if ( sibling2 ) addClass( sibling2, "jsHoverItem" );
	} else {
		removeClass( item, "jsHoverItem" );
		if ( sibling1 ) removeClass( sibling1, "jsHoverItem" );
		if ( sibling2 ) removeClass( sibling2, "jsHoverItem" );
	}
}


///////////// INIT SELECT NAVIGATION /////////////

/* --- initSelectNav --- initializes autosubmit on <input type="radio">s and <select>s, works with keyboard too (in IE, FX and Op) --- */
function initSelectNav() {
	var content = id( "siteContent" );
	if ( !content ) return;
	
	var selectNavOn = false;
	
	var navForms = withClass( "selectNav", "form", content );
	for ( var f = 0; f < navForms.length; f++ ) {
		var navForm = navForms[ f ];
		
		var inputs = tag( "input", navForm );
		for ( var i = 0; i < inputs.length; i++ ) {
			var radioButton = inputs[ i ];
			if ( radioButton.type != "radio" ) continue;
			
			if ( radioButton.checked ) navForm.origChecked = radioButton;
			addEvent( radioButton, "click", function() { if ( this != this.form.origSelected ) this.form.submit(); } );
			
			selectNavOn = true;
		}
	}
	
	if ( selectNavOn ) addClass( document.body, "jsSelectNavOn" );
}


///////////// PASS TABS /////////////

function initPassTabs() {
	var passTypes = id( "passTypes" );
	if ( !passTypes ) return;
	
	var passTabs = create( "ul" );
	addClass( passTabs, "tabs" );
	addClass( passTabs, "nav" );
		
	var li = create( "li" );
	var a = create( "a" );
	attr( a, { "href": "#" } );
	
	var passTypeContainers = withClass( "passType", "div", passTypes );
	if (passTypeContainers.length >1) {
		var qTab = queryString( "tab" );
		var bookmark = ( qTab > 0 && qTab <= passTypeContainers.length ) ? qTab - 1 : 0;
		for ( var p = 0; p < passTypeContainers.length; p++ ) {
			var passType = passTypeContainers[ p ];
		
			var header = tag( "h3", passType )[0];
			if ( !header ) continue;
			
			var tab = cloneTabElem( li, { "id": "tab" + p } );
			var tabLink = cloneTabElem( a );
			tabLink.innerHTML = header.innerHTML;
			addEvent( tabLink, "click", function( e ) {
				tabPass( this.parentNode );
				return stopDefault( e );
			} );
		
			addClass( passType, "type" + p );
			if ( p == bookmark ) {
				addClass( passTabs, "tab" + p );
				removeClass( passTypes, "tab0" );
				addClass( passTypes, "tab" + p );
				passTypes.currentTab = "tab" + p;	// reference
			}
		
			append( tab, tabLink );
			append( passTabs, tab );
			remove( header );
		}
		before( passTypes, passTypeContainers[ 0 ], passTabs );
		addClass( passTypes, "jsTabsOn" );
	}
}

function cloneTabElem( elem, attrib ) {
	var clone = elem.cloneNode( true );
	if ( attrib ) attr( clone, attrib );
	return clone;
}

function tabPass( tab ) {
	var passTypes = id( "passTypes" );
	
	if ( passTypes.currentTab ) removeClass( passTypes, passTypes.currentTab );
	addClass( passTypes, tab.id );
	passTypes.currentTab = tab.id;
}


///////////// FILTER PASSES /////////////

function initFilterPasses() {
	var listDivisions = 5;	// number of lists

	var passMatrix = id( "passMatrix" );
	if ( !passMatrix ) return;
	
	var matrix = tag( "table", passMatrix )[ 0 ];
	var matrixBody = tag( "tbody", matrix )[ 0 ];
	if ( !matrix || !matrixBody ) return;
	
	var filterPasses = setupFilter();
	
	var countries = tag( "tr", matrixBody );
	var perList = Math.ceil( countries.length / listDivisions );
	for ( var c = 0; c < countries.length; c++ ) {
		var country = countries[ c ];
		
		if ( c % perList == 0 ) {
			if ( countryList ) append( filterPasses, countryList );
			var countryList = create( "ul" );
		}
		var option = selectItem( country );
		if ( option ) append( countryList, option );
	}
	if ( countryList ) append( filterPasses, countryList );
	
	var selectAll = create( "div" );
	addClass( selectAll, "selectAll" );
	
	option = selectItem( "All" );
	if ( option ) append( selectAll, option );
	
	append( filterPasses, selectAll );
	before( passMatrix, matrix, filterPasses );
	
	var check_All = id( "check_All" );
	if ( check_All ) attr( check_All, { "checked": "checked" } );	// won't work in IE6 if declared much earlier
}

function selectItem( country ) {
	if ( country.constructor == String ) {
		var labelText = languageObj.selectAll || "Seleccionar todo"; // fall back
		var item = createOption( "check_" + country, labelText, true );
	} else {
		var countryID = attr( country, "id" );
		var countryHeader = tag( "th", country )[ 0 ];
		var countryName = tag( "span", countryHeader )[ 0 ];
		var labelText = countryName.firstChild.nodeValue;
		if ( !countryID || !labelText ) return;
		
		var label = createOption( "check_" + countryID, labelText, false );
	
		// list item
		var item = create( "li" );
		append( item, label );
	}
	
	return item;
}

function checkCountry() {
	var countryRow = id( this.id.substring( 6 ) );
	countryRow.style.display = this.checked ? "" : "none";
	
	var selectAll = id( "check_All" );
	if ( selectAll.checked ) {
		selectAll.checked = "";
		checkAll( false );
	}
}

function checkAll( check ) {
	var matrix = id( "passMatrix" );
	if ( !matrix ) return;
	
	var matrixBody = tag( "tbody", matrix )[ 0 ];
	if ( !matrixBody ) return;
	
	var countries = tag( "tr", matrixBody );
	for ( var c = 0; c < countries.length; c++ ) {
		var country = countries[ c ];
		
		var checkBox = id( "check_" + country.id );
		if ( checkBox ) {
			if ( check ) checkBox.checked = "";
			country.style.display = ( check || checkBox.checked ) ? "" : "none";
		}
	}
}

function createOption( itemID, labelText, all ) {
	// checkbox
	var checkBox = create( "input" );
	attr( checkBox, { "type": "checkbox", "id": itemID, "name": itemID, "value": itemID } );
	
	if ( all ) {
		//attr( checkBox, { "checked": "checked" } );
		//checkBox.checked = true;
		addEvent( checkBox, "click", function() {
			checkAll( this.checked ? true : false );
		} );
	} else {
		addEvent( checkBox, "click", checkCountry );
	}
	
	// label
	var label = create( "label" );
	attr( label, { "for": itemID } );
	append( label, checkBox );
	append( label, labelText );
	
	return label;
}

function setupFilter() {
	var filterPasses = create( "div" );
	attr( filterPasses, { "id": "filterPasses", "class": "show" } );
	
	// header
	var header = create( "h2" );
	var openLink = create( "a" );
	attr( openLink, { "href": "#" } );
	var headerText = languageObj.selectCountriesHeader || "Seleccione los pa\355ses que desea visitar y le mostraremos las opciones disponibles";	// fall back
	append( openLink, headerText );
	addEvent( openLink, "click", function( e ) {
		var filterPasses = id( "filterPasses");
		if ( filterPasses ) addClass( filterPasses, "show" );
		stopDefault( e );
	} );
	append( header, openLink );
	append( filterPasses, header );
	
	// close link
	var close = create( "p" );
	addClass( close, "close" );
	var closeLink = create( "a" );
	attr( closeLink, { "href": "#" } );
	var closeText = languageObj.closeFilter || "Cerrar"; // fall back to general "Close"
	append( closeLink, closeText );
	addEvent( closeLink, "click", function( e ) {
		var filterPasses = id( "filterPasses");
		if ( filterPasses ) removeClass( filterPasses, "show" );
		stopDefault( e );
	} );
	append( close, closeLink );
	
	var div = create( "div" );	// adding div = fix for IE6
	append( div, close );
	append( filterPasses, div );
	//append( filterPasses, close );
	
	return filterPasses;
}


///////////// FAQS /////////////

function initFAQs() {
	var faqs = id( "faqs" );
	if ( !faqs ) return;
	
	var questions = tag( "dt", faqs );
	for ( var q = 0; q < questions.length; q++ ) {
		var question = questions[ q ];
		var answer = next( question );
		if ( !answer ) continue;
		
		question.innerHTML = '<a href="#">' + question.innerHTML + '</a>';
		var qLink = tag( "a", question )[ 0 ];
		
		addClass( question, "closed" );
		addClass( answer, "closed" );
		
		addEvent( qLink, "click", function( e ) {
			var question = this.parentNode;
			var answer = next( question );
			if ( !question || !answer ) return;
			
			if ( hasClass( question, "closed" ) ) {
				removeClass( answer, "closed" );
				removeClass( question, "closed" );
			} else {
				addClass( answer, "closed" );
				addClass( question, "closed" );
			}
			
			return stopDefault( e );
		} );
	}
	
	if ( q > 0 ) addClass( faqs, "jsExpandable" );
}


/* --- call functions only if the used methods are supported --- */
domReady( function() {

	if ( !languageObj ) languageObj = {};
	
	if ( cssSupport() ) {
		addJSbuttons();
		initOverLabel();
		initSelectNav();
		if ( !document.all || window.opera ) initPassTabs();
		initFilterPasses();
		initFAQs();
		initClickableItems();
	}
} );

if ( document.all && !window.opera ) addEvent( window, "load", initPassTabs );
