var sctimer;
// The ID of the div that is used to load content using Ajax calls:
var scrid = '#ideasandinsights-right';
var modulepath = "";


function scrollIt ( forward ) {

   //var num = $ui(scrid).scrollTop();
   var step = 3*forward;
   //var num = num + step;
   
   $ui(scrid)[0].scrollBy(step);
     
   //$ui(scrid).scrollTop(num);
   //alert ("scrolled "+num);
   sctimer = setTimeout('scrollIt('+forward+')',100);
}

/**
 * This function is assuming that "modulepath" is set globally
 * before calling this function.
 */
function aggregator_helper_preloadimages  () {
  
  for(var i = 0; i<arguments.length; i++)
  {
    $ui("<img>").attr("src", modulepath+'/images/'+arguments[i]);
  }

}

function fixIEWeirdness() {
  
  // Make left-navig items vertically centered.
  //$('li.p2leftcolumn .activefeed').css("padding-top", "0px");    
  
}

function aggregator_helper_init( loading_placeholder, mpath ) {
  
  modulepath = mpath;
  
 /* if (jQuery.browser.msie) {
    fixIEWeirdness();
  }*/ 
  
  //jQuery.jScrollPane
  $ui(scrid).jScrollPane({animateTo:true, animateInterval:100, animateStep:3}); 
  //$ui(scrid).css("border", "1px solid #e1e1e1");
  
  /** Scroller Buttons - Disabled 
  $ui('a.scroller_control').mouseover(
    function scroller(eventObject) {
        var forward = $ui(this).attr ( 'forward' );
         scrollIt( forward );
    }
  );
 
  $ui('a.scroller_control').mouseout(
    function stopScroll(eventObject) {
        if (sctimer) clearTimeout(sctimer);
    } 
  ); 
  */

  aggregator_helper_preloadimages (
        'tab_our_feeds_on.gif',
        'tab_our_feeds_over.gif',
        'tab_our_feeds.gif',
        'tab_what_feeds_us_on.gif',
        'tab_what_feeds_us_over.gif',
        'tab_what_feeds_us.gif');
  
  //-- LOAD content are on link clicks. 
  $ui('li.ii_feeds').click( function() {
   
      var caption = $ui(this).text(); 
      var mark = null; 
      if ( $ui(this).attr("mark") ) {
        mark  = $ui(this).attr("mark");
        caption =  mark + " " + caption;
      }
      
      if ( $ui(this).attr("cat") ) {
        var cat  = $ui(this).attr("cat");
        //http://ogilvy.p2technology.com/aggregator/rss/22
        var rssurl = "/aggregator/rss/"+cat;
        var rssicon = "<img id=\"ii_categoryrssicon\" src="+modulepath+"/images/rss.png height=\"12\">";
        caption = caption + " " + "<a href=\""+rssurl+"\">"+rssicon+"</a>";
        //alert ($ui("h2#feeditemscaption").html() ); 
      }
      
    $ui("h2#feeditemscaption").html( caption );
    $ui("li.activefeed").attr("class", "ii_feeds");
    $ui(this).attr("class", "ii_feeds activefeed"); 
   
    $ui("#ideasandinsights-right").html( loading_placeholder );
    var url = $ui(this).attr("dest");
     
    $ui.get( url, function(data) {
        $ui("#ideasandinsights-right").empty().html(data).jScrollPane({animateTo:true, animateInterval:100, animateStep:3});;
    	});
    
  	return false;            
  	 
  });  

  //-- Tab Rollovers for I&I tabs  
  $ui('img#iiof_whatfeedsus').mouseover(
    function iiof_whatfeedsus(eventObject) {
      $ui(this).attr("src", modulepath+'/images/tab_what_feeds_us_over.gif') ;
    }
  );
  
  $ui('img#iiof_whatfeedsus').mouseout(
    function iiof_whatfeedsus_out(eventObject) {
      $ui(this).attr("src", modulepath+'/images/tab_what_feeds_us.gif') ;
    }
  );

  $ui('img#iiof_ourfeeds').mouseover(
    function iiof_ourfeeds(eventObject) {
      $ui(this).attr("src", modulepath+'/images/tab_our_feeds_over.gif') ;
    }
  );
  
  $ui('img#iiof_ourfeeds').mouseout(
    function iiof_ourfeeds_out(eventObject) {
      $ui(this).attr("src", modulepath+'/images/tab_our_feeds.gif') ;
    }
  );
  //-- End Tab Rollovers for I&I tabs
    	
}
                      
