var curpage;
var _DEBUG						= false;
var _INIT_HOME					= 1;
var _INIT_SCREENSHOTS			= 2;
var _INIT_FEEDBACK				= 3;
var _INIT_GOOGLE_MAPS			= 4;
var _INIT_GOOGLE_MAPS_MINI		= 5;

var _TOGGLE_MINI_MAP			= true;

var _REL_ABOUT_US				= 'about-us';
var _REL_PRODUCTS				= 'products';
var _REL_SUPPORT				= 'support';
var _REL_FEEDBACK				= 'feedback';

var _POPUP						= 'message';
var _POPUP_ERROR				= 'message_error';
var _POPUP_ACCEPT				= 'message_accept';
var _POPUP_INFO					= 1;
var _POPUP_ALERT				= 'message_alert';
var _POPUP_EFFECT				= false;
var _POPUP_TIMER;

var _EMAIL_FILTER				= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
function init(values) {

	if (values.init) {
		values.init == _INIT_HOME ? homeConstr() : '';
		values.init == _INIT_SCREENSHOTS ? ssConstr() : '';
		values.init == _INIT_FEEDBACK ? feedbackConstr() : '';
		values.init == _INIT_GOOGLE_MAPS ? googleMapConstr() : '';
		values.init == _INIT_GOOGLE_MAPS_MINI ? googleMapConstr(_TOGGLE_MINI_MAP) : '';
	}

	if (values.rel) {
		// get link
		var navlinks = $$('#header-nav a');

		for (var i=0; i<navlinks.length; i++) {
			if (navlinks[i].getAttribute('rel') == values.rel) {
				navlinks[i].className = 'active';
			}
		}
	}
}
function uninit(values) {	
	if (values.uninit) {
		values.uninit == _INIT_GOOGLE_MAPS ? GUnload() : '';
		values.uninit == _INIT_GOOGLE_MAPS_MINI ? GUnload() : '';
	}
}

function isArray(obj) {
	return (obj.constructor.toString().indexOf('Array') == -1) ? false : true; 
}

/**
 * Display error message
 *
 * @param		title		The message to display
 * @param		msg			The message to display
 * @param		type		Type of error [_POPUP_ERROR,_POPUP_INFO,_POPUP_ALERT]
 * @param		obj			Referenced object
 * @param		offset		Position offset
 * @param		timeout		Time of how long message should be displayed
 */
function showPopup(title, msg, type, obj, offset, timeout) {
	Element.stopObserving($$('#message div')[0],'click');

	// get middle position to place the popup
	var posLeft = Math.ceil($$('body')[0].getWidth() / 2) - Math.ceil(obj.getWidth() / 2) - Math.ceil($(_POPUP).getWidth() / 2) - offset.x;

	$(_POPUP).setStyle({ left: posLeft+'px', top: offset.y+'px' });

	// update the class to the type of message
	$(_POPUP).className = type;
	$$('#'+_POPUP+' h4')[0].innerHTML = title;
	$$('#'+_POPUP+' p')[0].innerHTML = msg;

	// update zindex to place on top *NOTE: bug with ie6 and lower- popup shows behind form elements
	$(_POPUP).style.zIndex = $(_POPUP).style.zIndex + 1;

	// internet explorer does not handle fades 
	if (/msie/.test(navigator.userAgent.toLowerCase())) {

		// display the popup with no animation
		$(_POPUP).show({ queue: 'end' });

		if (timeout > 0) {
			// close in 5 seconds
			_POPUP_TIMER = setTimeout('hidePopup(true)', timeout);
		}
		// enable the close button to hide the popup
		Element.observe($$('#message div')[0], 'click', function(event) {
			hidePopup(true);
		});
	}
	else {

		// all other browsers fade in 
		$(_POPUP).appear({ duration: 1.0, queue: 'end' });

		if (timeout > 0) {
			// close in 5 seconds
			_POPUP_TIMER = setTimeout('hidePopup()', timeout);
		}
		// enable the close button to hide the popup. allows fade.
		Element.observe($$('#message div')[0], 'click', function(event) {
			hidePopup(false);
		});
	}

	// global setting 
	_POPUP_EFFECT = true;
}

/**
 * Hide popup
 *
 * @ie			ie			If true, does not create animation
 */
function hidePopup(ie) {

	
	// check first if the popup is open
	if (_POPUP_EFFECT) {
		
		// if ie then do not show animation
		if (ie) {
			$(_POPUP).hide({ queue: 'end' });
		}
		else {
			$(_POPUP).fade({ duration: 1.0, queue: 'end' });
		}

		// disable the click so no clicking while fading!
		// Element.stopObserving($$('#message div')[0],'click');

		// cancel the timeout to re-fade/hide the element
		clearTimeout(_POPUP_TIMER);

		// global setting
		_POPUP_EFFECT = false;
	}
}