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

//  base.js
//  
//  Created by Matt Dills on 2010-10-05.
//  Copyright 2010 Scully Group. All rights reserved.
// 

$(document).ready(function() {
  
  /////// CUFON
  
  // Helvetica Bold
  Cufon.replace('#top-nav ul li a', {hover: true, fontFamily: 'Helvetica'});
  Cufon.replace('h1', {fontFamily: 'Helvetica'});
  Cufon.replace('testimonials p.author', {fontFamily: 'Helvetica'});

  // Helvetica Bold Italic
  Cufon.replace('.home-feature h1', {fontFamily: 'Helvetica Italic'});
  Cufon.replace('#interior-left h2', {fontFamily: 'Helvetica Italic'});


  // dropdowns
  $('#main-nav ul li').each(function() {
    $(this).hover(function() {
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
    });
  });
  
  // // add dividers to footer navigation  
  $('#footer-content ul.nav-first li:not(:first)').before('<li>|</li>');
  $('#footer-content ul.nav-last li:not(:first)').before('<li>|</li>');
  
  //shuffle the features
  $("#logo-wrap ul li").shuffle();
  
  //arrow click events
  $("#clients .left-arrow").click(function(){
    scrollLeft(false);
    return false;
  });
  $("#clients .right-arrow").click(function(){
    scrollRight(false);
    return false;
  });
  
  //create variable for the logo scroller
	var features = $("#clients");
	var animating = false;
	var scrollWidth = "250";

	//create the automatic animation
	features.everyTime(6000, "slider", function() {
		scrollLeft(true);
	});
  
  //function to scroll logos left
	function scrollLeft(clear){
		//stop the timer
		if(!clear){
			features.stopTime("slider");
		}

		if(!animating){
			animating = true;

			$("#logo-wrap ul").animate({"marginLeft":"-" + scrollWidth + "px"}, 1200, function(){
        var clone = $("#logo-wrap ul li:first").clone();
				$("#logo-wrap ul li:first").remove();

				//set the margin left
				$("#logo-wrap ul").css("marginLeft", "0px");

				//append the cloned element to the end
				$("#logo-wrap ul").append(clone);

				//set the animating to false
				animating = false;
			});
		}
	}
	
	function scrollRight(clear){
		//stop the timer
		if(!clear){
			features.stopTime("slider");
		}

		if(!animating){
			animating = true;
      
      var clone = $("#logo-wrap ul li:last").clone();
			$("#logo-wrap ul li:last").remove();
			
      //append the cloned element to the end
			$("#logo-wrap ul").prepend(clone);
      $("#logo-wrap ul").css("marginLeft", "-" + scrollWidth + "px");
			$("#logo-wrap ul").animate({"marginLeft":"0px"}, 1200, function(){
				animating = false;
			});
		}
	}
 
}); //end document.ready
