
jQuery(document).ready(function(){
    
       var details = new Array();
       details[0] = 'ecom';
       details[1] = 'app';
       details[2] = 'design';       
      
       jQuery('.detailbtn').click(function(){
           var id = jQuery(this).attr('id');
           jQuery.each(details, function(index, value) { 
                if(value != id){
                    jQuery('#' + value + '-detail').hide('fast');
                    jQuery('.detailbtn').attr('src','/wp-content/themes/bdi2012/images/down.png');
                }
           });
           
           if(jQuery('#' + id + '-detail').css('display') != 'block'){
                jQuery('#' + id + '-detail').fadeIn('slow');
                jQuery(this).attr('src','/wp-content/themes/bdi2012/images/up.png'); 

           } else {
                jQuery('#' + id + '-detail').fadeOut('slow');
                jQuery(this).attr('src','/wp-content/themes/bdi2012/images/down.png');  
           }
       });
    
 });


jQuery(window).scroll(function(e){
    var $nav_index = jQuery('nav').parent('li a.nav-active').index(),
        $active_nav = jQuery('nav a.nav-active'),
        $nav_items = jQuery('nav li a'),
        $sections = jQuery('#sections section'),
        $win = jQuery(window),
        scroll,
        top,
        bottom,
        section_range,
        section = Array();

    jQuery.each($sections,function(index, value) {
        top = jQuery(this).offset().top;
        bottom = jQuery(this).offset().top + jQuery(this).outerHeight();
        scroll = $win.scrollTop() + 200;      
        if(scroll > top && scroll <= bottom && index > 0){
            jQuery('nav a.nav-active').removeClass('nav-active');
            jQuery($nav_items[index + 1]).addClass('nav-active');
        } else if (scroll > top && scroll <= bottom && index == 0){
            jQuery('nav a.nav-active').removeClass('nav-active');
        }
    });
});
 

jQuery('nav').on('click','a',function(e){

    var section_id = jQuery(this).parent('li').index(),
        $sections = jQuery('#sections section'),
        $section = jQuery($sections[section_id  - 1]),
        section_offset = $section.offset(),
        that = this;
   
    console.log($sections[2]);

    if(section_id == 1){
        window.location.href = "http://www.binarydesigninc.com/blog/";    
    } else if (section_id == 0) {
    
    } else {

        // remove all active classes
        $sections.removeClass('showing');
        jQuery('#nav a').removeClass('nav-active');
        
        jQuery('html,body').animate({
            'scrollTop': section_offset.top - 14
        },{
            'duration': 250,
            'complete': function(e){
                
                // apply current active classes
                $section.addClass('showing');
                jQuery(that).addClass('nav-active');
                
                return false;
            }
        });
    }
    return false;
    
});

 
 jQuery(function(){

     var $wrapper =  jQuery('#wrapper'),
        $contact =  jQuery('#contact'),
        $x =        jQuery('#contact-close'),
        $logo =     jQuery('#logo'),
        $nav =      jQuery('#nav'),
        $handle =   jQuery('#ctHandle'),
        vOffset =   6;        

    // set default position
    $wrapper.css('margin-top', -$contact.outerHeight() + vOffset);
    
    $x.live('click', function(e){
        if($handle.hasClass('visible')){
        $wrapper.stop().animate({
            'margin-top': -$contact.outerHeight() + 6
            },{
             duration: 'slow',
              easing: 'easeInQuart',
              complete: function(){
                $handle.removeClass('visible');
                $nav.css('position','fixed');
                $logo.css('position','fixed');
                return false;
              }
        });
        }
    });     

    //bind handle
    $handle.on('click', function(e){
        
        //disable links
        e.preventDefault();

        
        if($handle.hasClass('visible')){

            // animate hide
            $wrapper.stop().animate({
                'margin-top': -$contact.outerHeight() + 6
                },{
                 duration: 'slow',
                  easing: 'easeInQuart',
                  complete: function(){
                    $handle.removeClass('visible');
                    $nav.css('position','fixed');
                    $logo.css('position','fixed');
                    return false;
                  }
            });         
        } else {
          
            // animate show
            jQuery('body').animate({
                 scrollTop: 0},{
                 duration: 100, 
                 easing: 'easeInQuart'});
            $contact.show();
            $nav.css('position','absolute');
            $logo.css('position','relative');
            $wrapper.stop().animate({
              'margin-top': 0
            },{
              duration: 'slow',
              easing: 'easeInQuart',
              complete: function(){
                $handle.addClass('visible');
                return false;
              }
            });
        }
        return false;
    });
});
