(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:0px;height:0px;left:-500px;top:-500px;';
      print_iframe = document.createElement('IFRAME');
      $(print_iframe).attr({
         style : iframeStyle,
         id    : iframeId
      });
      document.body.appendChild(print_iframe);
      var doc = print_iframe.contentWindow.document;
      $(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('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
      doc.close();
      var content = $(ele).html();
      if(content != null) {
         h = '<!--[if lte IE 7]> <body onLoad="if (win3.location.href.indexOf(\'reload\')==-1) win3.location.reload()">  <![endif]-->\n\
              <link href="/inc/css/default-print.css" rel="stylesheet" type="text/css" />\n\
              <div class="' + $(ele).attr("class") + '">' + content + '</div>\n\
              <? exit; ?>\n\
              <!--[if lte IE 7]>  </body>  <![endif]-->';
         win3 = window.open("", "Window3", "width=860,height=600,scrollbars=yes");
      } else {
         h = 'Ova stranica nije predefinisana za štampu'
         win3 = window.open("", "Window3", "width=300,height=100,scrollbars=yes");
      }
      win3.document.write(h);
      win3.document.close();
//      win3.focus()
      
      if($(ele).html() != null) {
         win3.print();
      }
      win3.stop();
   }
   var removePrintArea = function(id) {
   $( "iframe#" + id ).remove()
   }
})(jQuery);



