/**
 * 3Dify 1.0 - 2011-04-30
 * Copyright (c) 2010 Serafino Bilotta (serafinobilotta@hotmail.com - http://www.p2warticles.com)
 *  * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * More information on this project:
 * http://www.p2warticles.com/
 * 
 * Requires: jQuery v1.3+
 * 
 * Full Usage Documentation: http://www.p2warticles.com/2011/04/3dify-plugin/
 * Usage:
 *		$(el).threedify({
 *	 		posZ: value,		tilt of element, default 0
 *	 		angle: value		angle of perspective, default 15
 *		});
 * 
 */

(function($){  
 $.fn.threedify = function(options) {  
 	var defaults = {
		posZ:0,
		angle:15
	};
	var options = $.extend(defaults, options);
  
    return this.each(function() {  
 
	$(this).mousemove(function(e) {
        var posX = (50 - (e.layerX) / $(e.currentTarget).width() * 100);
        var posY = (-50 + (e.layerY) / $(e.currentTarget).height() * 100);
        var cssObj = {
            'transform': 'rotate3d(' + posY + ',' + posX + ', '+options.posZ+', '+options.angle+'deg)',
            '-webkit-transform': 'rotate3d(' + posY + ',' + posX + ','+options.posZ+' , '+options.angle+'deg)',
			'-moz-transform': 'rotate3d(' + posY + ',' + posX + ','+options.posZ+' , '+options.angle+'deg)',
			'-o-transform': 'rotate3d(' + posY + ',' + posX + ','+options.posZ+' , '+options.angle+'deg)',
			'-ms-transform': 'rotate3d(' + posY + ',' + posX + ','+options.posZ+' , '+options.angle+'deg)'
        };
        $(this).css(cssObj);
    });
 
    });  
 };  
})(jQuery);
