/**
 * Common functions/objects
 * 
 * @author AK
 * /

/**
 * debug/logging
 */
jQuery.log = function(message) {
	if (!$.ppprd.debug.enabled) {
		return false;
	}
	if (window.console && window.console.debug) {
		console.debug(message);
	} else {
		if ($.ppprd.debug.logAlerts) {
			alert(message);
		}
		else {
			return;
		}
	}
};

/**
 * Image Replace
 * Appends some spans to selection, so with css nice IR can happen)
 * @author AK|Peppered
 */
jQuery.fn.ImageReplace = function() {	
	this.each(function() {
		$(this).addClass('ir');		
		$(this).append('<span class="ir-aid"><span></span></span>');	
	});
};

/**
 * PopupWindow object
 * spwans/handles popup windows
 * 
 * @author AK
 * 
 * dependancies: jQuery 1.2.x
 */
function PopupWindow() {
	this.width = 500;
	this.height = 500;
	this.container = $(window);
	this.offsetLeft = 0;
	this.offsetTop = 0;
	this.menubar = true;
	this.location = false;
	this.resizable = true;
	this.scrollbars = true;
	this.status = true;
	this.name = 'popupWindow';
	this.url = ''; 
}
PopupWindow.prototype.prepare = function () {
	oAnchor = this.anchor;
	if (typeof oAnchor.data('popWinObject') == 'object') {
		oPopWin = oAnchor.data('popWinObject');
		if (!oPopWin.closed)
			oPopWin.close();	
	}
	sHref = oAnchor.attr('href');		
	if (sHref.indexOf('?') > -1)
		sHref += '&';
	else
		sHref += '?';	
	sHref += 'popup=true';
	this.url = sHref;
}
PopupWindow.prototype.spawn = function() {
	this.prepare();
	var x = this.container.width() / 2 - (this.width/2);
    var y = this.container.height() / 2 - (this.hegiht/2);
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	this.offsetLeft = x;
	this.offsetTop = y;
	
	oPopWin = window.open(this.url, this.name, 'width='+this.width+',height='+this.height+',left='+this.offsetLeft+',top='+this.offsetTop+',menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes');
	
	if (typeof oPopWin != 'undefined') {
		this.anchor.data('popWinObject', oPopWin);
		//popupWindows.push(oPopWin);
		return true;
	}
	return false;
}
