(function($) {
    var printAreaCount = 0;

    $.fn.printArea = function()
        {
            var ele = $(this);

            var idPrefix = "printArea_";

            removePrintArea( idPrefix + printAreaCount );

            printAreaCount++;

            var iframeId = idPrefix + printAreaCount;
            var iframeStyle = 'position:absolute;width:500px;height:500px;left:-500px;top:-500px;';

            iframe = document.createElement('IFRAME');

            $(iframe).attr({ style : iframeStyle,
                             id    : iframeId
                           });

            document.body.appendChild(iframe);
            
            //var doc = iframe.contentWindow.document;
            var doc = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;

            /*$(document).find("link")
                .filter(function(){
                        return $(this).attr("rel").toLowerCase() == "stylesheet";
                    })
                .each(function(){
                        doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
                    });*/
            doc.write('<link type="text/css" rel="stylesheet" href="/media/styles/belk_v1.css" />');
            doc.write('<link type="text/css" rel="stylesheet" href="/media/styles/shop_v1.css" />');
            doc.write('<link type="text/css" rel="stylesheet" href="/media/styles/bridal_v1.css" />');

            doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
            doc.close();
            $(iframe).load(function(){
            	var frameWindow = iframe.contentWindow;
				frameWindow.focus();
				frameWindow.print();
				frameWindow.close();
          });
          $(doc).ready(function(){
            	var frameWindow = iframe.contentWindow;
				frameWindow.focus();
				frameWindow.print();
				frameWindow.close();
         });
            
        }

    var removePrintArea = function(id)
        {
            $( "iframe#" + id ).remove();
        };

})(jQuery);



