/* 
	JQuery Externalify 0.2
	by Aaron Lozier (lozieraj-[at]-gmail.com) (Twitter: @ajlozier)
	version 0.2
		* "confirm function" and "before leave" function added
	
	* Binds a click event to all anchor tags passed to it which evaluates whether or not the href is a part of the current domain or not.
	* If it is, returns true and click is treated normally.
	* If not, location is opened in a new window.
	* No options at this time.
	* Wishlist: New window parameters and/or ability to create custom callbacks.
		
	Project Page:	
		* http://informationarchitech.com/externalify/
		
	Dependencies:
		* jQuery 1.2.x
 
	Basic Usage:
	
	$('a').externalify();
*/

(function(jQuery){
 jQuery.fn.externalify = function(options) {
    
	var defaults = {
		addClass: 'external',							//add class
		addRel: 'external',								//add rel parameter
		confirmFunction: true,
		beforeLeave: true,
		openNewWindow: true
	};
  
	var options = jQuery.extend(defaults, options);
	
	return this.each(function() {
	
		obj = jQuery(this);
		if(is_external(obj.attr('href'))){

			obj.click(function(){
				var thisEl = jQuery(this);	
				
				if(typeof(options.confirmFunction)=='function'){
					var confirm = options.confirmFunction( thisEl.attr('href') );
					//var confirm = options.confirmFunction();
				} else {
					var confirm = options.confirmFunction;
				}
				
				if(confirm){
					
					if(typeof(options.beforeLeave)=='function'){
						var beforeLeave = options.beforeLeave();
					} else {
						var beforeLeave = options.beforeLeave;
					}
					
					if(beforeLeave){
						
						if(options.openNewWindow){
							window.open(thisEl.attr('href'));
							return false;			
						} else {
							return true;
						}
					} else {
						return false;
					}
				} else {
					return false;
				}
				
			});
			
			if(options.addClass){
				obj.addClass(options.addClass);
			}
			
			if(options.addRel){
				obj.attr('rel',options.addRel);
			}
		}
		
		/* PARSING FUNCTIONS */
		
		function isolate_site(the_url){		
			try{	
			  	if(the_url) {
				var first_split = the_url.split("//");
				if(first_split[1] == undefined) {
					return false;
				}				
				var without_resource = first_split[1];
				var second_split = without_resource.split("/");
				var the_site = second_split[0];
				return the_site;
				}
			} catch(e) {
				return false;
			}
		}
		
		function isolate_domain(the_site){
			var num_parts = the_site.split(".").length;
			var parts = the_site.split(".");
			if(num_parts > 1){
				the_domain = parts[num_parts-2] + '.' + parts[num_parts-1];
			}
			return the_domain;	
		}	
		
		function is_external(the_url){							
			the_site = isolate_site(the_url);
			if(the_site){
				the_site_domain = isolate_domain(the_site);
				this_domain = isolate_domain(document.domain);
				if(the_site_domain != this_domain){
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		}	
		
	});
 };
})(jQuery);;
// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
//		jAlert( message, [title, callback] )
//		jConfirm( message, [title, callback] )
//		jPrompt( message, [value, title, callback] )
// 
// History:
//
//		1.00 - Released (29 December 2008)
//
//		1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC. 
//
(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		alert: function(message, title, callback) {
			if( title == null ) title = 'Alert';
			$.alerts._show(title, message, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		//confirm: function(message, title, callback) {
		confirm: function(message, title, callback, options) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', function(result) {
				if( callback ) callback(result, options);
				//if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			if( title == null ) title = 'Prompt';
			$.alerts._show(title, message, value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		// Private methods
		
		_show: function(title, msg, value, type, callback) {
			
			$.alerts._hide();
			$.alerts._overlay('show');
			
			$("BODY").append(
			  '<div id="popup_container">' +
			    '<h1 id="popup_title"></h1>' +
			    '<div id="popup_content">' +
			      '<div id="popup_message"></div>' +
				'</div>' +
			  '</div>');
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			// IE6 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0
			});
			
			$("#popup_title").text(title);
			$("#popup_content").addClass(type);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			switch( type ) {
				case 'alert':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});
					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();


						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
		
		_hide: function() {
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', $.alerts._reposition);
					break;
					case false:
						$(window).unbind('resize', $.alerts._reposition);
					break;
				}
			}
		}
		
	}
	
	// Shortuct functions
	jAlert = function(message, title, callback) {
		$.alerts.alert(message, title, callback);
	}
	
	/*
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
	*/

	jConfirm = function(message, title, callback, options) {
		$.alerts.confirm(message, title, callback, options);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);;
/**
 * @file
 * Provide a gateway for external links.
 */
(function ($) {

  Drupal.behaviors.compliance = {

    attach: function (context, settings) {
      $(':not(a[href*="altastreet"])').externalify({'confirmFunction': Drupal.behaviors.compliance.confirmFunction});
    },

    confirmFunction: function (href) {
      var message, showDisclaimer, title;
      message = Drupal.settings.compliance.message;
      showDisclaimer = Drupal.settings.compliance.showDisclaimer;
      title = Drupal.t('You are about to leave the site.');
      if (showDisclaimer == 1) {
        jConfirm(message, title, function(res, options) { Drupal.behaviors.compliance.jConfirmCallback(res, options); }, {'href': href});
      }
      else {
        window.open(href);
        return false;
      }
    },

    jConfirmCallback: function (res, options) {
      if (res) {
        window.open(options['href']);
        return false;
      }
      else {
        return false;
      }
    }
  }

})(jQuery);
;
/**
 * @file
 * Market Summary AJAX calls
 */

(function($) {

  $(function() {
    if ($('.market-summary-ajax-block').size() > 0) {
      market_summary_ajax_start();
    }
  });

  /**
   * Start Ajax calls
   */
  function market_summary_ajax_start() {
    $.ajax({
      url: Drupal.settings.basePath + 'market_summary/js/0',
      dataType: 'json',
      success: function(data) {
        if (data) {
          for (var i in data) {
            var block_data = data[i];
            for (var j in data[i]) {
              if (block_data[j].current_price == 0) {
                block_data[j].change_amt = 'N/A';
                block_data[j].current_price = 'N/A';
              }
              $('.market-summary-ajax-block #' + j + ' .stock-title').addClass('title-' + block_data[j].change);
              $('.market-summary-ajax-block #' + j + ' .current-price-float').text(block_data[j].current_price);
              $('.market-summary-ajax-block #' + j + ' .change-amt').addClass('value-' + block_data[j].change);
              $('.market-summary-ajax-block #' + j + ' .change-amt-float').text(block_data[j].change_amt);
              $('.market-summary-last-updated').text(block_data[j].last_updated);
            }
          }
        }
      }
    });
  }

})(jQuery);
;
// $Id: jquery.cookie.js,v 1.1.4.1 2010/01/12 15:32:29 attheshow Exp $

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
(function ($) {
  jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
      options = options || {};
      if (value === null) {
        value = '';
        options.expires = -1;
      }
      var expires = '';
      if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
        var date;
        if (typeof options.expires == 'number') {
          date = new Date();
          date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
        } else {
          date = options.expires;
        }
        expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
      }
      // CAUTION: Needed to parenthesize options.path and options.domain
      // in the following expressions, otherwise they evaluate to undefined
      // in the packed version for some reason...
      var path = options.path ? '; path=' + (options.path) : '';
      var domain = options.domain ? '; domain=' + (options.domain) : '';
      var secure = options.secure ? '; secure' : '';
      document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
      var cookieValue = null;
      if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
          var cookie = jQuery.trim(cookies[i]);
          // Does this cookie string begin with the name we want?
          if (cookie.substring(0, name.length + 1) == (name + '=')) {
            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
            break;
          }
        }
      }
      return cookieValue;
    }
  };
})(jQuery);;

