(function($){

jQuery.createNewWindow = function(argv) {
   templateOptions = {
     id        : 'mbContainerExtenedWindowObject',
     title     : 'Yeni Pencere',
     buttons   : 'i,c',
     icon      : null,
     closed    : 'false',
     skin      : 'black',
     width     : 500,
     height    : 300,
     dock      : 'dock',
     rememberMe: 'false',
     resizable : false,
     draggable : true,
     fullscreen: false,
     createAfterRemove: true,
     URL       : null,
     TEXT      : null,
     DOM       : null
   };
   jQuery.extend(true,templateOptions,argv);
   //templateOptions.id = templateOptions.id+'__'+Math.round(new Date().getTime());

   if (templateOptions.fullscreen===true) {
      templateOptions.width = jQuery(window).width()-45;
      templateOptions.height = (jQuery(window).height()-85);
   }

   if (jQuery('#'+templateOptions.id).is('div')===true) {
      jQuery('#'+templateOptions.id).remove();
      if ( templateOptions.createAfterRemove===false ) {
         return false;
      }
   }

   var template = new Array();
   template['BEGIN'] = '<div id="'+templateOptions.id+'" class="containerPlus '+(templateOptions.draggable?'draggable':'')+' '+(templateOptions.resizable?'resizable':'')+' {buttons:\''+templateOptions.buttons+'\', '+(typeof(templateOptions.icon)=='string'?'icon:\''+templateOptions.icon+'\',':'')+' closed:\''+templateOptions.closed+'\', skin:\''+templateOptions.skin+'\', width:\''+templateOptions.width+'\', height:\''+templateOptions.height+'\', dock:\''+templateOptions.dock+'\', rememberMe:\''+templateOptions.rememberMe+'\'}"><div class="no"><div class="ne"><div class="n"><b>'+templateOptions.title+'</b></div></div><div class="o"><div class="e"><div class="c"><div class="mbcontainercontent" id="containerContent_'+templateOptions.id+'">';
   template['END'] = '</div></div></div></div><div><div class="so"><div class="se"><div class="s"></div></div></div></div></div></div>';
   jQuery(document.body).append(template['BEGIN']+template['END']);
   //jQuery('#'+templateOptions.id).buildContainers({
   jQuery('.containerPlus').buildContainers({
      containment:"document",
      elementsPath:"/images/mb_elements/",
      mantainOnWindow: !templateOptions.fullscreen,
      effectDuration:1,
      onLoad: function() {
         if (templateOptions.fullscreen===true)
            jQuery('#'+templateOptions.id).css({'top':'70px','left':'20px'});
         else {
            jQuery('#'+templateOptions.id).css('margin-top','70px');
            jQuery('#'+templateOptions.id).mb_centerOnWindow(false);
         }
      }
   });

   if (templateOptions.TEXT)
      jQuery('#containerContent_'+templateOptions.id).html(templateOptions.TEXT);
   if (templateOptions.DOM)
      jQuery('#containerContent_'+templateOptions.id).html(jQuery('#'+templateOptions.DOM).html());
   if (templateOptions.URL) {
      if ( typeof(templateOptions.URL)=='string' )
         jQuery('#containerContent_'+templateOptions.id).load(templateOptions.URL);
      else if ( typeof(templateOptions.URL)=='object' )
         jQuery('#containerContent_'+templateOptions.id).load(templateOptions.URL.URL, (typeof(templateOptions.URL.parameters)=='object'?templateOptions.URL.parameters:null), (typeof(templateOptions.URL.callback)=='function'?templateOptions.URL.callback:null));
   }
};

})(jQuery);
