function fb_connect_invite_friends(options) {

  if ( typeof options != 'object' ) {options = {}}
  if ( options.title == undefined ) {options.title = "Invite your friends"}
  if ( options.type == undefined ) {options.type = window.location.hostname}
  if ( options.all_friends_invited == undefined ) {options.all_friends_invited = "<div style='padding: 10px; font-size: 1.2em;'>You've already invited all of your friends and they've accepted.</div>"}
  if ( options.invitation_copy == undefined ) {options.invitation_copy = ""}
  if ( options.invitation_choice_url == undefined ) {options.invitation_choice_url = window.location.protocol + '//' + window.location.host + '/'}
  if ( options.invitation_choice_label == undefined ) {options.invitation_choice_label = 'Accept'}
  if ( options.request_action_url == undefined ) {options.request_action_url = window.location.href}
  if ( options.request_action_text == undefined ) {options.request_action_text = options.title}
  if ( options.friend_selector_rows == undefined ) {options.friend_selector_rows = 3}
  if ( options.friend_selector_email_invite == undefined ) {options.friend_selector_email_invite = 'true'}
  if ( options.friend_selector_bypass == undefined ) {options.friend_selector_bypass = 'cancel'}
  if ( isNaN(options.width) ) {options.width = 600}
  if ( isNaN(options.height) ) {options.height = 510}

  var api = FB.Facebook.apiClient
  var sequencer = new FB.BatchSequencer()
  var friends = api.friends_get(null, sequencer)
  var friends_app_users = api.friends_getAppUsers(sequencer)

  sequencer.execute(function() {

    var friend_ids = ''
    try {
      friend_ids = friends.result.sort().join(',')
    }catch(e) {;}

    var exclude_ids = ''
    try {
      exclude_ids = friends_app_users.result.sort().join(',')
    }catch(e) {;}

    var dialog = new FB.UI.FBMLPopupDialog(options.title, '')

    if ( friend_ids.length > 0 && exclude_ids.length > 0 && friend_ids == exclude_ids ) {
      var fbml = ''
      fbml += '<fb:fbml>'
      fbml += options.all_friends_invited
      fbml += '</fb:fbml>'

      dialog.setFBMLContent(fbml)
      dialog.setContentWidth(300)
      dialog.setContentHeight(70)
    }else {
      var content = ''
      content += options.invitation_copy
      content += "<fb:req-choice url='" + options.invitation_choice_url + "' label='" + options.invitation_choice_label + "' />"

      var fbml = ''
      fbml += '<fb:fbml>'
      fbml += '<fb:request-form type="' + options.type + '" content="' + content + '" invite="true" action="' + options.request_action_url + '" method="post">'
      fbml += '<fb:multi-friend-selector'
      fbml += ' actiontext="' + options.request_action_text + '" '
      fbml += ' showborder="true" '
      fbml += ' rows="' + options.friend_selector_rows + '" '
      fbml += ' exclude_ids="' + exclude_ids + '" '
      fbml += ' bypass="' + options.friend_selector_bypass + '" '
      fbml += ' email_invite="' + options.friend_selector_email_invite + '" '
      fbml += '/>'
      fbml += '</fb:request-form>'
      fbml += '</fb:fbml>'

      dialog.setFBMLContent(fbml)
      dialog.setContentWidth(options.width)
      dialog.setContentHeight(options.height)
    }
    dialog.show()
  })


}
  function show_comment_in_approporiate_slot(new_comment_id,new_comment_parent_id) {
    holder_id = (new_comment_parent_id==0 ? "#preview_comment" : ("#comment_holder_"+new_comment_parent_id)  )
    $("#comment_holder_"+new_comment_id).insertAfter(holder_id);
  }
  function show_answer_in_approporiate_slot(new_comment_id,new_comment_parent_id,type) {
    holder_id = (new_comment_parent_id==0 ? "#"+type+"_preview_comment" : ("#comment_holder_"+new_comment_parent_id)  )
    $("#comment_holder_"+new_comment_id).insertAfter(holder_id);
  }
  function show_wysiwyg_editors(event,overlay_name) {
    $("#"+overlay_name+"_textarea_html").css('display','block');
  }

  function hide_wysiwyg_editors(event,overlay_name) {
      //alert(overlay_name);
      //alert(document.getElementById(overlay_name+"_textarea_html")==null)
    
    $("#"+overlay_name+"_textarea_html").css('display','none');
    $("#new_comment_textarea_html").css('display','none');
    //alert($("#"+overlay_name+"_textarea_html").css('display'));
  }

  function retain_wysiwyg_editor(name) {
      $("#"+name).css('display','block');
  }
  function change_user_settings_submit_type(form_type,return_type) {
    $("#return_type_"+form_type).val(return_type);
  }

function cleanup_comment_box(comment_box_id) {
    $("#"+comment_box_id+"_errors").html('');
    $("#"+comment_box_id+"_errors").hide();
    $("#"+comment_box_id+" textarea").val('')
    $("#"+comment_box_id+" input[type='text']").val('')
  }

  function calculate_monthly() {
    if($('#annual_amount').val() == null) {
      alert("You must enter an annual amount for us to calculate your monthly amount");
    } else {
      var monthly = parseInt(Math.round((($('#annual_amount').val()*0.8)/12)*100)/100);
      if(isNaN(monthly)) {
        alert("You must enter a valid annual amount for us to calculate your monthly amount");
        $('#monthly_amount').val(0);
        $('#annual_amount').val(0);
      }
      else {
        $('#monthly_amount').val(monthly);
      }
    }
  }

   function change_tab_content(li) {
     var menu_bar = $(li).parent('ul');
     var menu_items = $(menu_bar).children('li');
     $(menu_bar).children('li').attr('class','dashboard_menu_item');
     $(li).attr('class','dashboard_menu_item active');
     current_selection_index = -1;
     for(var i=0; i<menu_items.length;i++) {
       if(menu_items[i] == li) {
         current_selection_index = i;
         break;
       }
     }
     if(current_selection_index==-1) return;

     $('.'+$(menu_bar).attr('id')+'_body').hide();
     $($('.'+$(menu_bar).attr('id')+'_body')[current_selection_index]).show();

     return false;
   }

jQuery(document).ready(function($){
    /*/ BEGIN: JS-Version of Menubar

        $('li.dropdown > a')
                .mouseover( function(){
                        $('.sub').hide();
                        $('.navigation a' ).removeClass('hover');

                        $( this ).parent().find('.sub').show();
                        $( this ).parent().find('a:eq(0)').addClass('hover');
                });
        $('div.navigation').bind('mouseleave', function(){
                        $('.sub').hide();
                        $('.navigation a' ).removeClass('hover');
      $('.navigation a.active').addClass('hover');
      $('.navigation a.active').parent().find('.sub').show();
                });
    // END: JS-Version of Menubar*/
        
  function sort_links(){
    $('.suggestion_sort_links a').each(function(){
      var active_tab = $('.primary_block_tabs .primary_block_tab.active').attr('id');
      var href = $(this).attr('href').replace(/tab_id=(.*)/, 'tab_id=');
      $(this).attr('href', href+active_tab);
    });
  }
  sort_links();
  
  $('.tabbed_list li a').click(function(){ 
    $('.tabbed_list li a.active').removeClass('active');
    $('.tabbed_list li.active').removeClass('active');
    $('.primary_block_tabs .primary_block_tab').removeClass('active');
    tab = $(this).attr('id').replace('label', 'tab');
    $('#'+tab).addClass('active');
    $(this).addClass('active');
    $(this).parent().addClass('active');
    sort_links();
  });


  $('#rating_button').hover(
    function(){$('.rating_container').show();},
    function(){$('.rating_container').hide();}
  )
	
	var i=0;
	$('#slides-controls a').each( function(){
		this._index = i;
		i++;
	})
	
	$('#slides-controls a').click( function(){
		var index = this._index;
		
		$('#slides a').hide();
		$('#slides a:eq('+index+')').fadeIn();
		
		$('#slides-controls a').removeClass('current');
		$( this ).addClass('current');
		return false;
	});
	
	var cache = ['slide1.jpg', 'slide2.jpg', 'slide3.jpg', 'slide4.jpg'];
	var path = '/images/';
	for( var i=0; i<cache.length; i++ ) {
		var img = new Image();
		img.src = path + cache[i];
	}

    /*// Revised Top Menu Nav Starts
    $(".revised-dropdown").mouseover(function(){
        $(".sub").hide();
        $(this).find(".sub").show();
    });
    $(".revised-dropdown").mouseout(function(){
        $(this).find(".sub").hide();
        $('.main_menu a.active').parent().find('.sub').show();
    });
    // Revised Top Menu Nav Starts*/

    // Magnify glass button of search -- STARTS
    $('#magnified_search_button').bind('click', function(){
        $( this ).parent().parent('form').submit();;
    });
    // Magnify glass button of search -- ENDS

    // For extended navigation(second level) -- starts
   /* $('.sub ul li').mouseover(function(){
        if($(this).attr('class') != 'active'){
            $('.sub ul li.active').addClass('normal');
        }
    });
    $('.sub ul li').mouseout(function(){
        $('.sub ul li').removeClass('normal');
    });*/
    // For extended navigation(second level) -- ends
})
