/**
 * CREATE DISCLAIMERS
 * Dependencies:
 * jquery.js
 * extend-native-objects.js
 *-------------------*/
$(function(){
	var path     = window.location.pathname,
		fileExts = ['.jsp', '.php', '.htm', '.html', '.asp', '.aspx'],
		fLength  = fileExts.length,
		isExt    = false;
	
	// check if url has extension
	for (var i=0; i<fLength; ++i) {
		if (path.indexOf(fileExts[i]) === -1) {
			isExt = true;
			break;
		}	
	}
	
	// if no file extension make sure the path has trailing slash
	if (!isExt)
		path = (path.charAt(path.length-1) != "/") ? path + "/" : path;
	
	// append the query string if it exists
	path = path + window.location.search

	// don't run on disclaimers page
	if (path.indexOf('/disclaimers') != -1) return this;
	
	// declare variables
	var sups   = $('sup[title]'),
		uSups  = [], // unique sups
		cnt    = 1,
		i      = 0,
		len    = 0,
		val    = '',
		link   = '',
		target = '';
	
	// get an array that contains the disclaimer names
	sups.each(function(i,j){
		uSups[i] = $(j).attr('title');
	});
	
	// remove dups
	uSups.unique();
	
	if( path.indexOf("success.jsp") > -1 ){
		path = "/app/accountSignup/page/success.jsp";
	}
	
	// create the links that go into the sups
	len = uSups.length;
	for (i=0; i<len; i++) {
		val  = uSups[i]; // ex: barrons
		$('sup[title="'+val+'"]').each(function(k,l){
			target = ($(this).text().trim() == '0') ? 'target="_blank"' : '';
			link   = '<a href="/disclaimers/#'+path+'='+cnt+'" '+target+'>'+cnt+'</a>';
			$(this).html(link);
		});
		
		cnt++;
	}
});

