(function($j) {		

  

  init = function(){
  
   accordian();
   rollup();
   popup();

  }
  
  popup = function(){

    $j('.popup_link').unbind().bind('click',function(e){
          var offset = $j(this).offset();
          var curId = this.id;
          var hiddenContent = $j('#hiddenContent_'+curId);
          var popUp = $j('#popup_box');
          var popUpContent = $j('#popupContent');
          var overlay = $j('#overlay');
          
          var popUpHtml ='<a href="#" id="close_popup">Close</a>'+hiddenContent.html()
          popUpContent.html(popUpHtml);
          var windowHeight = $j(window).height();
          var docHeight = $j(document).height(); 
          var offset = $j(document).scrollTop(); 
          var centerY = offset+((windowHeight-500)/2);
          overlay.css({opacity:'.25',height:docHeight}).show();
          popUp.show('slow').css({top:centerY,left:'50%'});
          Cufon.replace('h2');
          $j('#close_popup').unbind().bind('click',function(e){
              var popUp = $j('#popup_box');
              var popUpContent = $j('#popup_content');
              overlay.hide();
              popUpContent.html('');
              popUp.hide('slow');
          return false;
          })
          $j('#overlay').unbind().bind('click',function(e){
              var popUp = $j('#popup_box');
              var popUpContent = $j('#popup_content');
              overlay.hide();
              popUpContent.html('');
              popUp.hide('slow');
          return false;
    })
          return false;
    })
    
   
  }
  
  rollup = function(){
  
     $j('.childThumbnail').hover(function(e){
          $j(this).find('.snippet').slideToggle();
     },function(e){
         $j(this).find('.snippet').slideToggle();
     });
  }


  accordian = function(){
  
    $j('.accordionHeader').unbind().bind('click',function(e){
        
        var curId = this.id
                
        
        
        $j('.accordionContent').each(function(){
          if($j(this).is(":visible")){
              $j(this).slideUp('fast');
              
          }
        });
         $j('.accordionHeader').each(function(){
          if($j(this).is(":visible")){
             
              $j(this).removeClass('accordionOn');
          }
        });
        $j('.close_acc').each(function(){
          if($j(this).is(":visible")){
             
              $j(this).hide();
          }
        });
        var curAcc = $j('#accordionContent_'+curId);
        if(curAcc.is(":visible")){}else{
          $j('#accordionContent_'+curId).slideDown('slow', function() {
            //console.log('complete');
            $j('#'+curId).addClass('accordionOn');
            $j('#close_acc_'+curId).show();
          });
        }
        
        return false;
    });
  }

 $j(document).ready(function() {
      init();
  });

})(jQuery);
