// JScript source code
(function($){
    
    $.fn.imagegenify = function( opt ) {
        opt = $.extend( {
            fontSize: 12,
            font: "/font/Jigsaw-Stencil-CE.ttf",
            fontColor: "#000000",
            fontStyle: "Regular",
            backgroundColor: "#ffffff",
            parentElement: "*"
            }, opt );
        opt = $.extend( { hoverFontSize: opt.fontSize, hoverFont: opt.font, hoverFontColor: opt.fontColor, hoverFontStyle: opt.fontStyle, hoverBackgroundColor: opt.backgroundColor, width: opt.width }, opt );
        
        // support multiple objects in constructor
		if( this.length > 1 ) {
			this.each( function() { $( this ).imagegenify( opt ); } );
			return this;
		}

        var $this = this,
            text = $( this ).text(),
            normal = '/umbraco/imageGen.ashx?text=' + text + '&Fontsize=' + opt.fontSize + '&Font=' + opt.font + '&FontColor=' + opt.fontColor + '&FontStyle=' + opt.fontStyle + '&BgColor=' + opt.backgroundColor + '&Width=' + opt.width,
            hover = '/umbraco/imageGen.ashx?text=' + text + '&Fontsize=' + opt.hoverFontSize + '&Font=' + opt.hoverFont + '&FontColor=' + opt.hoverFontColor + '&FontStyle=' + opt.hoverFontStyle + '&BgColor=' + opt.hoverBackgroundColor + '&Width=' + opt.width;

        normal = normal.replace( /#/g, "%23" );
        hover = hover.replace( /#/g, "%23" );
        $this
            .empty()
            .append( '<img src="' + normal + '" alt="' + text + '" />' )
            .parent( opt.parentElement ).eq( 0 )
                .hover( function() {
                        $this.find( "img" ).attr( "src", hover );
                    }, function() {
                        $this.find( "img" ).attr( "src", normal );
                    } );

        return this;
    }
    
})(jQuery);
