// 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
  // 
  // Helvetica Condensed Bold
  Cufon.replace('h1', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('h2', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('h3', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('h4', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('#subnav-repeat ul li a', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('.button a', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('.floorplan-preview h2 a', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('#content-center ul.floorplans li a', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('#footer-left p.footer-mail a span.replace', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('#footer-left label', {hover:true, fontFamily: 'Helvetica'});
  Cufon.replace('#footer-left li.follow', {hover:true, fontFamily: 'Helvetica'});
  
  Cufon.replace('.slide-description h3', {hover:true, fontFamily: 'Adobe Caslon Pro'});
  

  /////////////////////////////////////////////////////////// fancybox
  $(".flickr-gallery a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.88,
		'showNavArrows'   : true,
		'showCloseButton' : true
  });
  
  /////////////////////////////////////////////////////////// fancybox
  $(".floorplan-facebox").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titleShow'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.88,
		'showNavArrows'   : true,
		'showCloseButton' : true,
		'onComplete'      : function(links, index){
		  var fancyboxTitle = $("#fancybox-title-inside")
		  var self = $(links[index]);
		  var print = self.attr("href");
		  var large = self.attr("href").replace("/normal/", "/original/");
		  
		  //empty the current title and append the links to fancybox
		  fancyboxTitle.empty();
		  fancyboxTitle.append('<a target="_blank" href="' + print + '"><img src="/images/printicon.gif">Printable Image</a>');
		  fancyboxTitle.append('<span>|</span>');
		  fancyboxTitle.append('<a target="_blank" href="' + large + '"><img src="/images/zoom.gif">View Larger</a>');
		}
  });
  
  /////////////////////////////////////////////////////////// green products fancybox
  $("a.green-fancybox").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.65,
		'showNavArrows'   : true,
		'padding'         : 0,
		'showCloseButton' : true
  });
  
  /////////////////////////////////////////////////////////// fancybox
  $("a.home-video").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.88,
		'showNavArrows'   : true,
		'showCloseButton' : true
  });
  
  /////////////////////////////////////////////////////////// left & right rail video fancybox
  $("#content-right .video a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.88,
		'showNavArrows'   : true,
		'showCloseButton' : true
  });

  $("#content-left .video a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titlePosition'		: true,
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.88,
		'showNavArrows'   : true,
		'showCloseButton' : true
  });

  
  $(".youtube").click(function() {
  	$.fancybox({
  			'padding'		: 0,
  			'autoScale'		: false,
  			'transitionIn'	: 'none',
  			'transitionOut'	: 'none',
  			'title'			: this.title,
  			'width'		: 680,
  			'height'		: 495,
  			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
  			'type'			: 'swf',
  			'swf'			: {
  			   	 'wmode'		: 'transparent',
  				'allowfullscreen'	: 'true'
  			}
  		});

  	return false;
  });
  
  //////////////////////////////////////////////////////////////// add dividers to navigation elements
  // $('#header-content ul li:not(:first)').before('<li>|</li>');
  
  $('.megamenu ul').each(function(){
    $(this).children().first().addClass('first');
  });
  
  
  /////////////////////////////////////////////////////////////// javascript for floorplan nav 
  
  $('#content-center ul.floorplans li:not(:first)').before('<li class="spacer"></li>');

  // $('#content-center ul.floorplans li').each(function() {
  //   $(this).hover(function() {
  //     $(this).addClass('nav-on');
  //   }, function() {
  //     $(this).removeClass('nav-on');
  //   });
  // });
  
  //////////////////////////////////////////////////////////////// header dropdowns & MEGA MENUS
  $('#header-content ul li').each(function() {
    $(this).hover(function() {
      $(this).addClass('nav-on');
    }, function() {
      $(this).removeClass('nav-on');
    });
  });
  
  $('#navigation ul li').each(function() {
    $(this).hover(function() {
      $(this).addClass('nav-on');
    }, function() {
      $(this).removeClass('nav-on');
    });
  });	
  
  //////////////// show mega menu content for each nav item
  $('#navigation .megamenu li.first .megacontent').show();

  $('#navigation ul li .megamenu ul li').each(function(){
    $(this).hover(function(){
      $(this).children('.megacontent').show();
      $('#navigation .megamenu li.first .megacontent').hide();
      if($(this).hasClass('first')){
        $('#navigation .megamenu li.first .megacontent').show();
      }
    }, function(){
      $(this).children('.megacontent').hide();
      $('#navigation .megamenu li.first .megacontent').show();
    });
  });
  
  $('.interior-feature').each(function(){
    $(this).children().last().addClass('button');
  });
  
  //////////////////////////////////////////////////////////// clear input box fields in footer
  var focused = false;

  $("#mailer input").focus(function(){
    if(!focused){
      $(this).val("");
      focused = true;
    }
  });
  
  var searchfocus = false;
  
  $("#search-form input").focus(function(){
    if(!searchfocus){
      $(this).val("");
      searchfocus = true;
    }
  });
  
  // testimonial js
  $("#testimonials p").shuffle();
  $("#testimonials p").hide().first().show();
  
  var first = $("#testimonials p").first();
  var text = first.text();
  var textArray = text.split(" - ");
  first.html(textArray[0] + "<br /><span>&mdash;" + textArray[1] + "&mdash;</span>");
  
  //$("#slide").load("/filmstrip", function(){});
}); //end document.ready
