 var avatars =  {0:'tech', 1: 'creative', 2: 'marketing', 3: 'support', 4:'accountant', 5: 'legal'};
 var current_avatar = 0;
 var fadeoutime = 2000; //milli sec
 var timer_obj;
 var auto = true;

 $(document).ready(function()
 {
      // lightbox
      $('.fancyRegister').fancybox({'type':'iframe','width':482,'height':284,'padding':10});
      $('.fancyVideo').fancybox({'type':'iframe','width':640,'height':385,'padding':10});

      $('#techbutton,#creativebutton,#marketingbutton,#supportbutton,#accountantbutton,#legalbutton').click
      (function(event) {

          if(auto == true)
          {
              $('.people').stop();
              clearTimeout(timer_obj);
          }

          auto = false;
          fadeoutime = 400;
          event.preventDefault();switchavatar($(this).attr('href'));
      });

      /*** how will it work switch tabs ***/
        $('.home-block .bt-next').click(function(){
            $(this).toggleClass('bt-prev');
            no = $(this).hasClass('bt-prev')?'2':'1';
            $('.home-block .no').text(no);
            $('.work-list:visible').hide();
            $('.work-list.none').fadeIn(800).removeClass('none');
            $('.work-list:hidden').addClass('none');
        });

        /*** complete list lightbox ***/
        $('.fancybox').fancybox({
            'showCloseButton'	: true,
            'speedIn'		:	600,
            'speedOut'		:	200,
            'width'         :   730 ,
            'height'        :   548,
            'padding'       :   0,
            'titleShow'     :   true,
            'scrolling'     :   'no',
            'opacity'       :   true,
            'overlayOpacity':   0.7
        });
        $('#bt-email-friend').click(function(){
            $('#email-to-friend').toggle('slow');
        });

        $("a.bt-register").fancybox({
            'type'	:	'iframe'
	});


    // only run the auto switch if on the OfficeCavalry, NOT in the subcavalry (see views/home.php to hide #techbutton if not on main domain)
    if ($('#marketingbutton').length > 0)
    {
        timer_obj = setTimeout('autoswitch()', fadeoutime);
    }

    // transparent png fix for IE 6
    if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
      document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
     {        
        document.styleSheets[0].addRule('.transparent', 'behavior: url(' + oc.constants.base_url + 'css/iepngfix.htc)');
     }

     /*Cavalries dropdown menu*/
     $("#li-tech").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });
     $("#li-creative").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });
     $("#li-marketing").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });
     $("#li-support").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });
     $("#li-accountant").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });
     $("#li-legal").hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
         interval: 150,   // number = milliseconds for onMouseOver polling interval
         over: show,     // function = onMouseOver callback (required)
         timeout: 300,   // number = milliseconds delay before onMouseOut
         out: hide       // function = onMouseOut callback (required)
     });

     // Subscribe validation
    $("#subscribe").validate({
        errorPlacement: function(error, element) {
            /*element.parent().append('<span class="error-ico"></span>');*/
            element.parent().append(error);
        },
        /*unhighlight: function(element, errorClass, validClass) {
            //alert($(element).parent().children('.error-ico'));
            $(element).parent().children('.error-ico').remove();

        },*/
        errorClass: "error-msg",
        validClass: "valid",
        success: "check-ico",
        errorElement:'div'
    });
     
 });

function show() {
    var menu = $(this);
    menu.children(".dropdown-menu").fadeIn(200);
}

function hide() {
    var menu = $(this);
    menu.children(".dropdown-menu").hide();
}

function autoswitch()
{
    current_avatar ++;
    if(current_avatar == 6)
    {
        current_avatar = 0;
    }
    switchavatar(avatars[current_avatar]);
}

function switchavatar(avatar_class)
{
     $('.people:visible').fadeOut( fadeoutime, function(){


       $('.logos:visible').hide();
       $('.msg:visible').hide();
       $('.slide-nav li').removeClass('active');
       $('#' + avatar_class + 'button' ).parent('li').addClass('active');

       $('.' + avatar_class + 'logo' ).fadeIn(fadeoutime);
       $('.' + avatar_class + 'msg' ).fadeIn(fadeoutime);

       $('.' + avatar_class + 'avatar' ).fadeIn(fadeoutime , function(){

            if(auto == true)
            {
                timer_obj=  setTimeout('autoswitch()', fadeoutime);
            }
         });
     });
}
