var canlogbannerevent=0
var ntimeouts=10
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var logging=false
var quiet=false
var msiehtmlbuffer='';


$(document).ready(function(){
	logthis( $("#persistentlevel").attr("level")+"="+$("#persistentusername").val())
	if ( ($("#persistentlevel").attr("level")=='admin') || ($("#persistentusername").val()=="info@timo.co.za")) {
			quiet=true
			showhidebanners('hide')
	}

	if (!logging) $('#jqfeedbackholder').remove()
	else {
		$('#jqfeedbackholder').show()
		$('#jqfeedbackholder').before('<span id="dellog">Del</span>')
		$('#dellog').unbind().click(function() {
//			ajaxprefetch()
			logclear()
//			ajaxpostfetch()
		}).addClass('clickable')

		$('#jqfeedbackholder').before('<span id="stoptimer">Stop Timer</span>')
		$('#stoptimer').unbind().click(function() {
//			ajaxprefetch()
			clearalltimeouts()
			$(this).html('Stopped')
//			ajaxpostfetch()
		}).addClass('clickable')
	}


});


function waitforbanner() {
	// set to 11 in bnr_exec
		canlogbannerevent++
		if (canlogbannerevent>10) DoenAjax_logbannerevent('page','home','home')
		else	window.setTimeout( "waitforbanner()", 1000 );


		if (canlogbannerevent>10) MM_preloadImages('feat_articles_over.png','columnists_over.png','web_news_over.png','login_over.png','musicians_corner_over.png','music_reviews_over.png','weekly_events_over.png','archives_over.png')


//		$("#jqfeedbackholder").append('<div class=jqfeedback>'+'waiting:canlogbannerevent='+canlogbannerevent+'</div>')
}

// function DoenAjax_logbannerevent(a,b,c) {
//
// }

//======== ajax prefetch postfetch

function ajaxprefetch() {
	logthis ('<span style="color:red">prefetch</span>')
	setquiet('quiet')
}

function ajaxpostfetch() {
	logthis ('<span style="color:blue">postfetch</span>')
	setquiet('run')
}

//========== logs
function logthis (what) {
if (!logging) return
	$("#jqfeedbackholder").append('<div class=jqfeedback>'+what+'</div>').show()
}
function logclear() {
	$('.jqfeedback').remove()
	$('#jqfeedbackholder').html()
}
//http://simonwillison.net/2003/Dec/13/ieGotcha/

var reportStatus = new Array();

function report ( msg ) {
    reportStatus.push ( msg );
}

function showReport (  ) {
    alert ( reportStatus.join ( "\n" ) );
}

/*just one more thing before we move on. Notice the placement of the onerror  code in the above example; it is declared prior to any other codes, defined inside the <head> section, and wrapped around in its own <script> tags. This is necessary to ensure that the onerror event intercepts all scripting errors in the page.*/

// window.onerror = function ( err, url, line ) {
//     report ( err + " [" + url + " - line " + line + "]" );
//     showReport();
// }

//http://www.netlobo.com/url_query_string_javascript.html
//You want to get the value from the frank parameter so you call the javascript function as follows:
//var frank_param = gup( 'frank' );

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function splitHref (hrefString) {
// gets href attribute and returns matrix of [key]=>[value]
		var matrixString = hrefString.substr(hrefString.indexOf('?')+1)
		matrix = matrixString.split('&')
		var matrix2 = []
		for ( var key in matrix ) {
			var m3 = matrix[key].split('=')
			matrix2[m3[0]] = m3[1]
		}

		return matrix2
}

