/**
 * jQuery.window
 * 
 * @version 0.2.0
 */

jQuery.window = {};

/**
 * popup
 * @param String url
 * @param Object settings
 * @return Boolean false
 */
jQuery.window.popup = function (url, settings) {
 	settings = jQuery.extend({
 		name:'popup',
 		width:400,
 		height:300
 	}, settings);
 	
 	var posX = (screen.width - settings.width) / 2;
	var posY = (screen.height - settings.height) / 2;
	
	var options  = 'height=' + settings.height + ',';
	options 	+= 'width=' + settings.width + ',';
	options 	+= 'top=' + posY + ',';
	options 	+= 'left=' + posX + ',';
	options 	+= 'scrollbars=1';
 	
 	var popup = window.open(url, settings.name, options);
 	
 	if (window.focus) {popup.focus();}
	
	return (false);
};

/**
 * zoom
 * @param img
 * @return Boolean
 */
jQuery.window.zoom = function (img) {
	if (document.images) {
		var NEWLINE = "\n";
		
		var options = "resizable=yes,"
		options += "width=150,";
		options += "height=150,";
		options += "left=" + ((screen.width / 2) - 75) + ",";
		options += "top=" + ((screen.height / 2) - 75);
		
		var htmlTemp = '<html>' + NEWLINE;
		htmlTemp += '<head>' + NEWLINE;
		htmlTemp += '<title>Zoom Image</title>' + NEWLINE;
		htmlTemp += '</head>' + NEWLINE;
		htmlTemp += '<body style="margin:0;" onload="var myImage = new Image();myImage.src = \'' + img + '\';window.resizeBy((myImage.width - 150), (myImage.height - 150));window.moveBy(-((myImage.width - 150) / 2), -((myImage.height - 150) / 2));" onblur="self.close();">' + NEWLINE;
		htmlTemp += '<a href="javascript:self.close();"><img src="' + img + '" border="0" alt="Fermer" title="Fermer" /></a>' + NEWLINE;
		htmlTemp += '</body>' + NEWLINE;
		htmlTemp += '</html>' + NEWLINE;
		
		var popup = window.open('', 'zoom', options);
		
		popup.document.write(htmlTemp);
		popup.document.close();
		
		if (window.focus) {
			popup.focus();
		}
		
		return false;
	}
	else {
		return true;
	}
};

/**
 * toOpener
 * @param className
 * @return Boolean false
 */
jQuery.window.toOpener = function (className) {
	jQuery('a.' + className).click(function(){
		window.opener.open(this.href, '');
		return false;
	});
};