/*
 * base.js
 * Primary Javascript file.
 */
 

function initMenu() {
    
    if ($('li.current-menu-item').length == 0) {
        return;
    };
    
    // append pointer to menu
    $(".menu").append('<div class="pointer"></div>');
    
    // get the half the width of the pointer so that we can center it properly
    var pointerOffset = ($('.pointer').width() / 2);

    // set the easing transition
    // var style = 'jswing';  
    var style = 'swing';
      
    // retrieve the selected item position and width  
    var default_left = Math.round($('.menu li.current-menu-item').offset().left - $('.menu').offset().left);  
    var default_width = $('.menu li.current-menu-item').width();

    // calculate where we need to initially position the pointer
    default_left = default_left + (default_width / 2) - pointerOffset;

    // position the pointer. this is the middle of the selected item
    $('.pointer').css({left: default_left});
  
    // if mouseenter a menu item  
    $('.menu li').mouseenter(function () {  
          
        // get the position and width of the moused menu item  
        var new_left = Math.round($(this).offset().left - $('.menu').offset().left);  
        var new_width = $(this).width();   
        
        // calculate how far we're going to move the pointer
        new_left = new_left + (new_width / 2) - pointerOffset;
        
        // animate the pointer to the moused item
        $('.pointer').stop(false, false).animate({left: new_left},{duration:300, easing: style});        
      
    // if user clicks on a menu item
    }).click(function () {  
                  
        // remove the selected class from all menu items
        $('.menu li').removeClass('current-menu-item');    
          
        // add the 'selected' class to the clicked item
        $(this).addClass('current-menu-item');  
  
    });  
      
    // if the mouse leaves the menu, reset the pointer to the selected item  
    $('.menu').mouseleave(function () {  
  
        // retrieve the selected item position and width  
        default_left = Math.round($('.menu li.current-menu-item').offset().left - $('.menu').offset().left);  
        default_width = $('.menu li.current-menu-item').width();  
        
        // calculate how far we're going to move the pointer
        default_left = default_left + (default_width / 2) - pointerOffset;
        
        // animte the pointer to the 'selected' item
        $('.pointer').stop(false, false).animate({left: default_left},{duration:300, easing: style});     
          
    });
    
} 

function initBillboard() {

    $('#coin-slider').coinslider({
        width: 750, // width of slider panel
        height: 300, // height of slider panel
        spw: 11, // squares per width
        sph: 3, // squares per height
        delay: 8000, // delay between images in ms
        sDelay: 30, // delay beetwen squares in ms
        opacity: 0.7, // opacity of title and navigation
        titleSpeed: 500, // speed of title appereance in ms
        effect: '', // random, swirl, rain, straight
        navigation: false, // prev next and buttons
        links : false, // show images as links 
        hoverPause: true // pause on hover
    });
    
}

function initTweets() {

    $(".tweet").tweet({
        username: "salonintuitions",
        count: 3,
        loading_text: "<span class='tweet_loading'>Loading Tweets...</span>"
    });
    
}

 
$(document).ready(function(){
    
    initBillboard();
    
    
});

$(window).load(function(){
    
    initMenu();
    initTweets();
    $('.stylists').masonry({ singleMode: true });
    
});
