// JavaScript Document

$(document).ready(function () {
    var prevActTab;
    $('.hpTabs').children('div').hover(
      function () {
          $(this).stop(true, false).animate({ marginTop: 0 }, 300);
          prevActTab = $(this).attr('class');
          //
      },
      function () {
          $('.hpTabs div.' + prevActTab).stop(true, false).animate({ marginTop: 202 }, 400);
          prevActTab = $(this).attr('class');
      }
    );

      // this is for the banner to simply animate regardless of other code
      var openedBanner, clickedA, index = null;
      var $banners = $('.bannerChange');
      var banner_count = $banners.length;
      $('.bannerChange').hide();

      var bannerAnimation = function () {
          index = $('.hpTabs div').index(this);
          var curBanner = $banners[index];
          if (openedBanner != curBanner) {
              $(openedBanner).fadeOut(500); $(curBanner).fadeIn(500);
              $(clickedA).removeClass('selected'); $(this).addClass('selected');
              clickedA = this; openedBanner = curBanner;
          }
          return false;
      }

      $('.hpTabs div').click(bannerAnimation).eq(0).click();
     /* window.setInterval(function () {
          if (index < (banner_count)) { $('.hpTabs div').eq(index).click(); index++; }
          else index = 0;
      }, 5000);*/
      // end of banner animation


    $('.hpTabs').children('div').click(function () {
        if ($(this).hasClass('active')) {
            $('.hpTabs .active').css('marginTop', '0px').removeClass('active').stop(true, false).animate({ marginTop: 202 }, 400);
            //
            $('.bannerChange, .bannerDefault').hide();
            $('#default').fadeIn(300);
            //
            $('.wrapper').attr('id', 'wrapper');
        }
        else {
            $('.hpTabs .active').css('marginTop', '0px').removeClass('active').stop(true, false).animate({ marginTop: 202 }, 400);
            $(this).addClass('active');
            //
            var openLink1 = $(this).attr('class');
            var openLink2 = openLink1.split(" ", 1);
            $('.bannerChange, .bannerDefault, #default').hide();
            $('#' + openLink2).fadeIn(300);
            //
            $('.wrapper').attr('id', openLink2 + 'Wrapper');
        }
    });

});

// email to a friend
function EmailLink(){
window.location = "mailto:"+"?subject=Gulf Keystone Petroleum" + "&body=" + "I thought this link might interest you:  " + document.title + "  " + location.href;
}

