// This contains all base javascript (e.g. siFR, swfobject calls, etc)

//  base.js
//  
//  Created by Matt Dills on 2011-02-24.
//  Copyright 2010 Scully Group. All rights reserved.
// 

$(document).ready(function() {

  // /////////////////////////////////////////////////////////////// cufon
  // Whitney
  Cufon.replace('#navigation a.main', {hover:true, fontFamily: 'Whitney'});
  Cufon.replace('h1', {hover:true, fontFamily: 'Whitney'});
  // Whitney Light
  Cufon.replace('blockquote', {hover:true, fontFamily: 'Whitney-Light'});
  
  //////////////////////////////////////////////////////////// clear input box fields in footer
  var focused = false;

  $("#search input.search-box").focus(function(){
    if(!focused){
      $(this).val("");
      focused = true;
    }
  });
  
  $("#contact-form input").each(function(){
    var cleared = false;
    $(this).focus(function(){
      if(!cleared){
        $(this).val("");
        clear = true;
      }
    });
  });
  
  //////////////////////////////////////////////////////////////// dropdowns
  $('#navigation ul li').each(function() {
    $(this).hover(function() {
      $(this).addClass('nav-on');
    }, function() {
      $(this).removeClass('nav-on');
    });
  });
  
  $('ul.subnav li').each(function() {
    $(this).hover(function() {
      $(this).addClass('nav-on');
    }, function() {
      $(this).removeClass('nav-on');
    });
  });
  
  // $('#footer4 img').wrap('<a href="#footervid" class="footer-video"></a>');

  ////////////////////////////////////////////////////////////// fancybox  
  $("a.footer-video").fancybox({
     'transitionIn'  : 'elastic',
     'transitionOut' : 'elastic',
     'overlayOpacity': 0.8,
     'overlayColor' : '#000',
     'speedIn'   : 600, 
     'speedOut'    : 200, 
     'titleShow' : true,
     'titlePosition' : 'inside',
     'overlayShow' : true,
     'padding' : 1
  });
  
  $("a.contact-link").fancybox({
     'transitionIn'  : 'elastic',
     'transitionOut' : 'elastic',
     'overlayOpacity': 0.8,
     'overlayColor' : '#000',
     'speedIn'   : 600, 
     'speedOut'    : 200, 
     'titleShow' : true,
     'titlePosition' : 'inside',
     'overlayShow' : true,
     'padding' : 1
  });
  
  
  // check for iOS and add ios class
  if(!((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))) {
    $("a.process-module").fancybox({
       'overlayOpacity': 0.8,
       'overlayColor' : '#000',
       'speedIn'   : 600, 
       'speedOut'    : 200,
       'overlayShow' : true,
       //'type' : 'iframe',
  	   'padding' : 1
    });
  }
  
  // process
  $("#modules .content .module").fadeTo(0, 0);
  $("#modules .hitboxes .module").mouseenter(function(){
    $("#modules .content .module:eq(" + $(this).index() + ")").fadeTo(200, 1);
  });
  $("#modules .hitboxes .module").mouseleave(function(){
    $("#modules .content .module").fadeTo(0, 0);
  });
  
  // belief module
  $("#belief .bar-text p").hide();
  $("#belief .bar-text p").first().show();
  
  $("#belief .bar a").mouseenter(function(){
    $("#belief .bar-text p").hide();
    $("#belief .bar-text p:eq(" + ($(this).index() + 1) + ")").show();
  });
  
  // team approach module
  $("#team-approach .hitboxes .module").mouseenter(function(){
    var curitem = $("#team-approach .content .module:eq(" + $(this).index() + ")");
    //curitem.fadeTo(200, 1);
    curitem.addClass("selected");
    $(this).addClass("selected");
  });
  $("#team-approach .hitboxes .module").mouseleave(function(){
    //$("#team-approach .content .module").fadeTo(0, 0);
    $("#team-approach .content .module").removeClass("selected");
    $("#team-approach .hitboxes .module").removeClass("selected");
  });
  
  // wealth management module
  $("#wealth-management .hitboxes .module").mouseenter(function(){
    var curitem = $("#wealth-management .content .module:eq(" + $(this).index() + ")");
    //curitem.fadeTo(200, 1);
    curitem.addClass("selected");
    $(this).addClass("selected");
  });
  $("#wealth-management .hitboxes .module").mouseleave(function(){
    //$("#team-approach .content .module").fadeTo(0, 0);
    $("#wealth-management .content .module").removeClass("selected");
    $("#wealth-management .hitboxes .module").removeClass("selected");
  });

	$("#trust-services .module-box").mouseenter(function(){
    $(this).addClass("selected");
  });
  $("#trust-services .module-box").mouseleave(function(){
    $(this).removeClass("selected");
  });
  
}); //end document.ready
