pages=new Array();
pages['wedo_1']='wedo_1.html';
pages['wedo_2']='wedo_2.html';
pages['weare_1']='weare_1.html';
//pages['weare_2']='weare_2.html';
//pages['weare_3']='weare_3.html';
pages['contact_1']='contact_1.html';

pointer=new Array();
pointer['wedo']=1;
pointer['weare']=1;
pointer['contact']=1;

pagecount=new Array();
pagecount['wedo']=2;
pagecount['weare']=1;
pagecount['contact']=1;

$(document).ready(function() {	

  $('#sitelogo').click(function(){
    $('#tabMenu > li').removeClass('selected');
    if ($('#boxBody').find('div.active')) {
      $('.boxBody div.active').fadeOut('300', function(){
        $(this).hide();
        $('.boxBody div.tabs').hide();
      });
    }
  });

  $('#tabMenu > li').click(function(){
        
    if (!$(this).hasClass('selected')) {    
      $('#tabMenu > li').removeClass('selected');
      $(this).addClass('selected');
      newactive=$('.boxBody div.tabs:eq(' + $('#tabMenu > li').index(this) + ')');
      if (!$('#boxBody').find('div.active')) {
        $('.boxBody div.active').fadeOut('300', function(){
          $(this).hide();
          $('.boxBody div.tabs').hide();
          newactive.addClass('active');
          newactive.fadeIn('300');
        });
      } else {
        $('.boxBody div.active').removeClass('active');
        $('.boxBody div.tabs').hide();
        
        actid=newactive.attr('id');
        pointer[actid]=1;
        
        newactive.find('div.content').load(pages[actid + '_' + pointer[actid]], function(){
          $(this).width($(this).find('div.wrapper').outerWidth(true));
        });
        
        if (pointer[actid]>1) { newactive.find('span.leftarrow').show(); } else { newactive.find('span.leftarrow').hide(); }
        if (pointer[actid]<pagecount[actid]) { newactive.find('span.rightarrow').show(); } else { newactive.find('span.rightarrow').hide(); }
        
        newactive.fadeIn('300', function() {
          $(this).show();
          $(this).addClass('active');
        });
      }
    } else {
      $(this).removeClass('selected');
      if ($('#boxBody').find('div.active')) {
        $('.boxBody div.active').fadeOut('300', function(){
          $(this).hide();
          $('.boxBody div.tabs').hide();
        });
      }
    }

  }).mouseover(function() {

    $(this).addClass('mouseover');
    $(this).removeClass('mouseout');   
    
  }).mouseout(function() { 
    
    $(this).addClass('mouseout');
    $(this).removeClass('mouseover');    
    
  });

  $('span.arrow').click(function(){
        
    if ($(this).hasClass('leftarrow')) {
      $(this).parents('div.tabs').fadeOut(300, function (){
        var actid=$(this).attr('id');
        pointer[actid]=pointer[actid]-1; 
        $(this).find('div.content').load(pages[actid + '_' + pointer[actid]], function(){
          $(this).parents('div.tabs').width($(this).find('div.wrapper').outerWidth(true));
        });
        if (pointer[actid]>1) { $(this).find('span.leftarrow').show(); } else { $(this).find('span.leftarrow').hide(); }
        $(this).find('span.rightarrow').show();
        $(this).fadeIn(300);
      });    
    } else if ($(this).hasClass('rightarrow')) {
      $(this).parents('div.tabs').fadeOut(300, function (){
        var actid=$(this).attr('id');
        pointer[actid]=pointer[actid]+1;
        $(this).find('div.content').load(pages[actid + '_' + pointer[actid]], function(){
          $(this).parents('div.tabs').width($(this).find('div.wrapper').outerWidth(true));
        });
        $(this).find('span.leftarrow').show();
        if (pointer[actid]<pagecount[actid]) { $(this).find('span.rightarrow').show(); } else { $(this).find('span.rightarrow').hide(); }
        $(this).fadeIn(300);
      });
    }
  });
});
