// prevent issues w/ other frameworks
jQuery.noConflict();

// browser hacks
var is_mac_ff2 = false;
if (/Mac/.test(navigator.platform) && /Firefox\/2/.test(navigator.userAgent)) {
  is_mac_ff2 = true;
}
var is_opera = false;
if (jQuery.browser.opera) {
  is_opera = true;
}

// arrows on mouseover
jQuery(function(){
  var arrow_count = 0;
  var arrow_item = false;
  var arrow_interval = false;
  // some browsers encode, some don't
  var arrow_char = '&gt;';
  var s = jQuery('.headerContainer:first > ul:first > li:first > ul:first > li:first > a:first').eq(0).html();
  if(s != null) {
    if (s.substring(s.length - 1) == '>') {
      arrow_char = '>';
    }
  }
  var arrow_reg = new RegExp(arrow_char, 'g');
  function do_arrows() {
    arrow_count++;
    if (arrow_count > 2) {
      arrow_count = 0;
    }
    var arrow_string = '';
    for(var i=0; i<arrow_count; i++) {
      arrow_string += arrow_char;
    }
    if (arrow_count == 0) {
      arrow_string = '&nbsp;'
    }
    if (arrow_count == 1) {
      arrow_string += '&nbsp;'
    }
    arrow_item.next('span').html(arrow_string);
  }
  jQuery('#clientList > ul > li > a, .headerContainer > ul > li > ul > li > a, .brandfuel_expanded ul.brandfuel_nav li a, .backlink > li > a').each(function(e){
    jQuery(this).after('<span>&nbsp;&nbsp;</span>');
  });
  jQuery('#clientList > ul > li > a, .headerContainer > ul > li > ul > li > a, .brandfuel_expanded ul.brandfuel_nav li a, .backlink > li > a').hover(function(e){
      arrow_count = 0;
      arrow_item = jQuery(this);
      if (arrow_item.html().substring(arrow_item.html().length-arrow_char.length) == arrow_char) {
        do_arrows();
        arrow_interval = setInterval(do_arrows, 250);
        if(!arrow_item.parent().parent().hasClass('brandfuel_nav')) {
          arrow_item.css('color', '#cc092f');
        }
      }
    }, function(e){
      clearInterval(arrow_interval);
      arrow_item = jQuery(this);
      if (arrow_item.html().substring(arrow_item.html().length-arrow_char.length) == arrow_char) {
        arrow_item.next('span').html('&nbsp;&nbsp;');
        if(!arrow_item.parent().parent().hasClass('brandfuel_nav')) {
          arrow_item.css('color', '#77787b');
        }
      }
  }).click(function(e){
    // use JS to capture the click, not just regular HTML
    return true;
  });
});

// brandfuel sidebar
jQuery(function(){
  //animate the dropdown menus for navigation
  jQuery('.brandfuel_container').hover(function(e){
      jQuery('.brandfuel_head_bg > ul > li > h2').css('background', 'url(/images/logo.brandfuel_roll.gif) no-repeat scroll 0 0');
      toggleBrandFuel(true);
    }, function(e){
      jQuery('.brandfuel_head_bg > ul > li > h2').css('background', 'url(/images/logo.brandfuel.gif) no-repeat scroll 0 0');
      toggleBrandFuel(false);
  });

  // slide up/down
  var brandfuelExpanded = jQuery('.brandfuel_expanded:first');
  var brandfuelExpandedHeight = brandfuelExpanded.css('height');
  brandfuelExpanded.css('height', '0px').css('display', 'none');
  var brandfuelSlidingUp = false;
  jQuery('.brandfuel_content_wrap').html('');//remove it, .remove(); didn't work
  function toggleBrandFuel(show) {
    if (show) {
      jQuery('.brandfuel_content_wrap').html('');//remove it, .remove(); didn't work
      if (is_opera) {
        brandfuelExpanded.css('display', 'block').css('height', brandfuelExpandedHeight);
        jQuery('.brandfuel_content_wrap').append('<div id="brandfuel_content_swf"></div>');
        var flashvars = {
          process_url: sf_process_url,
          case_url: sf_case_studies_url
        };
        var params = {
          menu: "false",
          wmode: "transparent"
        };
        var attributes = {
          id: "brandfuelContentSwf",
          name: "brandfuelContentSwf"
        };
        swfobject.embedSWF("/flash/brandfuel.swf", "brandfuel_content_swf", "307", "317", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
      } else {
        brandfuelSlidingUp = false;
        brandfuelExpanded.stop().css('display', 'block').animate({height: brandfuelExpandedHeight}, 'slow', function(){
          if (!brandfuelSlidingUp) {
            jQuery('.brandfuel_content_wrap').append('<div id="brandfuel_content_swf"></div>');
            var flashvars = {
              process_url: sf_process_url,
              case_url: sf_case_studies_url
            };
            var params = {
              menu: "false",
              wmode: "transparent"
            };
            var attributes = {
              id: "brandfuelContentSwf",
              name: "brandfuelContentSwf"
            };
            swfobject.embedSWF("/flash/brandfuel.swf", "brandfuel_content_swf", "307", "317", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
          }
        });
      }
    } else {
      jQuery('.brandfuel_content_wrap').html('');//remove it, .remove(); didn't work
      if (is_opera) {
        brandfuelExpanded.stop().css('height', '0px').css('display', 'none');
      } else {
        brandfuelSlidingUp = true;
        brandfuelExpanded.stop().animate({height: '0px'}, 'slow', function(){
          brandfuelExpanded.css('display', 'none');
          brandfuelSlidingUp = false;
        });
      }
    }
  }

  // sidebar content
  function animateBrandFuel(){
    if (jQuery('.brandfuel_expanded .highlightable:first').length){
      jQuery('.brandfuel_expanded .highlightable:first').removeClass('highlightable').animate({
          color: '#636466'
        }, 'slow', null, function(){
          jQuery(this).animate({
              color: '#ffffff'
            }, 'slow', null, function(){
              animateBrandFuel();
          });
        }
      );
    }
  }

  function stopBrandFuel(){
    jQuery('.brandfuel_expanded:first .highlightable').removeClass('highlightable').stop().css('color', '#ffffff');
  }

  // sidebar iframe for overlaying flash
  jQuery('.brandfuel_expanded .overlay iframe').height(jQuery('.brandfuel_expanded').height());
});

// carousel
function showCarouselItem(index){
  if (navigator.appName.indexOf('Microsoft') != -1){
    window['carousel'].showIndex(index);
  } else {
    document['carousel'].showIndex(index);
  }
}

function activateCarouselItem(index){
  jQuery('ul#nav > li > a').eq(index).trigger('carousel');
}

// navigation
jQuery(function(){
  jQuery('ul#nav > li > a').click(function(e){
    if (jQuery('.carousel:first').length) {
      navTo(this);
      showCarouselItem(jQuery('ul#nav > li > a').index(this));
      return false;
    }
    return true;
  });

  jQuery('ul#nav > li > a').bind('carousel', function(e){
    navTo(this);
  });

  var activeBrandFuelIcon = 'propane';
  function navTo(item) {
    setActiveSolarMarkTo(item);
    jQuery('.solarMark').removeClass(menuGroup);
    menuGroup = jQuery(item).parent().attr('class');
    jQuery('.solarMark').addClass(menuGroup);
    var newBrandFuelIcon = 'propane';
    if(menuGroup == 'work') {
      newBrandFuelIcon = 'gascan';
    } else if(menuGroup == 'us') {
      newBrandFuelIcon = 'molotov';
    } else if(menuGroup == 'blog') {
      newBrandFuelIcon = 'oilcans';
    }
    var brandFuelIconImg = jQuery('.brandfuel_head_bg > ul > li.last > img');
    var brandFuelIconSrc = brandFuelIconImg.attr('src').replace(/\.[^\.]+\.jpg$/, '.'+newBrandFuelIcon+'.jpg');
    if (brandFuelIconImg.attr('src') != brandFuelIconSrc) {
      brandFuelIconImg.fadeOut(function(){
        jQuery(this).attr('src', brandFuelIconSrc).fadeIn();
      });
    }
    restoreActiveSolarMark();
  }

  //custom solar mark position for the home/logo link
  jQuery('.headerContainer > h1 > a.home').hover(function(e){
      setActiveSolarMarkTo(this);
    }, function(e){
      restoreActiveSolarMark();
  });

  //custom solar mark position for the brandfuel/logo link
  jQuery('.brandfuel_container').hover(function(e){
      jQuery('.brandfuel_head_bg > ul.fuel:first').each(function(){
        setActiveSolarMarkTo(this);
      });
    }, function(e){
      restoreActiveSolarMark();
  });

  //animate the dropdown menus for navigation
  jQuery('ul#nav > li').hover(function(e){
      setActiveSolarMarkTo(this);
      jQuery('> a', this).addClass('active');
      if (is_mac_ff2) { 
        jQuery('> ul:first', this).css('display', 'block');
      } else {
        jQuery('> ul:first', this).css('display', 'block').stop().animate({
          opacity: 1
        }, 'slow');
      }
    }, function(e){
      restoreActiveSolarMark();
      jQuery('> a', this).removeClass('active');
      if (is_mac_ff2) { 
        jQuery('> ul:first', this).css('display', 'none');
      } else {
        jQuery('> ul:first', this).stop().animate({
            opacity: 0
          }, 'fast', null, function(){
            jQuery(this).css('display', 'none');
        });
      }
  });

  // active menu item
  var menuGroup='';
  menuGroup = jQuery('.solarMark').attr('class').replace(/solarMark/,'');
  if (!menuGroup.length){
    menuGroup = 'home';
  }

  // These are the same as in the screen.css (line 136, .solarMark.work, .solarMark.us, .solarMark.blog)
  var solarMarkPositions = {
    'home': '78px',
    'work': '212px',
    'us': '288px',
    'blog': '368px',
    'fuel': '688px'
  };

  var moveToLeft = 0;
  var menuMovingTo = false;
  var menuMovingBack = false;
  function setActiveSolarMarkTo(activeItem) {
    // Keep the original Group to return to
    if (menuGroup.length <= 1){
      menuGroup = jQuery('.solarMark').attr('class').replace(/solarMark/,'');
      if (menuGroup.length){
        menuGroup = 'home';
      }
    }
    // Get the new group we're over
    newGroup = jQuery(activeItem).attr('class').replace(/hover/, '');
    if (!newGroup.length){
      newGroup = 'home';
    }
    moveToLeft = eval('solarMarkPositions.'+newGroup);
    if (moveToLeft) {
      jQuery('.solarMark').stop().animate({
          left: moveToLeft
        }, 'slow', 'easeOutBack'
      );
   }
  }

  function restoreActiveSolarMark() {
    moveToLeft = eval('solarMarkPositions.'+menuGroup);
    if (moveToLeft) {
      jQuery('.solarMark').stop().animate({
          left: moveToLeft
        }, 'slow', 'easeInBack'
      );
    }
  }
});

// scroller
jQuery(function(){
  if (jQuery.browser.opera) {
    jQuery('.flir', content_container).css('margin-bottom', '10px');
  }
  
  var scroll_control = jQuery('#scroll_control:first'); // wrapper for scrolling
  var scroll_content = jQuery('#scroll_content:first'); // items to scroll
  var content_container = jQuery('.contentContainer:first'); // bounding box for content position
  if (scroll_control.length && scroll_content.length && content_container.length) {
    // ###### CONFIGURATION #######
    // configuration
    var scroll_edge = 25; // cursor position as percentage of width to begin movement
    var scroll_walk = 10; // max distance to move at one interval

    // flags
    var scroll_over = false;
    var scroll_clicking = false;

    // ###### INITIALIZATION #######
    // control vars
    var c_offset, c_width, c_height, c_x1, c_x2, c_y1, c_y2;
    // content vars
    var t_offset, t_width, t_height, t_x1, t_x2, t_y1, t_y2;
    // bounding box vars
    var n_offset, n_x1, n_x2;
    // individual scrollable item width/height
    var i_width, i_height;
    // active start position
    var previous_position;
    var snap_left = 0;
    var curs_x = 0, curs_y = 0;
    var scroll_interval;
    var total_width = 0;
    var first_i_x1 = 0;
    var scroll_initialized = false;

    function scroll_init() {
      scroll_load_handlers();

      // control vars
      c_offset = scroll_control.offset();
      c_width = scroll_control.outerWidth();
      c_height = scroll_control.outerHeight();
      c_x1 = c_offset.left;
      c_x2 = c_x1 + c_width;
      c_y1 = c_offset.top;
      c_y2 = c_y1 + c_height;

      // content vars
      t_offset = scroll_content.offset();
      t_width = scroll_content.outerWidth();
      t_height = scroll_content.outerHeight();
      t_x1 = t_offset.left;
      t_x2 = t_x1 + t_width;
      t_y1 = t_offset.top;
      t_y2 = t_y1 + t_height;

      // bounding box vars
      n_offset = content_container.offset();
      n_x1 = n_offset.left;//hack?
      n_x2 = n_x1 + n_offset.width;

      if (!scroll_initialized) {
        // only first init, not re-inits
        // individual scrollable item width
        var first_item = jQuery('> *:first', scroll_content);
        var second_item = jQuery('> *:first ~:first', scroll_content);
        first_i_x1 = first_item.offset().left;
        i_width = first_item.outerWidth();
        i_margin = second_item.offset().left - first_item.offset().left - i_width;
        i_height = first_item.outerHeight();
        first_item.outerWidth();

        // configuration vars
        scroll_walk = Math.floor(i_width / 6);// a little more automated

        // get total width, set div width to un-float everything, position: relative; left: *i_width*, so add width
        total_width = scroll_item_left_offset(jQuery('> :last', scroll_content));
        scroll_content.css('width', (total_width + i_width) + 'px');
        t_width = scroll_content.outerWidth();
      }
      scroll_initialized = true;

      if (!scroll_clicking) {
        // reset scroll_carousel and position on resize
        previous_position = 0;
        scroll_content.css('left', '0');// set initial position
        snap_left = scroll_item_left_offset(jQuery('> .active:first', scroll_content));
        scroll_content.css('left', (n_x1 - snap_left) + 'px');// set initial position
        scroll_carousel_cycle(true);
      }
    }

    function scroll_item_left_offset(scroll_item) {
      var offset = 0;
      if (scroll_item.offset().top > t_y1) {
        // something to search it by
        scroll_item.addClass('scroll_findme');
        // if it's floated down, we add offsets together
        var position = 0;
        // loop through them all so we get the exact position
        var last = 0;
        jQuery('> *', scroll_content).each(function(){
          if (offset) {
            return;
          }
          if (jQuery(this).offset().left == first_i_x1) {
            // new row in float list
            position = position + last;
          }
          if (jQuery(this).hasClass('scroll_findme')) {
            // the item we're looking for
            jQuery(this).removeClass('scroll_findme');
            offset = position + jQuery(this).offset().left;
          }
          last = jQuery(this).offset().left;// add width of last item in last row
        });
      } else {
        offset = scroll_item.offset().left;
      }
      return offset;
    }

    // execute scroll function (on setInterval)
    var scroll_stop = false; // whether or not we're moving
    function scroll_do() {
      // if something wants to stop scroll, let it
      if (scroll_stop) {
        return;
      }

      snap_left = 0;
      scroll_move = 0;
      if (!scroll_over || scroll_clicking) {
        if (scroll_clicking) {
          // move position to new active item
          snap_left = scroll_item_left_offset(jQuery('> .active:first', scroll_content));
          speed = Math.abs(Math.floor(snap_left / c_width * 12));
          if (speed < 1) {
            speed = 1;
          }
          if (snap_left < n_x1) {
            // move right to get back to it
            scroll_move = scroll_walk * speed;
          } else if (snap_left > n_x1) {
            // move left to get back to it
            scroll_move = -1 * scroll_walk * speed;
          } else if ( snap_left == n_x1 ){
            scroll_clicking = false;
          }
        }
      } else {
        // optional: make it so that the cursor must also be outside the range of the bounding box
        //if (curs_x > n_x1 || curs_x < c_width - n_x1) {
        //  return;
        //}
        if (scroll_xp < scroll_edge) {
          // within edge range to move right
          snap_left = scroll_item_left_offset(jQuery('> :first', scroll_content)); // stop moving right when last item reached
          scroll_move = scroll_walk - Math.ceil(scroll_xp/scroll_edge * scroll_walk);// always 1:10
        } else if (scroll_xp > (100 - scroll_edge)) {
          // within edge range to move left
          snap_left = scroll_item_left_offset(jQuery('> :last', scroll_content)); // stop moving left when last item reached
          scroll_move = Math.ceil((scroll_edge - (100 - scroll_xp))/scroll_edge * scroll_walk) * -1;// always -1:-10
        }
      }

      if (scroll_move == 0) {
        return;
      }

      // stop any animations before we move manually
      scroll_content.stop();

      // hold all actions until we're done moving it
      scroll_stop = true;

      if (snap_left != 0) {
        // keep it from going too far to left past left of the snap item
        if (scroll_move < 0 && (snap_left + scroll_move) <= n_x1) {
          scroll_move = (snap_left - n_x1) * -1;
        }
        // keep it from going too far to right past left of the snap item
        if (scroll_move > 0 && (snap_left + scroll_move) >= n_x1) {
          scroll_move = n_x1 - snap_left;
        }
      }

      // move it
      scroll_content.css('left', (scroll_content.position().left + scroll_move) + 'px');

      // do carousel
      scroll_carousel_cycle();

      // we're done
      scroll_stop = false;
    }

    function scroll_carousel_cycle(force) {
      var reposition_max = jQuery('> *', scroll_content).length;
      for(i=0; i<reposition_max; i++) {
        if (!scroll_carousel(force)) {
          break;
        }
      }
    }

    function scroll_carousel(force) {
      // carousel
      new_position = scroll_content.position().left;
      // only do the carousel if there is a full browser width worth
      if ((t_width - ((i_width + i_margin)*1.5)) > c_width && (force || new_position != previous_position)) {
        var first = jQuery('> :first', scroll_content);
        var last = jQuery('> :last', scroll_content);
        var do_first = false;
        var do_last = false;
        if (force || new_position > previous_position) {
          // moved right
          left_edge = first.offset().left;
          if (left_edge > c_x1) {
            // it needs one to fill in to the left of it
            do_first = true;
          }
        }
        if (force || new_position < previous_position) {
          // moved left
          right_edge = last.offset().left + i_width;
          if (right_edge < c_x2) {
            // it's off screen to the left, move it to the right
            do_last = true;
          }
        }
        if (do_first && !do_last) {
          // add one before the first
          scroll_content.prepend(last).css('left', (new_position - i_width - i_margin) + 'px');
        } else if (do_last && !do_first) {
          // add one after the last
          scroll_content.append(first).css('left', (new_position + i_width + i_margin) + 'px');
        }
        previous_position = scroll_content.position().left;
        if (previous_position != new_position) {
          return true; // we adjusted
        }
      }
      return false; //no change
    }

    // scroll to an item w/in scroll content
    function scroll_to(item, callback) {
      // change active state
      scroll_clicking = true;
      jQuery('> .active:first', scroll_content).removeClass('active');
      item.addClass('active');
    }

    // load an item
    function scroll_load(item, callback) {
      url = item.children(':first').attr('href');
      if (url != '#') {
        if(jQuery.browser.msie) {
          content_container.stop().slideUp('fast', function(){
            // lock height for now, then animate to height
            jQuery('.pageContainer').css('background', "url('/images/loading.gif') no-repeat 165px 265px");
            content_container.load(url, null, function(){
              // hide load animation background
              jQuery('.pageContainer').css('background', 'none');
              setTimeout(scroll_load_callback, 250);
            });
          });
        } else {
          content_container.stop().animate({opacity: 0}, 250, null, function(){
            // lock height for now, then animate to height
            content_container.css('height', content_container.offset().height + 'px');
            jQuery('.pageContainer').css('background', "url('/images/loading.gif') no-repeat 165px 265px");
            content_container.load(url, null, function(){
              // hide load animation background
              jQuery('.pageContainer').css('background', 'none');
              setTimeout(scroll_load_callback, 250);
            });
          });
        }
        scroll_to(item, callback);
      }
    }

    // after loading content, callback to this so we can reset handlers and sizes
    function scroll_load_callback() {
      if(jQuery.browser.msie) {
        content_container.stop().slideDown('slow');
      } else {
        content_container.stop().animate({opacity: 1, height: 'auto'}, 1000);
      }
      scroll_init();
      if (jQuery.browser.opera) {
        jQuery('.flir', content_container).css('margin-bottom', '10px');
      }
      jQuery('.flir').css('visibility', 'hidden');
      FLIR.replace(jQuery('.flir', content_container), new FLIRStyle());
      setTimeout(function(){
          jQuery('.flir').css('visibility', 'visible');
        },
        250
      );
    }

    // unload an item
    function scroll_unload(item, callback) {
      content_container.stop().animate({opacity: 0}, 250);
      jQuery('.workNav a, .personNav a').hide();
      scroll_to(item, callback);
    }

    // load next item
    function scroll_load_next(callback) {
      next = jQuery('> .active:first', scroll_content).nextAll(':not(.divider):first');
      if (!next.length) {
        next = jQuery('> :not(.divider):first', scroll_content);
      }
      scroll_load(next);
    }

    // load prev item
    function scroll_load_prev(callback) {
      prev = jQuery('> .active:first', scroll_content).prevAll(':not(.divider):first');
      if (!prev.length) {
        prev = jQuery('> :not(.divider):last', scroll_content);
      }
      scroll_load(prev);
    }

    // set handlers after load
    function scroll_load_handlers() {
      // capture click of left arrow
      jQuery('.workNav > :first, .personNav > :first').click(function(){
        scroll_load_prev();
        return false;
      });

      // capture click of right arrow
      jQuery('.workNav > :last, .personNav > :last').click(function(){
        scroll_load_next();
        return false;
      });

      jQuery('.workNav > :first, .personNav > :first').hover(function() {
          jQuery('> a:first > img:first', this).attr('src', '/images/btn.arrowPrevHover.gif');
        }, function() {
          jQuery('> a:first > img:first', this).attr('src','/images/btn.arrowPrev.gif');
      });
      jQuery('.workNav > :last, .personNav > :last').hover(function() {
          jQuery('a:first > img:first', this).attr('src','/images/btn.arrowNextHover.gif');
        }, function() {
          jQuery('a:first > img:first', this).attr('src','/images/btn.arrowNext.gif');
      });
    }

    // capture click of an item
    jQuery('> *', scroll_content).click(function(){
      if (!jQuery(this).hasClass('divider')) {
        scroll_load(jQuery(this));
      }
      return false;
    });

    //gallery divider rollover
    jQuery('> .divider', scroll_content).mouseover(function(){
      jQuery('> img:first', this).attr('src', '/images/portfolio_items/thumb.dividerHover.jpg');
      if (jQuery.browser.msie) {
        jQuery('> span:first', this).css('opacity', 'auto').css('visibility', 'visible');
      } else {
        jQuery('> span:first', this).stop().css('opacity', '0').css('visibility', 'visible').animate({opacity: 1}, 'fast');
      }
    });
    jQuery('> .divider', scroll_content).mouseout(function(){
      jQuery('> img:first', this).attr('src', '/images/portfolio_items/thumb.divider.jpg');
      if (jQuery.browser.msie) {
        jQuery('> span:first', this).css('visibility', 'hidden');
      } else {
        jQuery('> span:first', this).stop().animate({opacity: 0}, 'fast');
      }
    });

    // rebuild the offset values on resize
    var scroll_window_width = window.innerWidth;
    jQuery(window).resize(function(){
      if (window.innerWidth != scroll_window_width) {
        scroll_window_width = window.innerWidth;
        // reset vars
        scroll_init();
      }
    });

    // function to capture mouse position
    jQuery().mousemove(function(curs){
      // if the mouse is over the scroll_control div, we might move
      scroll_over = false;
      if (curs.pageX > c_x1 && curs.pageY > t_y1 && curs.pageX < c_x2 && curs.pageY < t_y2) {
        // set offset calculation
        scroll_xp = Math.floor((curs.pageX - c_x1) / c_width * 100); // cursor position as a percentage of div width
        curs_x = curs.pageX;
        scroll_over = true;
      }
    });

    // to start scroller
    var scroll_started = false;
    function scroll_start() {
      if (!scroll_control || !scroll_content) {
        return;
      }
      if (scroll_started) {
        return;
      }
      scroll_started = true;

      // initialize the scroller
      scroll_init();

      // run it
      scroll_interval = setInterval(scroll_do, 25);
    }
    // start me up
    scroll_start();
  }
});

// Add the show/hide buttons to all articleHeaders
jQuery(function(){
  jQuery('h4.articleHeader').each(function(){
    var toggle_item = jQuery(this).next();
    if (toggle_item.hasClass('articleContent')) {
      toggle_item.hide();
      jQuery(this).append('<a class="showhide">view &gt;</a>');
    }
  });
  // show/hide buttons from tinymce editor
  jQuery('a.showhide').click(function(e){
    var toggle_item = jQuery(this).parent().next('.articleContent');
    if (toggle_item) {
      if (toggle_item.css('display') == 'none') {
        jQuery('.articleContent').not(toggle_item).slideUp();
        jQuery('h4.articleHeader a').not(this).text('view >')
        jQuery(this).text('close v');
      } else {
        jQuery(this).text('view >');
      }
    }
    toggle_item.slideToggle();
  });
  if (jQuery.browser.msie) {
    jQuery('a.showhide').hover(function(e){
        jQuery(this).css('color', '#e51937');
      }, function(e){
        jQuery(this).css('color', '#77787b');
    });
  }
});
