// http://thinkweb2.com/projects/prototype/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
function __getClass(obj) {
	return Object.prototype.toString.call(obj).match(/^\[object\s(.*)\]$/)[1];
}

//http://snippets.dzone.com/posts/show/4132
function mysqlTimeStampToDate(timestamp) {
	//function parses mysql datetime string and returns javascript Date object
	//input has to be in this format: YYYY-MM-DD HH:MM:SS
	var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
	var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
	return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}

// Convert a single digit integer into a double digit by prepending a zero.
function addZero(num) {
	(String(num).length < 2) ? num = String("0" + num) :  num = String(num);
	return num;
}

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};


$(document).ready(function() {
	
	$('#header_root_link').hover(function() {
		$(this).stop(true, true).fadeTo(500, 1);
	}, function() {
		$(this).stop(true, true).fadeTo(500, 0);
	});
	
	if ($('#flashMessage').length > 0) {
		setTimeout(function() {
			$('#flashMessage').slideUp(500, function() {
				$(this).remove();
			});
		}, 4000);
	}
	
	$('form.do_session_check').click(function(e) {
		e.preventDefault();
		login_popup = window.open('/login?popup');
	});
	
});

function debug(msg) {
	if("console" in window && "firebug" in console) {
		console.log(msg);
	}
}


function errorFlashMessage(msg, intTimeout) {
	$("#main").prepend('<div class="message error_flash" id="flashMessage">'+msg+'</div>');
	
	if(typeof(intTimeout) == 'undefined') {
	 	intTimeout = 1000;
	}
	
	if(intTimeout > 0) {
		setTimeout(function() {
			$('#flashMessage').slideUp(500, function() {
				$(this).remove();
			});
		}, intTimeout);
	}
}