//open popups
(function($){
	$.fn.thispopup = function(options){
		var defaults = {
			width:960,
			height:780,
			link: '',
			name: 'newwindow'
		}
		var settings = $.extend({}, defaults, options);
		$(this).click(function(){
			var _link = (settings.link.length > 0) ? settings.link : $(this).attr('href');
			var pwindow = window.open(_link, settings.name,  "location=no, scrollbars=yes, resizable=yes, width=" + settings.width + ", height=" + settings.height);
			if (!pwindow.opener) pwindow.opener = self;
			if (window.focus) {pwindow.focus()}
			return false;
		});
	};
})(jQuery);

//open popups
(function($){
	$.fn.newtab = function(){
		 $(this).live("click",  function(){
            var string =  this.href;
            window.open(string);
            return false;
          });
	};
})(jQuery);
//================================================

//Ajax Queue Manager
(function($) {

    $.tAjax = {
        queue: [],
        now: {
            inAction:false,
            inQueue: 0
        },
        next: 0,
        add: function(obj){
            this.params = obj;
            this.addQueue = function(){
                $.tAjax.queue.push(this.readyObj);
                $.tAjax.queue.sort(this.sort);
            };
            this.readyObj = {
                queue: this.params.queue,
                name: this.params.name,
                avars: {
                    beforeSend: function(){},
                    url: this.params.url,
                    success: this.params.success,
                    error: this.params.error || function(){return true;},
                    dataType: this.params.dataType,
                    complete: function(){}
                }
            };
            this.sort = function(a,b){
                x = a.queue;
                y = b.queue;
                return (x > y);
            };
        },
        preDo: function(){
            this.inLoop = $.tAjax.queue.length;
            this.runNow = $.tAjax.next;
            if(this.runNow == this.inLoop){
                return false;
            } else {
                this.aCnf = $.tAjax.queue[this.runNow].avars;
                this.aCnf.beforeSend = function(){
                    $.tAjax.now.inAction=true; inQueue=this.runNow;
                    $.tAjax.now.inQueue=this.runNow;
                };
                this.aCnf.complete = function(){
                    $.tAjax.now.inAction = false;
                    $.tAjax.now.inQueue = this.runNow;
                    $.tAjax.next++;
                    $.tAjax.preDo();
                };
                $.tAjax.Do(this.aCnf);
            }
        },
        Do: function(aParams){
            this.GOGO = new $.tAjax.aTpl(aParams);
            this.GOGO.init();
        },
        aTpl: function(obj){
            this.aP = obj;
            this.init = function(){
                $.ajax(this.aP);
            };
        }
  };
})(jQuery);
//================================================