var myTransition = new Fx.Transition(Fx.Transitions.Elastic, 3);
var myActive = -1;
var pclength = 0;
var pcspeed = 3000;
var box;
var box2;
var mootab = '';
//var nooptime = 60000;
var nooptime = 60000*10; // 60 seconds times 10
window.addEvent('load', function() {
  // noop the session
  window.setTimeout('noop()',nooptime);

  // main nav js 
  // let's see them
  $$('.slider').setStyle('visibility','visible');
  //create our Accordion instance
  var myAccordion = new Accordion($$('.trigger'), $$('.slider'), { alwaysHide: true, show: -1, onActive: function() { myActive = this.previous+1; } });
  //these are hidden to make page load more smooth..er
  $$('.slider').forEach(function(item,i) {
    item.setStyles('visibility','visible');
  });
/*
  //allow mouseover for the Accordion clickable triggers 
  $$('.trigger').forEach(function(item,i) {
    item.addEvent('mouseenter', function() { 
      myAccordion.display(i);
    });
  });
  $$('.slider').forEach(function(item,i) { 
    item.addEvent('mouseout', function() { 
      myCurrent = myAccordion.previous+1;
      if (myActive==myCurrent) {
        myAccordion.display(-1);
        myActive = -1;
      } 
    });
  });
  $$('.trigger').forEach(function(item,i) {
    item.addEvents({'mouseover':function() { myAccordion.display(i); },'mouseout':function() {  }});
  }); 
*/
  // end main nav js

  
  /*  tooltips */
  var Tips1 = new Tips('.creditstip');
  Tips1.addEvent('show', function(tip){
    tip.fade('in');
  });
  Tips1.addEvent('hide', function(tip){
    tip.fade('out');
  });


  /*  sub categories */
  // loop through all links in category_list div
  $$('#category_list a').each(function(item,index) {
    if (item.getProperty('id')) {
      ele_id = item.getProperty('id');
      var id2get = item.getProperty('id').toInt();
      morelink = id2get + "_cat";
      subcat = "subcategory_" + id2get;
    
      // if there is a subcategory div associated with that link run the following functions...
      if ($(subcat)) {
        hideEle($(subcat));
        toggle($(subcat),$(morelink));
      }
    }
  });

  

  /* first time here */
/*
  if($('content_top_note_comment')) {
    toggleClick($('content_top_note_comment'),$('first_time_here'));
    toggleClick($('content_top_note_comment'),$('close_img'));
    hideEle($('content_top_note_comment'));
    slideInEle($('content_top_note_comment'));
  }
*/

  /*  */
  if ( (navigator.platform.indexOf('Mac') > -1) && (navigator.appCodeName == "Mozilla")) {
//    $('end1').setStyle('margin-right', '96px');
//    $('dropDownMenu').setStyle('padding-top', '3px');
//    $('rss-icon-big').setStyle('margin-top', '129px');
  }

  /* smooth scrolling to anchor points */
  new SmoothScroll({ duration: 500 });

  // facebook connect init and update if connected
  FB.init("062acf2aa425a7077b385b08a65641dd", "/xd_receiver.htm", {"ifUserConnected":update_user_box});
//  if ($('login')) alert(FB);
/*
  if ($('login')) FB.Connect.ifUserConnected(update_user_box);
*/

  // set up the polls response stuff
  $$('.pollsubmit').forEach(function(item,id) {
    var formname = item.get('rel');
    var url = '/model/polls/sc//ajax'; // jj ;)
    $(formname).set('send',{
      url: url, method: 'post',
      onComplete: function(response) {
       if ($(formname)) {
          $(formname).set('html',response);
        }
      }
    });
    item.addEvent('click',function() {
      var formname = item.get('rel');
      $(formname).send(); 
    });
  });

  // this causes the recent comments to do...stuff
  window.setTimeout('recent_comments(0)',pcspeed);
  pclength = $$('.pcomments').length; 

  /* multi moo 1.2 */
  box = {};
  box2 = {};
  window.addEvent('domready', function(){
    box = new MultiBox('mb', {useOverlay: true, showControls: false});
    box2 = new MultiBox('mb2', {useOverlay: true, showControls: false, movieWidth:'750', movieHeight:'550'});
  });


	// twitters....
	twitterDiv = 'twitter_update_list';
	$(twitterDiv).set('style','font-size:11px; line-height:15px; ');
	$(twitterDiv).set('html','LOADING: <img src="/images/ajax-loader.gif" alt="Loading Twitter Feed" />');

//	twitterDivDiv = twitterDiv + '_rss';
//	$(twitterDivDiv).set('style','display:block; ');

	getTwitters(twitterDiv, { 
		id: 'rentavo', count: 6, enableLinks: true, ignoreReplies: true, clearContents: true,
		template: '"%text%" <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'		  
		} 
	);



// ----------------------------------------------------------
}); // end on domready.... which is on load but used to be domready ;)
// ----------------------------------------------------------

function recent_comments(i) {
  $$('.pcomments').forEach(function(item,id) {
     var ix = item.get('id').replace(/pc/,'')-1;
     // ix loops through each of them, 1,2,3 etc
     // i is just the one that is being turned on
     if (item&&(i-3===ix||i+pclength-3===ix)) {
       item.morph({height: 0, width: 0});
//       item.setStyle('display','none');
     }
  });
  var item = $$('.pcomments')[i];
  if (item) {
    item.morph({height: 85, width: 205});
    //item.setStyle('display','block');
    i = ($$('.pcomments')[i+1]) ? i+1 : 0;
    window.setTimeout('recent_comments('+(i)+')',pcspeed);
  }
}

function update_user_box() {
  onConnected();
  if ($('login')) {
    var url = '/facebook_rentavo/get_login_bar';
    var myajax = new Request({
      url: url,
      method: 'post',
      evalResponse: true,
      onComplete: function(response) {
        if ($('login')) {
          user_box = $('login').clone();
          user_box.setProperty('id','loggedin');
          user_box.set('html',response);
          user_box.replaces('login');
        }
        if ($('commenter')) {
          $('commenter_cmd').setStyle('display','none');
          $('commenter').setStyle('display','block');
        }
      }
    }).send();
  }
}

function facebook_onlogin() {
  onConnected(1);
}
var onlyonce = 0;
function facebook_logout() {
    var url = '/facebook_rentavo/logout';
    var myajax = new Request({
      url: url,
      method: 'post',
      onComplete: function() {
        //location.reload(true);
        FB.Connect.logoutAndRedirect(""); 
      }
    }).send();
}
function onConnected(user_id) { 
  // originally was meant to do the work of get_login_bar...but now simply updates the user's session
  if (onlyonce<1) {
    var url = '/facebook_rentavo/get_user';
    var myajax = new Request({
      url: url,
      method: 'post'  
    }).send();
    onlyonce = 1;
  }
} 

function fbrequiresession() {
  FB.Connect.requireSession();
  //box.close();
  $$('.MultiBoxClose').forEach(function(item,i) {
    if (i==1) item.fireEvent('click');
  });
  $('wob').setStyle('display','none');
  $('loginbarform').setStyles({'display':'block'});
}

// control the timing of the flash on the login now from the mb popup
var initwait = 1000; 
var wait2on  = 325;
var wait2off = 650;
var stop_it  = 0;
function closesignup() {
  //box.close();
  $$('.MultiBoxClose').forEach(function(item,i) {
    if (i==1) item.fireEvent('click');
  });
  $('wob').setStyle('display','none');
  $('loginbarform').setStyles({'opacity':0,'display':'block'});
  setTimeout("closesignup_fadein()",initwait);
}
function closesignup_fadeout() {
  $('loginbarform').setStyle('opacity',0);;
  setTimeout("closesignup_fadein()",wait2on);
}
function closesignup_fadein() {
  stop_it++;
  $('loginbarform').fade('in');
  if (stop_it>2) {
    setTimeout("$('loginbarform_user').highlight('#F00');",initwait+wait2on);
    setTimeout("$('loginbarform_pass').highlight('#F00');",initwait+wait2on+wait2on);
  } else {
    setTimeout("closesignup_fadeout()",wait2off);
  }
}


function noop() {
    // namby pamby session nooping
    // probably means i don't know 
    // how to keep da session from
    // being cleaned up, oh well:(
    var url = '/';
    var myajax = new Request({
      url: url,
      method: 'post'
    }).send();
  window.setTimeout('noop()',nooptime);
}



function toggle(expandThis,mouseOver) {
  var mySlide = new Fx.Slide(expandThis);
  $(mouseOver).addEvent('mouseover', function(e){
    e = new Event(e);
    mySlide.toggle();
    e.stop();
  });
}    


function toggleClick(expandThis,mouseOver) {
  var mySlide = new Fx.Slide(expandThis);
  $(mouseOver).addEvent('click', function(e){
    e = new Event(e);
    mySlide.toggle();
    e.stop();
  });
}    


function hideEle(ele) {  
  $(ele).setStyle('display', 'block');
  var mySlide = new Fx.Slide(ele);
  mySlide.hide();      
}


function showEle(ele) {  
  $(ele).setStyle('display', 'block');
  var mySlide = new Fx.Slide(ele);
  mySlide.show();      
}


function slideInEle(ele) {  
  $(ele).setStyle('display', 'block');
  var mySlide = new Fx.Slide(ele);
  mySlide.slideIn();      
}


function slideOutEle(ele) {  
  $(ele).setStyle('display', 'block');
  var mySlide = new Fx.Slide(ele);
  mySlide.slideOut();      
}


