jQuery(document).ready(function(){

  // set bg color of input submit buttons
  jQuery('input[type=submit]').css('backgroundColor','#555');
  jQuery("a[hrefjQuery=.jpg],a[hrefjQuery=.jpeg],a[hrefjQuery=.png]").addClass('nyroModal');
  

//set content height for asthetic footer when content height is less than window height
  var windowheight = jQuery(window).height();
  var topheight = jQuery('.main-slideshow').height();
  var widecolheight = jQuery('.wide-column').height();
  var sidebarheight = jQuery('.narrow-column').height();
  if (windowheight > topheight + sidebarheight - 120) {
	  jQuery('.wide-column').css('min-height', windowheight - topheight - 120);
  }
  
  
  //set sidebar height 

  jQuery('.narrow-column').css('height',widecolheight);
  
  
  // set nav opacity
  jQuery('.menu li a').css('opacity',0.7);



  //smooth scrolling
  jQuery('.menu').localScroll({
	 hash: false,
	 easing: 'swing',
	 duration:500
  });



  // scroll to top when you click the icon
  jQuery('#header .icon').localScroll({
	 hash: false,
	 easing: 'swing',
	 duration:500
    }).click(function(){
	jQuery(".arrow").animate({
	  "marginTop": '50'
      }, 500,'swing');
    if(jQuery.support.opacity) {
		jQuery('.menu li a').removeClass('selected').css('opacity',0.7);
	}
	jQuery(this).addClass('selected');
  });
  
  // Slideshow & Nav

  
  if ((jQuery('.slideshow-nav').length != 0)) {
  	if ((jQuery('.autoplayslideshow').length != 0)) {
  		jQuery("#browsable").scrollable({circular: true}).autoscroll({ autoplay: true, autopause: true, interval: 4000 }).navigator();
  		var api = jQuery("#browsable").data("scrollable");
  		jQuery('.slideshow-buttons a').click(function(){
  			api.pause();
  		});
  		
 	}
 	else {
 		jQuery("#browsable").scrollable().navigator();
 	}
  }
  
	if ((jQuery('.slideshow-buttons > a').size()) == 1) {
		jQuery('.slideshow-buttons').hide();
	}

  // Nav header fade
  if(jQuery.support.opacity) {
	  jQuery(".menu li a").hover(
	    function () {
	      jQuery(this).not(".menu li a.selected").fadeTo("350", 1);
	    }, 
	    function () {
	      jQuery(this).not(".menu li a.selected").fadeTo("350", 0.7);
	    }
	  );
  }



  // nav click
  // mousedown
  jQuery(".menu li a").mousedown(function(){
    jQuery(this).css({
		'marginLeft':'3px',
		'marginBottom':'7px',
		'marginTop':'7px',
		'padding':'17px 25px',
		'opacity':0.9
	});
  });
  

  // mouseup
  var clickedItem = null;
  var animateTo = null;

  jQuery(".menu li").mouseup(function(){
  	
	jQuery('.menu li a').removeClass('selected').css('opacity',0.7);
	jQuery('#header .icon').removeClass('selected');
    jQuery('a',this).css({
		'marginLeft':'0px',
		'marginBottom':'6px',
		'marginTop':'0',
		'padding':'18px 25px',
		'opacity':1
	});
	jQuery('a',this).addClass('selected');
	
	
	
	// figure out where to animate the arrow to
	clickedItemPosition = jQuery(this).position().top;
	clickedItemHeight = jQuery(this).height() / 2;
	animateTo = clickedItemPosition + clickedItemHeight - 20;
	jQuery("#header .arrow").animate({
	  "marginTop": animateTo
	}, 500,'swing');
  });






// sticky sidebar
if (jQuery('.stickySidebar').length != 0) {
  var sidebarYloc = null;
  sidebarYloc = jQuery('.stickySidebar').offset();
  sidebarYloc = sidebarYloc.top;


  	if (sidebarYloc < jQuery(document).scrollTop()) {
		jQuery('.stickySidebar').addClass('fixed');
	}
	else {
		jQuery('.stickySidebar').removeClass('fixed');
	}

	jQuery(document).scroll(function () { 
		if (sidebarYloc < jQuery(document).scrollTop()) {
			jQuery('.stickySidebar').addClass('fixed');
		}
		else {
			jQuery('.stickySidebar').removeClass('fixed');
		}
	});
}
  


  // if hash in url, highlight proper nav section
  if(window.location.hash) {
	  var currenthash = window.location.hash;
	  if (currenthash != '#top') {
	  	jQuery('.menu li a[href*='+currenthash+']').addClass('selected').css('opacity',1);
	  	var currentSelectedItemOffset = jQuery('.menu li a[href*='+currenthash+']').parent().position().top;
	  	var currentItemHeight = jQuery('.menu li a[href*='+currenthash+']').height() / 2 + currentSelectedItemOffset - 3;
	  	jQuery("#header .arrow").css('marginTop',currentItemHeight);
	  }
  } 



  // contact form
  if (jQuery('#contactForm').length != 0) {
	
	var temppath = jQuery('#contactForm .submitpath').val() + '/contact_submit.php';
  	jQuery("#contactForm").validate({
     	submitHandler: function(form) {
     		jQuery(form).ajaxSubmit({
	    		target: ".contact",
				url: temppath
    		});
     	}
  	})

  	jQuery('#contactForm').ajaxStart(function() {
		jQuery('.onesec').show();
	});
	
  	jQuery('#contactForm').ajaxStop(function() {
		jQuery('.onesec').hide();
	});

  	jQuery('.contact-submit').click(function(){
  		jQuery('#contactForm').submit(); 
  	});
  }


  // set bg color of input submit buttons
  jQuery('input[type=submit]').css('backgroundColor','#555');
  
  
  //tooltips
  jQuery(".facebook, .twitter, .feed, .appstore, .buynow").tipTip({delay: 0});
  
  
}); // end doc ready





