/**
 * (c) Copyright 2006 ActiveSpotLight, Active8Media, LLC
 */

function quick_jump(target,selObj,restore)
{
	var override = false;
	if(target=='external')
	{
		var url = selObj;
		override = true;
	}
	else
	{
		var url = selObj.options[selObj.selectedIndex].value;
	}
	if (url)
	{
		// Automatically push full path links into new windows
		if(url.indexOf('http') != -1) target = 'window.open()';
		// Assume all local links have .html, .php, or news extensions
		if(target=='parent' &&  url.indexOf('htm') == -1 && url.indexOf('php') && url.indexOf('news') == -1)
		{
			// Probably not valid
		}
		else
		{
			// temp override
			if(target.indexOf('window') != -1)
			{
				var xlm = popupsize(.85);
				if(xlm.width)
				{
					if(override==false)
					{
						container(selObj.options[selObj.selectedIndex].value,'navWin','width='+
						xlm.width+',height='+xlm.height+',scrollbars=1,resizeable=1,'+
						'toolbar=0,menubar=0,status=1,location=1,copyhistory=1');
					}
					else
					{
                                                container(selObj,'navWin','width='+
                                                xlm.width+',height='+xlm.height+',scrollbars=1,resizeable=1,'+
                                                'toolbar=0,menubar=0,status=1,location=1,copyhistory=1');
					}
				}
			}
			else
			{
				if(override==false)
					eval(target+".location='"+selObj.options[selObj.selectedIndex].value+"'");
				else
					eval(target+".location='"+selObj+"'");
			}
		}
	}

	if (restore) selObj.selectedIndex=0;
}

function legal(page) 
{
        var locate = window.open(page,
	             'legal','left=20,top=20,width=480,height=520,toolbar=0,'+
	             'location=0,status=0,menubar=0,resizable=1,scrollbars=yes');
}

function container(url,name,params)
{
	window.open(url,name,params);
}

function popupsize(percent)
{
	var percent = (percent)?percent:.85;
	var width = parseInt(screen.width * percent);
	var height= parseInt(screen.height* percent);
	if(width<800) width = 800;
	if(height<600) width = 600;
	return { width : width, height : height };
}

jQuery(function(){
	jQuery('a.print').click(function(){
		window.print();
		return false;
	});
	jQuery('a.legal').click(function(){
		legal(jQuery(this).attr('href'));
		return false;
	});
	jQuery('a.external').click(function(){
		quick_jump('external',jQuery(this).attr('href'),1);
		return false;
	});
	jQuery('.container').click(function(){
		var dim = popupsize(.85);
		if(dim.width)
		{
			container(jQuery(this).attr('href'),'DemoWin','width='+
			dim.width+',height='+dim.height+',scrollbars=1,resizeable=1,'+
			'toolbar=0,menubar=0,status=1,location=1,copyhistory=1');
			return false;
		}
	});
	jQuery('select.ql').change(function(){
		quick_jump('parent',this,1);
		return false;
	});
});

/* Limit Queue Plugin */


/**
 * @author Abdur-Rahman Advany
 */

jQuery.fn.extend({
	queue: function(type,fn){
		if ( !fn ) {
			fn = type;
			type = "fx";
		}
	
		return this.each(function(){
			if ( !this.queue )
				this.queue = {};
				
			if ( !this.limitQueue )
				this.limitQueue = {};
	
			if ( !this.queue[type] )
				this.queue[type] = [];
				
			if ( !jQuery.queue )
				jQuery.queue = {};
	
			if (!this.limitQueue[type] || this.queue[type].length < this.limitQueue[type])
				if (!this.scope)
					this.queue[type].push( fn );
			
			if (this.scope){
				if ( !jQuery.scope[this.scope] )
					jQuery.scope[this.scope] = [];
					
				if (!this.limitQueue[type] || jQuery.scope[this.scope].length < this.limitQueue[type])
					jQuery.scope[this.scope].push( new Array(this, fn) );
			}
							
			if ( this.scope && jQuery.scope[this.scope].length == 1 || this.queue[type].length == 1 )
				fn.apply(this);
		});
	},
	/**
	 * limit the amount of active queue items in a queue
	 *
	 * @example $("div").slideUp().limitQueue(1); // will not repeat slideUp until its done
	 *
	 * @name limitQueue
	 * @type jQuery.fn
	 * @param String to be used to match the queue type
	 * @param Integer to be used to specify the limit of queue
	 * @cat queue
	 */
	limitQueue: function(type, limit){
		if ( !limit ) {
			limit = type;
			type = 'fx';
		}
		
		return this.each(function(){
			if ( !this.limitQueue )
				this.limitQueue = {};
			
			this.limitQueue[type] = limit;
		});
	},
	scope: function(name){
		if ( !jQuery.scope )
			jQuery.scope = {};
				
		if ( !jQuery.scope[name] )
			jQuery.scope[name] = [];
		
		return this.each(function(){
			if ( !this.scope )
				this.scope = name;
		});
	}
});

jQuery.extend({
	limitQueue: {},
	scope: {},
	dequeue: function(elem,type){
		type = type || "fx";
		
		if ( !elem.scope && elem.queue && elem.queue[type]) {
			// Remove self
			elem.queue[type].shift();
	
			// Get next function
			var f = elem.queue[type][0];
		
			if ( f ) f.apply( elem );
		} else {
			// Remove self
			jQuery.scope[elem.scope].shift();
			
			if ( jQuery.scope[elem.scope][0] ){
				var elem_this = jQuery.scope[elem.scope][0][0];
				var f = jQuery.scope[elem.scope][0][1];
			}
			
			if ( f ) f.apply( elem_this );
		}
	}
});

