window.log = function(){
  log.history = log.history || [];   
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);

$.expr[':'].external = function(obj) { return !obj.href.match(/^mailto:/) && (obj.hostname != document.location.hostname); };
$.expr[':'].mailto = function(obj) { return obj.href.match(/^mailto:/); };

var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0] ); return v > 4 ? v : undef; }());

$('a').live('click', function(e) {
	
	var elem = $(this), href = elem.attr('href'), _host = document.domain.replace(/^www\./i,""), _pattern = "^(?:https?:)?\/\/(?:(?:www)\.)?" + _host + "\/?";

	if ((href.match(/^https?\:/i)) && (!href.match(_pattern))) {
		if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) { _gaq.push(['_trackEvent', 'Download', 'click', href]); } 
		else { _gaq.push(['_trackEvent', 'External', 'click', href]); } } 
	else if (href.match(/^mailto\:/i)) { _gaq.push(['_trackEvent', 'Email', 'click', href.substr(7)]); } 
	else if (href.match(/^.*\.(pdf|jpg|png|gif|zip|mp3|txt|doc|rar|js|py)$/i)) { _gaq.push(['_trackEvent', 'Download', 'click', href]); }
	
});

var url_params = {};

(function() {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

    while (e = r.exec(q))
       url_params[d(e[1])] = d(e[2]);
})();

function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g,' ')); }

