/**
 * @fileoverview Loads generic modules required for all widgets.
 *
 * <pre>
 * Copyright (c) 2003-2007 by BWin Technologies Ltd.
 * http://www.bwintech.com
 * Quay House, South Esplanade, St. Peter Port
 * GY1 4EJ Guernsey, CI, UK
 * All rights reserved.
 * </pre>
 */

/* $Id: bwin.js */

if (typeof BWin == 'undefined') {BWin = function() {};}																		// Namespace definition.
/**
	* BWin version.
	* @private
	*/
BWin.version = '2.0';
/**
	* Path to main BWin script.
	* @private
	*/
BWin.bwinPath = function() {
  var arrScripts = document.getElementsByTagName('script');																// Get all script elements
  for (var iScript = arrScripts.length - 1; iScript >= 0; iScript--) {										// Find the script in the list
    var strSrc = arrScripts[iScript].getAttribute('src');
    if (!strSrc) {
      continue;
    }
    var arrTokens = strSrc.split('/');
    var strLastToken;																																			// Remove last token
    if (Array.prototype.pop) {
      strLastToken = arrTokens.pop();
    } else {
      strLastToken = arrTokens[arrTokens.length - 1];																			// IE 5
      arrTokens.length -= 1;
    }
    if (strLastToken == '?id=49823') {
      return arrTokens.length ? arrTokens.join('/') + '/' : '';
    }
  }
  return '';																																							// Not found
} ();
/**
	* Convenience funtion.
	*
	* <pre>
	* Instead of the syntax: $(element)
	* One can use now the shorter syntax: $(element)
	* </pre>
	* returns an array of elements or a single element object
	*/
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') { element = document.getElementById(element); }
    if (arguments.length == 1) { return element; }
    elements.push(element);
  }
  return elements;
}
/**
	* Convenience funtion.
	* Addition to the document. interface
	* <pre>
	* Syntax: document.getElementByClassName(className, parentElement)
	* The dom tree is inspected from the specified parentElement
	* </pre>
	* returns an array of elements or a single element object
	*/
if(!document.getElementsByClassName){
	document.getElementsByClassName = function(className, parentElement) {
	  var results = [];
	  var children = ($(parentElement) || document.body).getElementsByTagName('*');

		for(var n = 0; n < children.length; n++){
			if(children[n].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))){
				results.push(children[n]);
			}
		}

		return results;
	};
}
/**
	* Simply writes script tag to the document.
	*
	* <pre>
	* If special BWin.doNotInclude flag is set, this function does nothing.
	* </pre>
	*
	* @private
	* @param {string} strSrc Src attribute value of the script element
	* @param {string} strId Optional. Id of the script element
	*/
BWin.include = function(strSrc, strId) {
  if (BWin.doNotInclude) {return;}																												// Check flag
  document.write('<script type="text/javascript" src="' + 																// Include file
   strSrc + (typeof strId == 'string' ? '" id="' + strId : '') + '"></script>');
};

BWin.include(BWin.bwinPath + '?id=49824', 'BWin.Utils');																		// Include required scripts
BWin.include(BWin.bwinPath + '?id=50112', 'BWin.EventDriven');
BWin.include(BWin.bwinPath + '?id=49825', 'BWin.Transport');
BWin.include(BWin.bwinPath + '?id=50129', 'BWin.Crypto');																		// Required by Transport
BWin.include(BWin.bwinPath + '?id=49826', 'BWin.Widget');
