var is_wvv = false;
var wvv_modified = false;
var submitted = false;

(function($) {

  var trailing_whitespace = true;

  $.fn.truncate = function(options) {

    var opts = $.extend({}, $.fn.truncate.defaults, options);
    
    $(this).each(function() {

      var content_length = $.trim(squeeze($(this).text())).length;
      
      if (content_length <= opts.max_length) {
      	var textNotTruncated = true;
      	if (!opts.extra) {
	        return; 
      	}
      }
 			// bail early if not overlong

      var actual_max_length = opts.max_length - opts.more.length - 3;  // 3 for " ()"
      var truncated_node = recursivelyTruncate(this, actual_max_length);
      var full_node = $(this).hide();

      truncated_node.insertAfter(full_node);
      
      findNodeForMore(truncated_node).append('<span class="read-more">...<br /><a href="#show more content">+ '+opts.more+'</a></span>');
      findNodeForLess(full_node).append('<br /><a href="#show less content">'+opts.less+'</a>');
      
      truncated_node.find('a:last').click(function() {
        if (!textNotTruncated) { truncated_node.slideUp(); full_node.slideDown(); }
        if (opts.extra == true) {
        	full_node.parent().find('.extra').slideDown('fast');
        	full_node.parent().find('.read-more').hide();
        }
        return false;
      });
      full_node.find('a:last').click(function() {
        if (!textNotTruncated) { truncated_node.slideDown(); full_node.slideUp(); }
        if (opts.extra == true) {
        	full_node.parent().find('.extra').slideUp('fast');
        	full_node.parent().find('.read-more').slideDown('fast');
        	
        }        
        return false;
      });

    });
  }

  $.fn.truncate.defaults = {
    max_length: 100,
    more: '- More',
    less: '- Less',
    extra: false
  };

  function recursivelyTruncate(node, max_length) {
    return (node.nodeType == 3) ? truncateText(node, max_length) : truncateNode(node, max_length);
  }

  function truncateNode(node, max_length) {
    var node = $(node);
    var new_node = node.clone().empty();
    var truncatedChild;
    node.contents().each(function() {
      var remaining_length = max_length - new_node.text().length;
      if (remaining_length == 0) return;  // breaks the loop
      truncatedChild = recursivelyTruncate(this, remaining_length);
      if (truncatedChild) new_node.append(truncatedChild);
    });
    return new_node;
  }

  function truncateText(node, max_length) {
    var text = squeeze(node.data);
    if (trailing_whitespace)  // remove initial whitespace if last text
      text = text.replace(/^ /, '');  // node had trailing whitespace.
    trailing_whitespace = !!text.match(/ $/);
    var text = text.slice(0, max_length);
    // Ensure HTML entities are encoded
    // http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb
    text = $('<div/>').text(text).html();
    return text;
  }

  // Collapses a sequence of whitespace into a single space.
  function squeeze(string) {
    return string.replace(/\s+/g, ' ');
  }
  
  // Finds the last, innermost block-level element
  function findNodeForMore(node) {
    var $node = $(node);
    var last_child = $node.children(":last");
    if (!last_child) return node;
    var display = last_child.css('display');
    if (!display || display=='inline') return $node;
    return findNodeForMore(last_child);
  };

  // Finds the last child if it's a p; otherwise the parent
  function findNodeForLess(node) {
    var $node = $(node);
    var last_child = $node.children(":last");
    if (last_child && last_child.is('p')) return last_child;
    return node;
  };

})(jQuery);

function setNextCategory( currCategory ) {
  var $categories = new Array();
  $('.edit-submenu li a').each(function(index){
    $categories.push( $(this).attr('category') );
  });
  var len = $categories.length;
  for( var i=0; i < len; i++ ) {
    if ( currCategory == $categories[i] ) {

      if ( i + 2 >= len ) {
        $('#edit-form-submit').attr( 'value', 'Save Changes' );
      }
      if ( i + 1 == len ) {
        $next_category = $categories[i];
      } else {
        $next_category = $categories[i+1];
      }
    }
  }
  if ( $next_category != '' ) {
    $('#show_category').attr('value', $next_category );
  }
}

function wvvModified(fieldName) {
  if ( ! is_wvv || fieldName == 'Education Information' ) {
    return true;
  }
  alert('Modifying this field will affect your current WealthVisor Verified status');
  if ( $('input[name$="wvv_modified"]').length == 0 ) {
    $('<input>').attr({
      type: 'hidden',
      id: 'wvv_modified',
      name: 'wvv_modified',
      value: '1'
    }).appendTo('#professional_edit_form');
  }
  wvv_modified = true;
}

function submitProEditForm() {
  if ( submitted == true ) {
    return true;
  }
  var submitted = true;
  var submit = true;
  $('#photo-upload-wait').show();
  if ( is_wvv && wvv_modified ) {
    submit = confirm('You have altered data affecting your WealthVisor Verified status.  To proceed, click OK, otherwise click Cancel to revert your changes' );
  }
  if ( submit ) {
    $('#professional_edit_form').submit();
    return true;
  } else {
    document.location.href = '/edit';
    return false;
  }
}

function previewPhoto() {
  $('#show_category').attr( 'value', 'profile-photo' );
  $('#edit-form-submit').attr( 'value', 'Upload Photo' );
}

function deletePhoto() {
  $('#show_category').attr( 'value', 'profile-photo' );
  $('#show_category').after('<input type="hidden" name="delete_photo" value="true" />');
}

function trackClick( type, id ) {
  var tsTimeStamp= new Date().getTime();
  jQuery.get( '/e?event=' + type + '&id=' + id + '&ts=' + tsTimeStamp )
}

$(document).ready(function() {
	var viewportWidth = $(window).width();
	var viewportHeight = $(window).height();	
	var documentHeight = $(document).height();
// Clear form fields on focus
  $('.clearme').focus(function() {
    $(this).val("");
  });

// Login Slider
	//Expand Panel
	$(".login-open").click(function(){
		$("div#panel").slideDown("fast");
	});	
	
	// Collapse Panel
	$(".login-close").click(function(){
		$("div#panel").slideUp("fast");	
	});		
					
// Toggle refine options

	$("li.refine a").click(function () {
      $(this).toggleClass("select-active");
   });
   
   var $hidden = $('.hidden');
   var $expand = $('.expand');
	 var $contract = $('.contract');
	 	
	$expand.click(function() {
		$(this).slideUp(200, function() {	
			$(this).parent().find('.hidden').slideDown();
		});
		return false;
	});
	
	$contract.click(function() {
		$(this).parent().slideUp(200, function() {
			$(this).parent().find('.expand').slideDown(200);
		
		})
	})
	
	$('.read-more').click(function() {
		$(this).hide();
		$(this).parent().find('.hidden-text').slideDown();
		return false;
	})
	
	$('.truncate').each(function() {
		var more = $(this).attr('more');
		var length = $(this).attr('length');
		var extra = $(this).attr('extra') ? true : false;
		$(this).truncate({
			max_length: length, 
			more: more,
			extra: extra
		});	
	});

	var $content = $('#content');
	var $editsubmenu = $('.edit-submenu li a');
    var $categories = $content.find('[category]');
	  $editsubmenu.click(function() {
		$editsubmenu.removeClass('selected');
		$(this).addClass('selected');
		var category = $(this).attr('category');
		//$('#welcome').fadeOut(); //we don't need the welcome all the time.
	
        setNextCategory(category);    
		$('form').children().hide();
		$('#content [category='+category+']').fadeIn();
		$('#submitter').fadeIn();
        $('#page').attr( 'value', category );    
		return false;
	})
	var $incomplete = $('#incomplete-sections li a')
    $incomplete.click(function() {
		$editsubmenu.removeClass('selected');
		var category = $(this).attr('category');
        $('.edit-submenu li a[category='  + category + ']').addClass('selected')
        /*$('.edit-submenu li a').each(function(index){
          if ( $(this).attr('category') == category ) {
            $(this).addClass('selected');
          }
        });*/
		//$('#welcome').fadeOut(); //we don't need the welcome all the time.
	
        setNextCategory(category);    
		$('form').children().hide();
		$('#content [category='+category+']').fadeIn();
		$('#submitter').fadeIn();
        $('#page').attr( 'value', category );    
		return false;
	})

      
});



/// popupWindow /// added 7-5-2011 /// used for social sharing popup windows
(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:1, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){
						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);

// set .SocialPop links to popup...
$(document).ready(function() {
	$('.SocialPop').popupWindow({ 
		centerScreen:1,
		width:700,
		height:600
	}); 
});
/// END popupWindow ///




/// "Was this questions helpful" YES/NO ///
/// used on:
/// profile/answers.html.erb,
/// profile/view_profile.html.erb,
/// questions/view_question.hrml.erb
var Vote = function() {
  return {
    UPVOTE   : 'up',
    DOWNVOTE : 'down',
    vote     : function( id, direction ) {
      id        = new String(id);
      var cname = id + '-vote';

      if ( ! $.cookie(cname) ) 
        $.ajax(
          {
            url      : '/vote/answer/' + direction + '/' + id,
            cache    : false,
            complete : function() {
              $.cookie( cname, direction )
              $('div#' + id + '-vote')
                .html('')
                .append(
                  $('<div></div>')
                    .html('Thank you for your feedback')
                  )
              ;
            }
          }
        );
    }
  };
}();
/// END "Was this questions helpful"




/*
 * TipTip
 // UPDATED FOR WealthVisor.com (7/29/2011):
 // defaults changed
 // "org_elem.attr('class')" added to tiptip_holder for different tooltip styling based on class
 * Copyright 2010 Drew Wilson
 * www.drewwilson.com
 * code.drewwilson.com/entry/tiptip-jquery-plugin
 *
 * Version 1.3   -   Updated: Mar. 23, 2010
 *
 * This Plug-In will create a custom tooltip to replace the default
 * browser tooltip. It is extremely lightweight and very smart in
 * that it detects the edges of the browser window and will make sure
 * the tooltip stays within the current window size. As a result the
 * tooltip will adjust itself to be displayed above, below, to the left 
 * or to the right depending on what is necessary to stay within the
 * browser window. It is completely customizable as well via CSS.
 *
 * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($){
	$.fn.tipTip = function(options) {
		var defaults = {
			activation: "hover",
			keepAlive: false,
			maxWidth: "250px",
			edgeOffset: 8,
			defaultPosition: "top",
			delay: 20,
			fadeIn: 20,
			fadeOut: 20,
			attribute: "title",
			content: false, // HTML or String to fill TipTIp with
		  	enter: function(){},
		  	exit: function(){}
	  	};
	 	var opts = $.extend(defaults, options);

	 	// Setup tip tip elements and render them to the DOM
	 	if($("#tiptip_holder").length <= 0){
	 		var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
			var tiptip_content = $('<div id="tiptip_content"></div>');
			var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
			$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
		} else {
			var tiptip_holder = $("#tiptip_holder");
			var tiptip_content = $("#tiptip_content");
			var tiptip_arrow = $("#tiptip_arrow");
		}

		return this.each(function(){
			var org_elem = $(this);
			if(opts.content){
				var org_title = opts.content;
			} else {
				var org_title = org_elem.attr(opts.attribute);
			}
			if(org_title != ""){
				if(!opts.content){
					org_elem.removeAttr(opts.attribute); //remove original Attribute
				}
				var timeout = false;

				if(opts.activation == "hover"){
					org_elem.hover(function(){
						active_tiptip();
					}, function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				} else if(opts.activation == "focus"){
					org_elem.focus(function(){
						active_tiptip();
					}).blur(function(){
						deactive_tiptip();
					});
				} else if(opts.activation == "click"){
					org_elem.click(function(){
						active_tiptip();
						return false;
					}).hover(function(){},function(){
						if(!opts.keepAlive){
							deactive_tiptip();
						}
					});
					if(opts.keepAlive){
						tiptip_holder.hover(function(){}, function(){
							deactive_tiptip();
						});
					}
				}

				function active_tiptip(){
					opts.enter.call(this);
					tiptip_content.html(org_title);
					tiptip_holder.hide().removeAttr("class").css("margin","0");
					tiptip_arrow.removeAttr("style");

					var top = parseInt(org_elem.offset()['top']);
					var left = parseInt(org_elem.offset()['left']);
					var org_width = parseInt(org_elem.outerWidth());
					var org_height = parseInt(org_elem.outerHeight());
					var tip_w = tiptip_holder.outerWidth();
					var tip_h = tiptip_holder.outerHeight();
					var w_compare = Math.round((org_width - tip_w) / 2);
					var h_compare = Math.round((org_height - tip_h) / 2);
					var marg_left = Math.round(left + w_compare);
					var marg_top = Math.round(top + org_height + opts.edgeOffset);
					var t_class = "";
					var arrow_top = "";
					var arrow_left = Math.round(tip_w - 12) / 2;

                    if(opts.defaultPosition == "bottom"){
                    	t_class = "_bottom";
                   	} else if(opts.defaultPosition == "top"){ 
                   		t_class = "_top";
                   	} else if(opts.defaultPosition == "left"){
                   		t_class = "_left";
                   	} else if(opts.defaultPosition == "right"){
                   		t_class = "_right";
                   	}

					var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
					var left_compare = (tip_w + left) > parseInt($(window).width());

					if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){
						t_class = "_right";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left = -12;
						marg_left = Math.round(left + org_width + opts.edgeOffset);
						marg_top = Math.round(top + h_compare);
					} else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)){
						t_class = "_left";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left =  Math.round(tip_w);
						marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
						marg_top = Math.round(top + h_compare);
					}

					var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
					var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;

					if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_top";
						} else {
							t_class = t_class+"_top";
						}
						arrow_top = tip_h;
						marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
					} else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)){
						if(t_class == "_top" || t_class == "_bottom"){
							t_class = "_bottom";
						} else {
							t_class = t_class+"_bottom";
						}
						arrow_top = -12;						
						marg_top = Math.round(top + org_height + opts.edgeOffset);
					}

					if(t_class == "_right_top" || t_class == "_left_top"){
						marg_top = marg_top + 5;
					} else if(t_class == "_right_bottom" || t_class == "_left_bottom"){		
						marg_top = marg_top - 5;
					}
					if(t_class == "_left_top" || t_class == "_left_bottom"){	
						marg_left = marg_left + 5;
					}
					tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"});
					tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class+" "+org_elem.attr('class'));

					if (timeout){ clearTimeout(timeout); }
					timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay);	
				}

				function deactive_tiptip(){
					opts.exit.call(this);
					if (timeout){ clearTimeout(timeout); }
					tiptip_holder.fadeOut(opts.fadeOut);
				}
			}				
		});
	}
})(jQuery);
/* end TipTip */



/* // Account Settings Tab // */
function qaToggle() {
	//show/hide edit options
	$('div.QAsettings-wrap input').toggle();
	$('li.unchecked').toggle();
	$('li.edit').toggle();
}
function emailToggle() {
	$('form#change-email-form div').toggle();
	$('form#change-email-form a').toggle();
}
function passwordToggle () {
	$('form#change-password-form div').toggle();
	$('form#change-password-form a').toggle();
}
/* end Accoung Settings Tab JS */


/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqModal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * $Version: 03/01/2009 +r14
 */
(function($) {
  $.fn.jqm=function(o){
	
  	var p={
			overlay: 50,
			overlayClass: 'jqmOverlay',
			closeClass: 'jqmClose',
			trigger: '.jqModal',
			ajax: F,
			ajaxText: '',
			target: F,
			modal: F,
			toTop: F,
			onShow: F,
			onHide: F,
			onLoad: F
		};
		
		return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
		H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
		//fixes IE7 z-indexing issues
		$('body').append($(this));
		if(p.trigger)$(this).jqmAddTrigger(p.trigger);
		});};

		$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
		$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
		$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
		$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

		$.jqm = {
			hash:{},
			open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 			if(c.modal) {if(!A[0])L('bind');A.push(s);}
 			else if(c.overlay > 0)h.w.jqmAddClose(o);
 			else o=F;

 			h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 			if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 			if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  		r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 			else if(cc)h.w.jqmAddClose($(cc,h.w));

 			if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 			(c.onShow)?c.onShow(h):h.w.show();e(h);return F;
		},
		close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 			if(A[0]){A.pop();if(!A[0])L('unbind');}
 			if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 			if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
		},
		params:{}};
		var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
		i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
		e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
		f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
		L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
		m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
		hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 			if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery);


//"Limit": limit text area characters
(function($){ 
     $.fn.extend({  
         limit: function(limit,element) {
			
			var interval, f;
			var self = $(this);
					
			$(this).focus(function(){
				interval = window.setInterval(substring,100);
			});
			
			$(this).blur(function(){
				clearInterval(interval);
				substring();
			});
			
			substringFunction = "function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}";
			if(typeof element != 'undefined')
				substringFunction += "if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0 characters remaining':limit-length+' characters remaining');}"
				
			substringFunction += "}";
			
			eval(substringFunction);
			
			substring();
			
        } 
    }); 
})(jQuery);
//end


// search bar drop down toggle
$(document).ready(function(){
  $(".ul-click").click(function(){
	  $(".ul-drop").show()
    })
  $(".ul-drop").mouseout(function(){
	  $(this).hide()
	}).mouseover(function(){
	  $(this).show()
  })
  $(".li-questions").click(function(){
	  $(".li-click-txt").html("Questions")
	  $(".ul-drop").hide()
	  $(".q-arrow").show()
	  $("#index-question-form").show()
	  $("#index-pro-form").hide()
  })
  $(".li-experts").click(function(){
	  $(".li-click-txt").html("Experts")
	  $(".ul-drop").hide()
	  $(".q-arrow").hide()
	  $("#index-question-form").hide()
	  $("#index-pro-form").show()
  })
})

