
// ======================================================================
// Name:    	  Raskin's DOM Helper namespace
// Version:		  0.9.5 w/ JSON Serializer (requires rAjax.js or json.js)
// Created: 	  28/12/2006
// Last Modified: 02/07/2007
// Author: 		  Max Raskin ( ghunter@netvision.net.il )
// ======================================================================
//
// NOTES: Moved $ to rDom.$ so it won't conflict with prototype (when using LightBox, Cropper etc..)
//
var rDom = {

	
	/**
	 * Returns an element by id/class/name and automatically extends it with
	 * 
	 *
	 * [!] by class prefix with a period     - '.'
	 * [!] by name  prefix with an exc. mark - '!' 
	 * 				(use '!!' in order to escape to document.getElementById)
	 */
	$ : function(s,srcEl)
	{
		var els = [];
		
		if (typeof srcEl == 'undefined') {
			srcEl = document;
		}
		
		if (typeof s == 'object') {
			els[0] = s;
		} else if (s.charAt(0) == '.') { // by class);
			s = s.substring(1,s.length);
			
			var els = rDom.getElementsByClassName(s, srcEl);
		} else if (s.charAt(0) == '!' && s.charAt(1) != '!') {
			s = s.substring(1,s.length);
			rDom.getElementsByName(srcEl,s,els);
		} else if(typeof s == 'string') { // by id
			els[0] = document.getElementById(s);
		}
		
		for (var i = 0; i < els.length; i++) {
			if (els[i] && !els[i].____extended) {
				var nodeName = els[i].nodeName.toLowerCase();
				var type	 = els[i].type;
				// Extend with global functions
				rExt(els[i],rExtendableElements['global']);
				// Extend by node name
				if (typeof rExtendableElements[nodeName] !='undefined') {
					rExt(els[i],rExtendableElements[nodeName]);
				}
				// Extend by type
				if (typeof rExtendableElements[type] != 'undefined') {
					rExt(els[i],rExtendableElements[type]);
				}
			}
		}
		if (els.length == 1) {
			els = els[0];
		} else if (!els.length) {
			els = null;
		}
		
		return els;
	},
	
	/**
	 * Disables/enables all elements within a form
	 */
	disableForm : function(f, enable) {
		
		for (var i = 0, len = f.elements.length; i < len; ++i) {
			f.elements[i].disabled = !enable;
		}
	},
	
	/**
	 * @param mixed o - any object which isn't an array converted to an array
	 *
	 * @return Array
	 */
	toA : function(o) {
		
		if (o && (o.nodeName && o.nodeName.toLowerCase() == 'select') || (!this.isA(o) && !this.isCol(o))) {
			
			return [o];
		}
		
		return o;
	},
	
	/**
	 * Adds a css rule - creates a new stylesheet (*** only once - all rules are added to that stylesheet )
	 *
	 * @param string selector
	 * @param string properties
	 * @param object[optional] win - ref. to window object/iframe element
	 								 which contains the doc to add the css to (defaults to window)
	 */
	addCSSRule : function(selector, properties, win) {
		
		if (typeof win == 'undefined') {
			win = window;
			
		} else {
			// for iframes
			win =  (win.contentWindow) ? win.contentWindow : win;
		}
		
		var doc = (win.documentElement) ? win.documentElement : win.document;
		
		var isIE = (navigator.userAgent.toLowerCase().indexOf('msie') > -1 
					&& !window.opera
					&& doc.styleSheets);
		
		if (!win.styleEl) {
			win.styleEl = doc.createElement('style');
			win.styleEl.setAttribute('type', 'text/css');
			doc.getElementsByTagName('head')[0].appendChild(win.styleEl);
		}
		
		
		if (isIE) {
			if (!win.styleIE) {
				win.styleIE = doc.styleSheets[doc.styleSheets.length - 1];
				
				
			}
			var selectors = selector.split (',');
			for (var i = 0; i < selectors.length; i++) {
				win.styleIE.addRule(selectors[i], properties);
			}
			
		} else {
			win.styleEl.appendChild(doc.createTextNode(selector + '{' + properties + '}'));
			win.styleEl.appendChild(doc.createTextNode(selector + '{' + properties + '}'));
			
		}
		
	},
	
	/**
	 * Add multiple css rules to document
	 *
	 * @param string selector
	 * @param string properties
	 */
	addCSSRules : function(rules, win) {
		for (selector in rules) {
			if (rules.hasOwnProperty(selector)) {
				this.addCSSRule(selector, rules[selector], win);
			}
		}
	},
	
	/**
	 * Queries the user's browser for visited sites :-)
	 * @param string|Array urls - url or an array of urls to check
	 *
	 * @return array - an array of boolean values
	 *
	 */
	sniffVisitedSites : function (urls) {
		if (!this._visitedSitesRule) {
			this.addCSSRule('a.rDOMsniffURLClass:visited', 'color:#ccc !important;');
			this._visitedSitesRule = true;
		}
		
		if (typeof urls.push == 'undefined') {
			urls = [urls];
		}
		
		var div = rDom.createEl('div');
		for (var i = 0; i < urls.length; i++) {
			var a = rDom.createLink('link', urls[i]);
			a.className = 'rDOMsniffURLClass';
			div.appendChild(a);
		}
		document.body.appendChild(div);
		
		var visited = [];
		for (var i = 0; i < div.childNodes.length; i++) {
			var clr = rDom.getCurrentStyle(div.childNodes[i],'color');
			
			if (clr == 'rgb(204, 204, 204)' || clr == '#ccc' || clr == '#cccccc') {
				visited[i] = true;
			} else {
				visited[i] = false;
			}
			
			
		}
		
		document.body.removeChild(div);
		
		return visited;
	},

	/**
	 * Gets computed style of an element
	 *
	 * @param Object el - DOM element
	 * @param String prop - style property to get
	 *
	 * @return String
	 * from http://www.codehouse.com
	 */
	getCurrentStyle : function (el, prop)
	{
	   if(el&& el.currentStyle )
	   {   
	      var ar = prop.match(/\w[^-]*/g);
	      var s = ar[0];
	      
	      for(var i = 1; i < ar.length; ++i)		   
	      {
	         s += ar[i].replace(/\w/, ar[i].charAt(0).toUpperCase());
	      }
	           
	      return el.currentStyle[s]
	   }
	   else if( document.defaultView && document.defaultView.getComputedStyle )
	   {
	      return document.defaultView.getComputedStyle(el, null).getPropertyValue(prop);
	   }
	},
	
	/**
	 * Sets a handler for the onload event of window
	 * 
	 * @param Object obj - manager object **MUST** implement the init(ev) function
	 * @return bool
	 */
	setInitHandler : function(obj) {
		return this.addEvent(window, 'load', obj.init, obj);
	},

	/*
		Prevents default internal method of an event
		
		Params:
			object e - event
	*/
	preventDefault : function(e)
	{
		(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	},
	
	/*
		Stops event bubbling
		
		Params:
			object e - event
	*/
	stopPropagation : function(e)
	{
		(e.stopPropagation) ? e.stopPropagation() : (e.stopBubble = true);
	},
	
	/*
		Gets an event's targetted element
		
		Params:
			object - event
		
		Returns:
			object on success, false on failure.
	*/
	getTarget : function(e)
	{
		var target = window.event ? window.event.srcElement : e ? e.target : false;
		return this.$(target);
	},
	
	/**
	* Gets document's size
	*
	* @return object hash(width;height}
	*/
	getDocSize : function() {
		if (document.documentElement && document.documentElement.clientHeight)
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else if (document.body)
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}

		return {width:w, height:h}
	},
	/*
		Gets closest sibling to specified element
		
		Params:
			object  el  - element which sibling's to get
			integer dir - direction from which to get sibling (-1 - backward, 1 - forward)
		Returns:
			object if found sibling
			false if not.
	*/
	closestSibling : function (el,dir)
	{
		if (dir > 0)
		{
			var cEl = el.nextSibling;
			while (cEl.nodeType != 1 && cEl != null)
				cEl = cEl.nextSibling;
		}
		else if (dir < 0)
		{
			var cEl = el.previousSibling;
			while (cEl.nodeType != 1 && cEl != null)
				cEl = cEl.previousSibling;
		}
		return (cEl != null) ? cEl : false;
	},
	
	/*
		Gets last sibling (according to document hierarchy) of a specified element
		
		Params:
			object el - the element of which sibling to get
		
		Return:
			object is there is a last sibling, false if not.
	*/
	lastSibling : function (el)
	{
		if (el.nextSibling == null)
			return false;
		
		var tmp = null;
		while(el != null)
		{
			if (el.nodeType == 1)
				tmp = el;
			el = el.nextSibling;
		}
		return (tmp != null) ? tmp : false;
	},
	
	/*
		Gets first sibling (according to document hierarchy) of a specified element
		
		Params:
			object el - the element of which sibling to get
		
		Return:
			object is there is a first sibling, false if not.
	*/
	firstSibling : function (el)
	{
		if (el.previousSibling == null)
			return false;
		
		var tmp = null;
		while(el != null)
		{
			if (el.nodeType == 1)
				tmp = el;
			el = el.previousSibling;
		}
		return (tmp != null) ? tmp : false;
	},
	
	/*
		Gets the first child text node value of an element.
		
		Params:
			object el - element of which text to get
		
		Returns:
			text on success, false on failure.
	*/
	getText : function (el)
	{
		if (!el.hasChildNodes())
			return false;
		var tmp = null;
		el = el.firstChild;
		var reg = /^\s+$/;
		while (el != null && !reg.test(el.nodeValue))
		{
			if (el.nodeType == 3)
				tmp = el;
			el = el.nextSibling;
		}
		return (tmp != null) ? tmp.nodeValue : false;
	},

	/*
		Sets the value of first child text node of an element if exists,
		if not appends a new child text node element.
		
		Params:
			object el  - the element of which text to set
			string txt - text to set
	
	*/
	setText : function (el,txt)
	{

		var tn = document.createTextNode(txt);
		if (!el.hasChildNodes())
		{
			el.appendChild(tn);
		}
		else
		{
			var tmp = el.firstChild;
			while (tmp != null && tmp.nodeType != 3)
			{
				tmp = tmp.nextChild;
			}
			if (tmp == null)
				el.appendChild(tn);
			else
				tmp.nodeValue = txt;
		}
		return true;
	},
	
	/*
		Creates an element
		
		Params:
			string el  - element's name
			string txt - element's inner text (optional)
		
		Returns:
			object el on success, null on failure.
	*/
	createEl : function (el,txt)
	{
		var tmpEl = document.createElement(el);
		if (txt != null) tmpEl.appendChild(document.createTextNode(txt));
		return tmpEl;
	},
	
	/*
		Create anchor element
		
		Params:
			string txt  - url link
			string href - link url
	
	*/
	createLink : function (txt, href)
	{
		var aEl = document.createElement('a');
		aEl.appendChild(document.createTextNode(txt));
		aEl.setAttribute('href', href);
		return aEl;
	},
	
	/*
		Check whether a class set in a specified element class list
		
		Params:
			object el - element to check
			string c  - class name to look for
	*/
	cssClassCheck : function (el,c)
	{
		if (!el || !el.className) return;
		var regex = new RegExp("\\b" + c +"\\b");
		return regex.test(el.className);
	},
	
	/*
		Removes a class from an element's class list
		
		Params:
			object el - element to remove class from
			string c  - class name to remove
	*/
	cssClassRemove : function (el, c)
	{
		var regex = new RegExp("\\s*\\b" + c +"\\b\\s*");
		el.className = el.className.replace(c, ' ');
		//alert(el.className);
	},
	
	trim : function (s)
	{
		while (s.substring(0,1) == ' ')
			s = s.substring(1, s.length - 1);
		while (s.substring(s.length - 1, 1) == ' ')
			s = s.substring(0, s.length - 1);
			
		return s;
	},
	
	/*
		Swaps a class within an element's classes list
		
		Params:
			object el - element to swap classes
			string c1 - first class name
			string c2 - second class name
	*/
	cssClassSwap : function (el,c1,c2)
	{
		
		if (this.cssClassCheck(el,c1))
			el.className = el.className.replace(c1,c2);
		else
			el.className = el.className.replace(c2,c1);
	},
	
	
	/*
		Adds a class to an element
		
		
		@param	object el - element to add a class to
		@param	string c  - name of class to add
		@return bool
	*/
	cssClassAdd : function (el,c)
	{
		if (!el) return false;
		if (!this.cssClassCheck(el,c))
		{
			if (el.className.length) 
				el.className += (' ' + c);
			else
				el.className = c;
		}
		return true;
	},
	
	/*
		Recursively gets elements by class name (recursive method)
		
		Params:
		string	c		 - class name to match
		Object|string el[optional] 		 - root element to start search in
		@return Array
	*/
	getElementsByClassName : function (c, el) {
		el = rDom.$(el) || document;
		
		var descendants = el.getElementsByTagName('*');
		var results = [];
		var regex = new RegExp("\\b" + c +"\\b");
		for (var i = 0, len = descendants.length; i < len; ++i) {
			
			if (regex.test(descendants[i].className) ) {
				results.push(descendants[i]);
				
			}
		}
		
	    return results;
	},
	
	/*
		Recursively gets elements by name (recursive method)
		
		Params:
			el 		 - root element to start search in
			s		 - name to match
			arr		 - output array to contain matching elements
	*/
	getElementsByName : function (el,s,arr)
	{
	
		if (el) 
		{
			for (var i = 0; i < el.childNodes.length; i++)
			{
				if (el.childNodes[i].nodeType == 1)
				{
								
					if (el.childNodes[i].getAttribute('name') == s) arr.push(el.childNodes[i]);
					this.getElementsByName(el.childNodes[i],s,arr);					
				}

			}
			
		}
		else
			return;
	},
	
	/*
		Recursively gets elements by type (recursive method)
		
		Params:
			el 		 - root element to start search in
			t		 - type to match
			arr		 - output array to contain matching elements
	*/
	getElementsByType : function (el,t,arr)
	{
		
		if (el)
		{
			for (var i = 0; i < el.childNodes.length; i++)
			{
				
				if (el.childNodes[i].nodeType == 1)
				{
					if (el.childNodes[i].type == t) arr.push(el.childNodes[i]);
					rDom.getElementsByType(el.childNodes[i],t,arr);					
				}
			}
			
		}
		else
			return;
	},
	
    /**
     * Hides/Unhides element(s) by a given class name
     * (extended by rDom.$ as element.showChildrenByClass and element.hideChildrenByClass)
     *
     * @param Object rootEl - root parent element                      
     * @param String c - class name
     * @param bool[optional] hide - deafaults to false (shows elements)
     *
     * @return int - number of elements modified
     */
    toggleChildrenByClass : function(rootEl, c, hide) {
        if (typeof hide == 'undefined') hide = false;

        var els = rDom.$(rootEl).$('.' + c);
        for (var i = 0, len = els.length; i < len; ++i) {
            if (hide)
                rDom.$(els[i]).hide();
            else
                rDom.$(els[i]).show();
        }
        
        return len;
    },
    
	/**
	 * Binds a function to an object - thusly, makes the function
	 * inherit all the object's properties via its 'this' object.
	 *
	 * (taken from prototype)
	 *
	 * @param Function f
	 * @param Object   obj
	 * @param Array[optional] extraArgs - append extra arguments
	 */
	bindToObj : function (f, obj, extraArgs) {
		
		argsList = [1,2];
		
		
		return function() {
			var args = [];
			// convert to array
			for (var i = 0, len = arguments.length; i < len; ++i) {
				args.push(arguments[i]);
			}
			if (extraArgs) {
				for( var i = 0, len = extraArgs.length; i < len; ++i ) {
					args.push(extraArgs[i]); //extra args
				}
			}
			f.apply(obj, args);
		};
	},
	
	// is array
	isA : function(o) {
		return (o && typeof o.push != 'undefined');
	},
	
	// is collection
	isCol : function(o) {
		if (!o) return false;
		return (typeof o.length != 'undefined' && typeof o != 'string');
	},
	
	/**
	*	Attaches an event handler to an element or multiple elements
	*
	*	@param object|array el	 - the element/elements of which events to capture
	*	@param string|array ev 	 - event/events (without the 'on' prefix)
	*	@param function f 	 - handler function
	*	@param object bindObj[optional] - an optional object to bind handler function to
	*	
	*	@return int - number of succesfull event handlers set
	*/
	addEvent : function (el,ev,f,bindObj)
	{
		
		// if an array of events is given
		if (typeof ev.push != 'undefined') {
				
			for (var i = 0; i < ev.length; i++) {
			
				this.addEvent(el, ev[i], f, bindObj);
				
			}
			return;
		}
		
		var els = rDom.toA(el);
	
		var numSuccess = 0;
		
		for (i = 0; i < els.length; i++) {
			
			if(els[i] === null || typeof els[i] == 'undefined') continue;
			var func = f;
			
			if (typeof bindObj != 'undefined' 
			    && typeof func.apply == 'function') {
					func = rDom.bindToObj(f, bindObj);
			    }
	
			if (els[i].attachEvent) {
				els[i].attachEvent('on' + ev, func);
			} else if (els[i].addEventListener) {
				els[i].addEventListener(ev, func, false);
			} else {
			
				els[i]['on' + ev] = func;
			}
			
			numSuccess++;
		}
				
		return numSuccess;
	},

	/*
		Detaches an event handler
		
		Params:
			@param object el	  - the element of which events to capture
			@param string ev 	  - event (without on prefix)
			@param function func - subclass function
			@param bool useCap   - use event capturing (MSIE ignores this param)
			
	*/
	removeEvent : function(el,ev,func,useCap)
	{
		if (el.detachEvent)
		{
			el.detachEvent('on' + ev, func);
		}
		else if (el.removeEventListener)
		{
			if (useCap === null) useCap = true;
			el.removeEventListener(ev, func, useCap);
		}
		else
			el['on' + ev] = null;
	},
	
	/*
		Stops both bubbling and prevents default method call of an event
		
		Params:
			object e - event
	*/		
	stopEvent : function (e)
	{
		if (!e && !window.event) return;
		if (!e) e = window.event;
		this.stopPropagation(e);
		this.preventDefault(e);
	},
	
	/*
		Gets key code from an event
		
		Params:
			object e - event
	*/
	getKeyCode : function(e)
	{
		return (e) ? e.keyCode : window.event.keyCode;
	},
	
	/*
		Gets mouse coordinates
		
		Params:
			object e - event
	*/
	getMouseCoords : function(e)
	{
		e = e || window.event;
		
		if (typeof e.pageX != 'undefined')
			return {x:e.pageX, y:e.pageY};
		else
			return {
				x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
				y:e.clientY + document.body.scrollTop  - document.body.clientTop
			};
	},
	/*
		Gets element position coordinates in pixels, relative to document
		
		Params:
			object el - element
	*/
	getElementPos : function(el)
	{
		var top = 0, left = 0;
		while (el.offsetParent)
		{
			left += el.offsetLeft;
			top  += el.offsetTop;
			el	  = el.offsetParent;
		}
		
		left += el.offsetLeft;
		top  += el.offsetTop;

		return {x:left,y:top};
	},
	
	/**
	* Toggle an element's visibility
	* NOTE: (style.display NOT style.visibility)
	* @param object el - reference to an elemnt
	*/
	
	toggleDisplay : function(el)
	{
		el.style.display = (el.style.display == 'none') ? 'block' : 'none';
	},
	
	/**
	* Swaps one node with another
	* @param object oldNode - node to swap
	* @param object newNode	- node to swap with
	*/
	swapNode : function(oldNode,newNode)
	{
		oldNode.parentNode.insertBefore(newNode, oldNode);
		oldNode.parentNode.removeChild(oldNode);
		if (typeof newNode.focus == 'function') newNode.focus();
	},
	
	/**
	* Adds events to every descended (excluding) of el
	* @param object el - parent to begin with
	* @param string event
	* @param function func
	*/
	addEventRecursive : function(el, event, func)
	{
		
		if (el.hasChildNodes())
		{
			for (var i = 0; i < el.childNodes.length; i++)
			{
				if (el.childNodes[i].nodeType == 1)
				{
					rDom.addEvent(el.childNodes[i], event, func);
					rDom.getElementsByType(el.childNodes[i],event,func);					
				}
			}
			
		}
		else
			return;
	},
	
	/*
	@todo: can be cool
	serializeFormToQueryString : function(form, namesArray) {
		
	},*/
	
	/** 
	 * DeSerializes object into a form by names - object has to to be in the following format:
	 * {'someElementName' : 'data'|1234|[1,2,3] ...}
	 * @param mixed form - id/class (prefixed with a '.')/object of the form element
	 * @param Array obj  - object to deserialize
	 *
	 */
	deserializeObjectToForm : function(form, obj) {
		var f = this.$(form);
		for (i in obj) {
			if (obj.hasOwnProperty(i)) {
				var el = f.elements[i];
				
				if (!el) {continue;}
				// turn a single element into array
				// that is because if we get an element which is a collection of
				// elements, like a group of radio boxes for instance, we'll have to
				// iterate through it separately otherwise
				if (typeof el.length == 'undefined') {
				
					el = [el];
				}
				
				// php based array counter
				var kk = 0;
				
				for (var j = 0; j < el.length; j++) {
							
					if (el[j].disabled || !el[j]) { // Don't deserialize disabled elements and undefined ones
						continue;
					}
					
					switch(el[j].nodeName.toLowerCase()) {
						
					// select option
						case 'option':
							var toSel = false;
							if (typeof obj[i] == 'object') {
								for (opt in obj[i]) {
									if (obj[i].hasOwnProperty(opt)) {
										if (obj[i][opt] && el[j].value == obj[i][opt]) {
											toSel = true;
										}
									}
								}
								
							} else {
								
								if (obj[i] && el[j].value == obj[i]) {
									toSel = true;
								}
							}
							el[j].selected = toSel;
							break;
						case 'input':
							switch (el[j].type.toLowerCase()) {
								case 'checkbox':
									// Check checkbox if true
									el[j].checked = (parseInt(obj[i]) > 0);
									break;
								case 'radio':
									// Check radio only if value matches
									if (el[j].value == obj[i] ) {
										el[j].checked = true;
									}
									break;
								default:
									// detect php array
									if (el[j].name.substring(el[j].name.length -2 ) == '[]') {
										el[j].value = obj[i][kk];
										kk++;
									} else {
										kk = 0
										el[j].value = obj[i];
									}
							}
							break;
						case 'textarea':
							el[j].value = obj[i];
							break;
					}
				}
			}
		}
		
		return true;
	},
	
	/** 
	 * Serializes form elements into an object
	 *
	 * @param mixed form - id/class (prefixed with a '.')/object of the form element
	 * @param Array namesArray - an array of strings with the elements u want to serialize
	 *
	 * @todo : allow namesArray to be * - all elements will be serialized
	 */
	serializeFormToObject : function(form, namesArray) {
		var f = this.$(form);
		var obj = {};
		for (var i = 0; i < namesArray.length; ++i) {
			
			var el = f.elements[namesArray[i]];
			
			if (!el) continue;
			
			// turn a single element into array
			// that is because if we get an element which is a collection of
			// elements, like a group of radio boxes for instance, we'll have to
			// iterate through it separately otherwise
			if (typeof el.length == 'undefined') {
				el = [el];
			}
			for (var j = 0; j < el.length; j++) {
						
				if (el[j].disabled || !el[j]) { // Don't serialize disabled elements and undefined ones
					continue;
				}
				
				switch(el[j].nodeName.toLowerCase()) {
					case 'option':
						
						if (el[j].selected) {
							if (!obj[namesArray[i]]) 
							{
								obj[namesArray[i]] = '';
							}
						
							if (typeof obj[namesArray[i]].push == 'undefined') {
								obj[namesArray[i]] = [];
							}
							obj[namesArray[i]].push(el[j].value);
							
						}
						break;
					case 'input':
						switch (el[j].type.toLowerCase()) {
							case 'radio':
								// Set radio's value only if checked
								if (el[j].checked) {
									obj[namesArray[i]] = el[j].value;
								}
								break;
							case 'checkbox':
								// A checkbox must be checked in order for its value
								// to be serialized
								if (!el[j].checked) continue;
								if (el.length > 1) {
									// we have an array of checkboxes
									if (typeof obj[namesArray[i]] == 'undefined') {
										obj[namesArray[i]] = [];
									}
									obj[namesArray[i]].push(el[j].value);
								} else {
									// not an array, add just its value
									obj[namesArray[i]] = el[j].value;
								}
								
								break;
							default: // other input elements - text, hidden
								// detect php arrays
								if (namesArray[i].substring(namesArray[i].length - 2) == '[]') {
									if (!this.isA(obj[namesArray[i]])) {
										obj[namesArray[i]] = [];
									}
									obj[namesArray[i]].push(el[j].value);
								} else {
									obj[namesArray[i]] = el[j].value;
								}
						}
						break;
					case 'textarea':
						obj[namesArray[i]] = el[j].value;
						break;
				}
			}
		}
		
		return obj;
	},
	
	/**
	 * Serializes form elements by name into a JSON string
	 *
	 * Note: requires JSON.js (obtain from http://www.json.org)
	 *
	 * @param mixed form - id/class (prefixed with a '.')/object of the form element
	 * @param Array namesArray - an array of strings with the elements u want to serialize
	 *
	 */
	serializeFormToJSON : function(form, namesArray) {
		if (!Object.prototype.toJSONString) return false;
		var obj = this.serializeFormToObject(form, namesArray);
		return obj.toJSONString();
	},
	
	/**
	* getPageSize()
	* Returns array with page width, height and window width, height
	* Core code from - quirksmode.org
	* Edit for Firefox by pHaez
	*
	* Edited by Max Raskin to return a hash table:
	* @return Array ['pageWidth', 'pageHeight', 'windowWidth', 'windowHeight']
	*/
	getPageSize : function () {
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
	
		arrayPageSize = [];
		
		arrayPageSize['pageWidth'] = pageWidth;
		arrayPageSize['pageHeight'] = pageHeight;
		arrayPageSize['windowWidth'] = windowWidth;
		arrayPageSize['windowHeight'] = windowHeight;
		return arrayPageSize;
	},

	/**
	* Creates a DOM on load handler, allows you to modify the DOM
	* when its finished loading (even if other elements weren't loaded yet)
	* Based on Solutions by: Dean Edwards/Matthias Miller/John Resig
	*
	* URL: http://dean.edwards.name/weblog/2006/06/again/
	*
	* Konqueror and Multiple Loaders via MSIE support added by Max Raskin (24.06.07).
	*
	* Browsers Tested with : IE6, IE7, FireFox 2.0/Win, FireFox 1.5/Linux, Konqueror 3.5.2/Linux
	*
	* Function Assembled by: Max Raskin
	*
	* @param Function func 			  - callback function to call when DOM's loaded.
	* @param Object[optional] bindObj - an object to bind the function to
	*
	* @return bool - true if succeeded setting a DOM event listener, false if
	*				 reverted to regular onload listener
	*/
	setDOMLoadHandler : function(f, bindObj) {
		var func = f;
		
		// Bind to an object if specified
		if (typeof bindObj != 'undefined' 
		    && typeof func.apply == 'function') {
				func = rDom.bindToObj(f, bindObj);
		}
		/* for Mozilla/Opera9 */
		if (document.addEventListener 
			&& !/WebKit/i.test(navigator.userAgent)
			&& !/Konqueror/i.test(navigator.userAgent)) {
					
		    document.addEventListener("DOMContentLoaded", func, false);
		    return true;
		}
		
		/* for Internet Explorer */
		/*@cc_on @*/
		/*@if (@_win32)
			var num = 1;
			while (document.getElementById("__ie_onload" + num)) {
				num++;
			}
			
		    document.write("<script id=__ie_onload" + num + " defer src=javascript:void(0)><\/script>");
		    var script = document.getElementById("__ie_onload" + num);
		    script.onreadystatechange = function() {
		        if (this.readyState == "complete") {
		        
		            func(); // call the onload handler   
		        }
		    };
		    return true;
		  
		/*@end @*/
		
		
		
		/* for Safari/Konqueror */
		if (/WebKit/i.test(navigator.userAgent) 
			|| /Konqueror/i.test(navigator.userAgent)) {
		    var _timer = setInterval(function() {
		        if (/loaded|complete/.test(document.readyState)) {
		        	// call the onload handler
		            var initfunc = function(event,_timer) {
		            	clearInterval(_timer);
		            	func(event);
		            }
		            initfunc(event,_timer);
		        }
		    }, 10);
		    return true;
		}
		
		// In case all above failed, use regular load event handler
		rDom.addEvent(window, 'load', func);
		return false;
	}
	
};

/**
* Dynamically includes a js file - lazy loadin' style baby! :-)
* @param string fileName - full file name and path to include
*/
function includeJs(fileName)
{
	var script = rDom.createEl('script');
	script.setAttribute('type', 'text/javascript');
	script.setAttribute('src', fileName);
	document.getElementsByTagName('head')[0].appendChild(script);
}

/**
* Dynamically includes a stylesheet file - lazy loadin' style baby! :-)
* @param string fileName - full file name and path to include
*/
function includeCss(fileName)
{
	var link = rDom.createEl('link');
	link.setAttribute('type', 'text/css');
	link.setAttribute('rel', 'stylesheet');
	link.setAttribute('href', fileName);
	document.getElementsByTagName('head')[0].appendChild(link);
	
}
/**
 * Checks whether a given value is in an array
 *
 * @param mixed needle - what to look for
 * @param array haystack - the array to look in
 */
function in_array(needle, haystack) {
	if (typeof haystack == 'undefined' || haystack === null) {
		return false;
	}
	for (i = 0; i < haystack.length; i ++) {
		if (needle == haystack[i]) {
			return true;
		}
	}
	return false;
}

function isset(o) {
	return (typeof o != 'undefined');
}

/**
 * Checks whether a given key is in an array
 *
 * @param mixed needle - what to look for
 * @param array haystack - the array to look in
 */
function is_array_key(needle, haystack) {
	if (typeof haystack == 'undefined' || haystack === null) {
		return false;
	}
	for (key in haystack) {
		if (needle === key) {
			return true;
		}
	}
	return false;
}


/**
 * Extendable function collections object
 * elements are extended either by their nodeName (select for instance)
 * or type attribute (for input elements)
 *
 * to create a new function collection simply name a type or nodeName as
 * an object within rExtendable and implement any functions you'd like,
 *
 * @var Object
 */

var rExtendableElements = {
	// Global functions which extend ANY element
	global : {
		/**
		 */
		$ : function (s) {
			return rDom.$(s,this);
		},
        
        hide : function() {
                       
            this.style.display = 'none';
        },
        
        show : function() {
            
                this.style.display = 'block';
            
        },
        
        
        removeNode : function() {
			this.parentNode.removeChild(this);
		},
		
        /** 
         * @see rDom.toggleChildrenByClass
         */
		hideChildrenByClass : function(c) {
            rDom.toggleChildrenByClass(this, c, true);
        },
        
        /** 
         * @see rDom.toggleChildrenByClass
         */
        showChildrenByClass : function(c) {
            rDom.toggleChildrenByClass(this, c);
        },
        
		up : function(tagName) {
			return rDom.$(this.findNode(tagName));
		},
		
		down : function(tagName) {
			return rDom.$(this.findNode(tagName, 1));
		},
		
		/**
		 * Looks up for an element of tagName either up or down
		 * relatively to a specified element.
		 *
		 * @param String tagName - which element to lookup for (css supported - i.e. div.monkey for class 
		 *														or div#donkey for id)
		 * @param int[optional] dir - if -1 (default) looks up, if 1 looks down
		 *
		 */
		findNode : function(tagName, dir) {
			var el = this;
			
			var isClass = false, isId = false, tmp;
			
			if (tagName.indexOf('.') > -1) {
				isClass = true;
				tmp = tagName.split('.'); // claass
				tagName = tmp[0];
			} else if (tagName.indexOf('#') > -1) {
				isId = true;
				tmp = tagName.split('#'); // id
				tagName = tmp[0];
			}
			tagName = tagName.toUpperCase();
			
			if (!dir || dir == -1) { // find element up
				while (el) {
					if (el.nodeName == tagName) {
						if (isClass) {
							if (this.cssClassCheck(el, tmp[1])) {
								return el;
							}
						} else if (isId) {
							if (el.id == tmp[1]) {
								return el;
							}
						} else {
							return el;
						}
					
						
					}
					el = el.parentNode;
				}
			}
		}

	},
	select : {
		/**
		 * Selects item(s) by value if found (and unselects all the rest)
		 * @param string|array val
		 *
		 * @return int - number of items selected
		 */
		selItemByVal : function(val) {
			var numSel = 0;
			
			if (typeof val.push == 'undefined') {
				val = [val]
			}
			
			for (var i = 0; i < this.options.length; i++) {
				for (j = 0; j < val.length; j ++)  {
					if (this.options[i].value == val[j]) {
						numSel ++;
						this.options[i].selected = true;
					} else {
						this.options[i].selected = false;
					}
				}
			}
			return numSel;
		},
		
		modifyItem : function(index, text, value) {
			this.options[index] = new Option(text, value, false, false);
		},
		
		/**
		 * Checks whether an index's in range
		 *
		 * @return bool
		 */
		isInRange : function(index) {
			return (index >= 0 && index < this.length);
		},
		
		/**
		 * Copies all items to destination select box
		 * @param object destList - destination select box
		 * @param bool[optional]	 clear - if true, clears destination list box
		 */
		copyTo : function(destList, clear) {
			if (clear) rDom.$(destList).clear();
			for (var i = 0; i < this.options.length; i++) {
				destList.options[i] = new Option(this.options[i].text, this.options[i].value, 
					   							 this.options[i].defaultSelected, this.options[i].selected);
			}
		},
		         
		/**
		 * Safely swaps items by indices
		 *
		 * @param int src  - source index
		 * @param int dest - destination index
		 *
		 * @return bool
		 */
		swapItems : function(src, dest) {
			
			// if target is out of range don't move
			if (!this.isInRange(dest)) {
				return false;
			} else {
				var cloneDest = new Option(this.options[dest].text, this.options[dest].value, 
									   this.options[dest].defaultSelected, this.options[dest].selected);
				
				this.options[dest] = new Option(this.options[src].text, this.options[src].value, 
									   this.options[src].defaultSelected, this.options[src].selected);
				// swap dest with src
				this.options[src] = cloneDest;
				return true;
			}
		},
		
		/**
		 * Inserts an option to a specified index in the list
		 * @param object option
		 * @param int index
		 *
		 */
		insertOptionToIndex : function (option, index) {
			
			if (this.options[index] == null) {
				this.options[index] = option;
			} else {
				var opArr = [];
				for (var i = index; i < this.length; i++) {
					opArr.push(this.options[i]);
				}
				
				this.options[index] = option;
				
				for (var i = 0; i < opArr.length; i++) {
					this.options[index + i + 1] = opArr[i];
					
					
				}
			}
			
		},
		
		
		
		/**
		 * Removes an item by value
		 * @param string val
		 * @param bool[optional] returnItem - returns removed item
		 *
		 * @return bool | object {option:Option,index:int}
		 */
		removeItemByVal : function(val, returnItem) {
			for (var i = 0; i < this.options.length; i++) {
				if (this.options[i].value == val) {
					if (returnItem) {
						var o = this.options[i];
						retObj = {option : o, index : i};
						this.options[i] = null;
						return retObj;
					}
					this.options[i] = null;
					return true;
				}
			}
			
			return false;
		},
		
		clear : function() {
			for (var i = this.options.length - 1; i >= 0 ; i--) {
				this.options[i] = null;
			}
		},
		/**
		 * Checks whether an item appears in the list by value
		 * @param string val
		 *
		 * @return bool
		 */
		isInListByVal : function(val) {
			
			for (var i = 0; i < this.options.length; i++) {
				if (this.options[i].value == val) {
					return true;
				}
			}
			
			return false;
		},
		
		/**
		 * Gets the selected item's value
		 * @param multiple - if true, returns an array
		 * @return String|Array
		 */
		getSelItemVal : function(multiple) {
			if (typeof multiple != 'undefined') {
				var items = [];
				for (var i = 0; i < this.options.length; i++) {
					if (this.options[i].selected) {
						items.push(val);
					}
				}
			} else {
				if (this.selectedIndex == -1) {
					return null;
				}
			}
			
			
			return (items) ? items : this.options[this.selectedIndex].value;
		},
		
		/**
		 * Changes a selected item
		 *
		 * @param String text
		 * @param String value
		 */
		changeSelItem : function(text, value) {
			this.options[this.selectedIndex].text = text;
			this.options[this.selectedIndex].value = value;
		},
		
		/**
		 * Removes selected items
		 *
		 * @bool selectItem[optional] - if true selects the first item
		 * @return int - number of items removed
		 */
		removeSelItems : function(selectItem) {
			var numRemoved = 0;
			
			for (var i = this.options.length - 1; i >= 0 ; i--) {
				if (this.options[i].selected) {
					this.options[i] = null;
					numRemoved++;
				}
			}
			if (selectItem) {
				this.selectedIndex = 0;
			}
			return numRemoved;
		},
		
		/**
		 * Inserts a new option
		 *
		 * @param string text
		 * @param string value
		 * @param bool   defaultSelected
		 * @param bool   selected
		 */
		insertItem : function(text, value, defaultSelected, selected) {
			this.options[this.length] = new Option(text, value, 
												   defaultSelected, selected);
		},
		
		/**
		 * Inserts items from a hash table
		 *
		 * @param Array hash
		 */
		insertItemsFromHash : function (hash) {
			for (var k in hash) {
				this.insertItem(hash[k], k);
			}
		},
		
		/**
		 * Deselects all items
		 *
		 */
		deselectAll : function() {
			for (var i = this.options.length - 1; i >= 0 ; i--) {
				this.options[i].selected = false;
			}
		}
	}, /// End select methods
	
	div : {
		echoColored : function(color) {
			this.innerHTML = '<span style="color:' + color + '">' + this.innerHTML + '</span>';
		}
		
	}
}


/**
 * Extends an element with functions from an object
 * [!] a function collection object is simply an object with an array of
 *      functions
 *
 * The function stores an array flag within the object to know which
 * function collections were used to extend it, so no unneccassary
 * operations will occur in case has already been extended.
 *
 * @param object el - the element to extend
 * @param object funcsColl - a functions collection
 */
function rExt(el, funcsColl) {
	if (typeof el['____extended'] == 'undefined') {
		el['____extended'] = [];
	}
	
	if (!in_array(funcsColl, el['____extended'])) {
		for (func in funcsColl) {
			if (funcsColl.hasOwnProperty(func)) {
				el[func] = funcsColl[func];
			}
		}
		el['____extended'].push(funcsColl);
	}
}

/*
	Gets GET variables from page's location.

	Returns:
		associative array or null on failure
	
*/
function getVars()
{
	if (window.location.href.indexOf('?') == -1) return null;
	
	var vars = window.location.href.substring(window.location.href.indexOf('?') + 1, window.location.href.length);
	
	vars = vars.split('&');
	var ret = new Array();
	
	for (var i = 0; i < vars.length; i++)
	{
		var h = vars[i].indexOf('#');
		if (h > -1) {
			vars[i] = vars[i].substring(0, h);
		}
		var tmp = vars[i].split('=');
		ret[tmp[0]] = tmp[1];
	}
	
	return ret;
}

//////////////////////////////////
/// built in objects extensions://
//////////////////////////////////
// Taken from http://www.mredkj.com/javascript/numberFormat.html
Number.prototype.addCommas = function() {
	nStr = this + '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	if (x2.length && x2.length < 3) {
		x2 += '0';
	}
	return x1 + x2;
}

Number.prototype.NaN0 = function() {	
	return (isNaN(this)) ? 0 : this;
}

/*Site global js file*/

var Global = {
	
	// css classes declared in css/he/global.css
	overlayCSSClass		 : 'overlay', 	  // Background overlay
	loginDialogCSSClass  : 'loginDialog', // Login modal dialog form
	
	
	searchKeyPressed 	 : false,
	searchStringLabel 	 : 'Text',
	searchStringCSSClass : 'searchStringLabel',

	init : function() {
		
		// Event handlers for search string input box
		
		
		if (langSelForm = rDom.$('langSelect')) {
			rDom.$('langSelect').langId.onchange = function () {
				langSelForm.submit();
			}
		}
		
	},
		
	onClickLogin : function(ev) {
		// create overlay
		if (!this.o) {
			this.o = document.createElement('div');
			this.o.className = this.overlayCSSClass;
			document.body.appendChild(this.o);
			this.o.style.width = '100%';
			// create login dialog form
			this.loginDlg = document.createElement('div');
			this.loginDlg.className = this.loginDialogCSSClass;
			var g = rDom.$('globalVars'); // global vars form (header.tpl)
			this.loginDlg.innerHTML = 
			'<form id="loginFormDialog" method="post" action="?action=login&amp;srcPage=' + rDom.$('pageName').value + '">' +
				'<fieldset>' +
				  '<h1>' + g.loginLangLoginTitle.value + '</h1>' +
				
				   '<label for="login_email">' + 
						'<span>'  + g.loginLangEmail.value +  ':</span>' +
						'<input type="text" maxlength="32" id="login_email" name="login_email" />' +
					'</label>' +
					
					'<label for="login_password">' +
						'<span>' + g.loginLangPassword.value + '</span>' +
						'<input type="password" maxlength="32" id="login_password" name="login_password" />' +
					'</label>' +
					
					'<label for="remember_me" id="remember_me_cont">' +
						'<span>' + g.loginLangRememberMe.value +'</span> ' +
						'<input type="checkbox" id="remember_me" name="remember_me" />' +
					'</label>' +
					
					'<div class="lostPass">' +
						'<a href="?action=lost_pass">' + g.loginLangLostPass.value + '</a>' +
					'</div>' +
					
					'<div class="buttonsArea">' +
						'<input class="firstChild" type="submit" value="' + g.loginLangLogin.value + '" name="submitLogin" />' +
						'<input type="button" value="' +g.loginLangCancel.value + '" name="cancelLogin" />' +
					'</div>' +
				'</fieldset>' +
			'</form>';
			
			document.body.appendChild(this.loginDlg);
			rDom.addEvent(rDom.$('loginFormDialog').submitLogin, 'click', this.onClickLoginSubmit, this);
			rDom.addEvent(rDom.$('loginFormDialog').cancelLogin, 'click', this.onClickLoginCancel, this);
		}
		
		
		
		this.o.style.display = 'block';
		this.loginDlg.style.display = 'block';
		rDom.$('loginFormDialog').login_email.focus();
		var pageSize = rDom.getPageSize();
		this.o.style.height = pageSize['pageHeight'] + 'px';
		
		// Window resize timer
		this.oTimer = setInterval(rDom.bindToObj (function() {
									var pageSize = rDom.getPageSize();
									this.o.style.height = pageSize['pageHeight'] + 'px';
									}, this), 250);
		
		
		rDom.stopEvent(ev);
	},
	
	onClickLoginSubmit : function(ev) {
		
	},
	
	onClickLoginCancel : function(ev) {
		
		if (this.o) {
			clearInterval(this.oTimer);
			this.o.style.display = 'none';
			this.loginDlg.style.display = 'none';
			
		}
	},
	
	onSubmitGeneralSearch : function (ev) {
		if (!this.searchKeyPressed) {
			
			rDom.stopEvent(ev);
			var g = rDom.$('globalVars'); // global vars form (header.tpl)
			alert(g.globalLangEnterSearchPhrase.value);
			rDom.$('searchString').focus();
			
		}
	},
	
	// Adds/removes 'on value' label of the search input text field
	onSearchString : function (ev) {
		var el = rDom.getTarget(ev);
		switch(ev.type) {
			case 'blur':
			
				if (!this.searchKeyPressed) {
					rDom.cssClassAdd(el, this.searchStringCSSClass);
					el.value = this.searchStringLabel;
				}
				break;
			
			case 'focus':
			
				if (!this.searchKeyPressed) {
					
					el.value = '';
					rDom.cssClassRemove(el, this.searchStringCSSClass);
				}
				break;
				
			case 'keypress':
				this.searchKeyPressed = true;
				break;
		}
		
		
	}
	
}

rDom.setDOMLoadHandler(Global.init, Global);
var isIE6 = (navigator.userAgent.indexOf("MSIE 6.") != -1);
var isIE5 = (navigator.userAgent.indexOf("MSIE 5.5") != -1);
var doc_  = document;
var imgs_ = new Array();
function getStyle(oElm, strCssRule)
	{
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	else if(oElm.currentStyle)
		{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1)
			{
			return p1.toUpperCase();
			});
		strValue = oElm.currentStyle[strCssRule];
		}
	return strValue;
	}



function loadPNG()
	{	
	if (!(isIE6 || isIE5))
		return ;
	var nodes_ = 	document.getElementsByTagName("*");
	var len_ 	= 	nodes_.length;
	for (var i = 0; i < len_ ; i++)
		{
		background_style = getStyle(nodes_[i],"backgroundImage");
		if (background_style != "none" && background_style != "")
			{
			background_url = background_style.replace("url(\"","").replace("\")","");
			background_ext = background_url.substr(background_url.length-3,3).toUpperCase();
			if (background_ext == "PNG")
				{
				
				background_url = "images/badges/"+getStyle(nodes_[i],"backgroundImage").match("([0-9a-zA-Z_]*)[\.](png)")[0];
				nodes_[i].style.background = "";
				nodes_[i].style.width = nodes_[i].offsetWidth + " px";
				nodes_[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+background_url+"',sizingMethod='image')";
				}
			}
		if (nodes_[i].tagName == "IMG")
			{
			image_url = nodes_[i].src;
			image_ext = image_url.substr(image_url.length-3,3).toUpperCase();
			if (image_ext == "PNG")
				{
				image_url = "images/badges/" + image_url.match("([0-9a-zA-Z_]*)[\.](png)")[0];
				nodes_[i].style.height = nodes_[i].offsetHeight + " px";
				nodes_[i].style.width = nodes_[i].offsetWidth + " px";
				nodes_[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+image_url+"',sizingMethod='image')";
				nodes_[i].src = "images/blank.gif";
				}
			}
		}
	}
function boubleMe(event,obj)
	{
	if (!event) var event = window.event;
	if (obj.getElementsByTagName("span")[0].className == "nobubble") 
		return ;
	
	var alt = obj.getElementsByTagName("span")[0].innerHTML;
	
	
	var bouble = doc_.getElementById("bouble");
	
	var bouble_height = 122;
	var bouble_width = 184;
	
	bouble.getElementsByTagName("div")[0].innerHTML = alt;

	bouble.style.display = "block";
	bouble.style.position = "absolute";
	bouble.style.top = (event.clientY-bouble_height-5 + doc_.documentElement.scrollTop) + "px";
	bouble.style.left = (event.clientX-bouble_width+70) + "px";

	}
function initLoad()
	{
	loadImages();	
	
	if (document.getElementById("badges"))
		var	nodes_ = document.getElementById("badges").getElementsByTagName("li");

	for (i=0;i<nodes_.length;i++)
		{
		nodes_[i].onmouseover = function() {
					
					 if (this.className == 'Contact')
					 	return ;
					 
					 if (isIE6 || isIE5 ) 
					 	this.style.background = "url('images/badges/" + this.className + "On.png')"; 
					 else
					 	{
					 	
					 	this.style.backgroundImage = "none";
					 
					 	this.getElementsByTagName("a")[0].style.backgroundImage = "none";
					 	
					 	this.getElementsByTagName("a")[0].style.background = "url('images/badges/" + this.className + "On.png')"; 
						}
					 loadPNG();
					
					 } 
		nodes_[i].onmouseout = function() {
					
					if (this.className == 'Contact')
					 	return ;
					if (isIE6 || isIE5)
						this.style.background = "url('images/badges/" + this.className + "Off.png')";
					else
						this.getElementsByTagName("a")[0].style.background = "url('images/badges/" + this.className + "Off.png')";
					doc_.getElementById("bouble").style.display="none";
					loadPNG();
					} 
		nodes_[i].onmousemove = function(event) { if (this.className != 'Contact')  boubleMe(event,this); };
		}
	var	intro_ = document.getElementById("intro");
	var 	nodes_	= intro_.getElementsByTagName("li");
	for (i=0;i<nodes_.length;i++)
		{
		nodes_[i].onmouseover = function() { changeMenu(this); }
		}

	if (!(isIE6 || isIE5))
		return;
	loadPNG();
	}
function loadImages()
	{
	//Todo : add here all the images to load
	var images = new Array("images/intro/marketing.jpg","images/intro/crm.html","images/intros/CRMEnd.gif","images/intros/marketingEnd.gif")
	for (i = 0; i<images.length;i++)
		{
		imgs_[i] = new Image();
		imgs_[i].src = images[i];
		}
	}
	
function changeMenu(obj)
	{
	var	intro_ = document.getElementById("intro");
	var 	nodes_	= document.getElementsByTagName("li");
	for (i=0;i<nodes_.length;i++)
		{
		nodes_[i].className = nodes_[i].className.replace(" selected","");
		}
	document.getElementById("intro").className = obj.className;
	obj.className += " selected";
	}
window.onload = initLoad;