if( typeof(console)=='undefined' || typeof(console.log)=='undefined' || ! (console.log instanceof Function) ) {

	var console = {};

	if( cdtRegistry.appMode=='dev' ) {

		if( window.opera  && window.opera.postError ) {

			console.log = function( aText ) {
				window.opera.postError( '************************* ' + aText );
			};

			console.log('Opera console spotted !');

		} else {

			var pageStartTime = (new Date()).getTime();
			var numLogs = 0;
			function padLeft(aStr, aPadChar, aLength) {
				aStr = aStr.toString();
				while(aStr.length<aLength)
					aStr = aPadChar + aStr;
				return aStr;
			}

			$customConsole = $('<div id="console-log" style="display: block; width: 100%; background-color: #FFFFE1; border-top: solid #666 1px;">Console<br/></div>');
			$(document).ready( function() {
				$('BODY').append( $customConsole );
			});

			console.log = function( aText ) {

				var logTime = ( Math.round( ( (new Date()).getTime() - pageStartTime )/100 ) / 10 ).toString() ;
				if( logTime.indexOf('.')==-1 )
					logTime = logTime + '.0';

				$customConsole.append( padLeft(++numLogs, '0', 3) + ' :: ' + padLeft(logTime, '0', 5) + ' :: &nbsp;&nbsp;&nbsp;&nbsp; ' + aText+'<br/>'+"\n");
				//$customConsole.stop().scrollTo('max', 'sync', {axis:'y'} );

			};
			//alert('Custom console created.');

		}

	} else {

		console.log = function() {};

	}
}

var curvyCornersNoAutoScan = true;
var curvyCornersVerbose    = false;


$(document).ready( function() {

	_handleIe();
	_handlePromptInputs();
	_handleGlobalSearchForm();

} );


function toggleFlashMap(_switch){

	var flashMap = $('#map');
	
	if(flashMap.length){
		
		var darkBlock = $('#main .darkblock');
		
		if(!_switch) _switch = !(flashMap.css('display') == 'block');
	
		flashMap.toggle(_switch)
		darkBlock.toggle(!_switch);
		
		$('#mapButton').toggleClass('current', _switch);
		
		if(typeof gmap_init == 'function' && map == null) gmap_init();
		
	}
}
	
	
function _handleIe() {

	if($.browser.msie){	
		curvyCorners.init();		
		$('.line .module:last-child').css('margin-right', '0');
	}
		
}


function _handleGlobalSearchForm() {
		
	var form = $('#search form');
	var input = $('input.input', form);
	
	form.submit(function(){
		if(
			input[0].value == input[0].defaultValue ||
			input[0].value.length < 3
		) return false;	
		return true;
	});

}

function _handlePromptInputs() {

	$('form').each(function(){
	
		inputs = $('input.prompt', this);
		
		inputs.focus(function(){
			if(this.value == this.defaultValue) this.value = '';
		});
		
		inputs.blur(function(){
			if(this.value == '') this.value = this.defaultValue;
		});
		
		$(this).submit(function(){
		
			$('input.prompt', this).each(function(){
				if(this.value == this.defaultValue) this.value = '';
			});
		
		});
	
	});

}
