////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Greater Wilmington Business Journal Javascript functions
// This file includes a collection of functions for use on the Greater Wilmington Business Journal site
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$(function()
{
   // home tabs
   $('#tabs_entrepreneurs div').click(switch_entrepreneur);

   // article slideshow
   if($('#article_slideshow').length > 0) {
      article_slideshow();
   }

   // horizontal navigation
   $('#header .nav a').mouseover(display_subnav);
   
   // dropdown menu
   $('#header .dropdown').hover(display_dropdown, hide_dropdown);

});


function switch_entrepreneur()
{
   var top,inner,title;
   var tab = $(this).attr('id');

   switch(tab) {
      case 'personal_business_tab':
         top = '52';
         inner = 'business';
         title = 'personal_business_top.jpg';
         break;
      case 'entrepreneur_tab':
         top = '0';
         inner = 'entrepreneur';
         title = 'entrepreneurs_top.jpg';
         break;
      case 'real_estate_tab':
         top = '26';
         inner = 'real_estate';
         title = 'real_estate_top.jpg';
         break;
   }

   // switch tab
   $(this).parent().css('background-position','0px '+top+'px');

   // hide all inner content
   $('#entrepreneurs_box .inner').hide();

   // display specified tab
   $('#entrepreneurs_box .inner.'+inner).show();

   // change title graphic and alt
   $('#entrepreneurs_box img.title').attr('src','/images/'+title).attr('alt',inner);
}


function article_slideshow()
{
   // show first image
   $('#article_slideshow div:first').show();

   // show next image
   $('#article_slideshow .next').click(function(){
      var next = $('#article_slideshow div:visible').next();
      if(next.attr('tagName') != 'DIV') { return; }
      $('#article_slideshow div').hide();
      next.show();
   });

   // show previous image
   $('#article_slideshow .previous').click(function(){
      var previous = $('#article_slideshow div:visible').prev()
      if(previous.attr('tagName') != 'DIV') { return; }
      $('#article_slideshow div').hide();
      previous.show();
   });
}


function display_subnav()
{
   var sn_class = $(this).attr('class');

   $('#header .subnav div').removeClass('hovered');

   if(sn_class == undefined) {
      $('#header .subnav div[class="sn_home"]').addClass('hovered');
   } else {
      $('#header .subnav div[class="'+sn_class+'"]').addClass('hovered');
   }
}


function hide_subnav()
{
   $('#header .subnav div').removeClass('hovered');
   $('#header .subnav div.latest_news').addClass('hovered');
}


function display_dropdown()
{
	$('.dropdown div').show();
}

function hide_dropdown()
{
	$('.dropdown div').hide();
}
