var win = null;
var baseURL;
window.onerror = null;
baseURL = window.location.protocol + "//" + window.location.hostname + "/";


function inURL( str ) {
	if( window.location.href.indexOf( str ) != -1 ) return true;
	return false;
}

// NEW WINDOW
function newWindow(mypage, myname, w, h, scroll) {
	closePopWin();
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresize';
	win = window.open(mypage, myname, winprops);
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// CLOSE POPUP
function closePopWin()  {
	if(win != null) {
		if(!win.closed) {
			win.close();
			win = null;
		} else {
			win = null;
		}
	}
}

// GET OBJECT BY ID.. OLDER METHOD
function getObject(id) {
	var object = null;
	if( document.layers ) object = document.layers[id];
	else if( document.all ) object = document.all[id];
	else if( document.getElementById )  object = document.getElementById(id);
	return object;
}

// GOOGLE ANALYTICS
if (typeof(_gat) == "object") { 
	//var pageTracker = _gat._getTracker("UA-5192063-3");
	var pageTracker = _gat._getTracker("UA-5192063-2");
	pageTracker._initData(); 
	pageTracker._trackPageview(); 
}

function analyticTrack( address ){ 
	pageTracker._trackPageview( address );	
	//getObject('google_tracking_debug').innerHTML = '<!-- [' + address + '] -->'; 
}

// SPOTLIGHT
function spotlight(src) {
	var axel = Math.random()+"";
	var a = axel * 1000000000000000000;
	//var url = src + a + '?';
//	alert(a)
	var url = src + a + "?";
	var spotpix = new Image();
	spotpix.src = url;
	//getObject('spotlight_pixel').innerHTML = '<img src=' + url + ' />';
}




var MAX_DUMP_DEPTH = 10;

function dumpObj(obj, name, indent, depth) {
	  if (depth > MAX_DUMP_DEPTH) {
			 return indent + name + ": <Maximum Depth Reached>\n";
	  }
	  if (typeof obj == "object") {
			 var child = null;
			 var output = indent + name + "\n";
			 indent += "\t";
			 for (var item in obj)
			 {
				   try {
						  child = obj[item];
				   } catch (e) {
						  child = "<Unable to Evaluate>";
				   }
				   if (typeof child == "object") {
						  output += dumpObj(child, item, indent, depth + 1);
				   } else {
						  output += indent + item + ": " + child + "\n";
				   }
			 }
			 return output;
	  } else {
			 return obj;
	  }
}

String.prototype.linkify=function(){
	return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&;\?\/.=]+/g,function(m){
		return m.link(m);
	});
};
String.prototype.linkuser=function(){
	return this.replace(/[@]+[A-Za-z0-9-_]+/g,function(u){
		return u.link("http://twitter.com/"+u.replace("@",""));
	});
};
String.prototype.linktag=function(){
	return this.replace(/[]+[A-Za-z0-9-_]+/,function(t){
		return t;
	});
};
