
/**
*	PRELOAD IMAGES
*/
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


jQuery.preLoadImages(	"/wp-content/themes/farvest/images/button-bg.gif", 
						"/wp-content/themes/farvest/images/button-bg-hover.gif",
						"/wp-content/themes/farvest/images/button-bg-clicked.gif",
						"/wp-content/themes/farvest/images/bg_submenu.gif",												
						"/wp-content/themes/farvest/images/slide_home_01.gif",
						"/wp-content/themes/farvest/images/slide_home_02.gif",												
						"/wp-content/themes/farvest/images/slide_home_03.gif",												
						"/wp-content/themes/farvest/images/slide_home_04.gif"												
);

jQuery(document).ready(function($) 
{
	initServicesHover();
	
	$('a[href="#"]').click(function(e)
	{
		e.preventDefault();
	}); 
	
	/**
	*	MENU
	*/
	$('#menu-bottom ul > li').hover(function()
	{
		$(this).find('ul:hidden').prepend("<li class='sub_prepend'></li>");				
		$(this).find('ul:hidden').slideDown('fast');
		
	}, function()
	{
		$(this).find('ul').slideUp('fast', function()
		{
			$(this).find('.sub_prepend').remove();
		});
	});
	
	
 	$.expr[':'].has_sub = function(e) {   
    	return $(e).children().length == 2; 
	}; 
	
	var hassub = $('#menu-bottom ul > li:has_sub a');
	hassub.addClass("no_pointer");
	

	
	/**
	*	TYPE WRITER
	*/
	$("#cycle_typewriter").cycle({
	 // fx: "scrollDown",
	  before: function() { $(this).find('p').jTypeWriter({duration:2, type:'word'}); }
	});
	/* $("#cycle_typewriter").cycle({
		 // fx: "scrollDown",
		before: function() { $(this).find('p').ticker({
			cursorList:  " ",
			rate:        10,
			delay:       4000
		}).trigger("play").trigger("stop");
	});	 */
	
	
	
	/**
	*	SLIDER HOMEPAGE
	*/
	//$('#slider_home').jshowoff({ links:false });	
	$('#slider_home').cycle({ 
		fx: "scrollDown"
	});	
	
 	$(".jshowoff-slidelinks a").css({ opacity: 0.8 });
 	$(".jshowoff-controls a").css({ opacity: 0.8 });
	
	
	/**
	*	FLOATING MENU NEWS
	*/
	/*$("#modules_home").makeFloat({x:"current",y:"current",alwaysTop:true});	 */
	 
	function initServicesHover(){
	  $('#featured li div a, #featured2 li div a').each(function(){
		/* identify children */
		var firstImg = $(this).children().eq(0);
		var secondImg = $(this).children().eq(1);
		/* set initial styles */
		$('#featured li div a img, #featured2 li div a img').css({
		  "left": "0px",
		  "position": "absolute",
		  "top": "0px"
		})
		$(secondImg).css({"opacity":0});
		$(firstImg).css({"z-index":0}); 
		$('#featured ul li span p').css({"opacity":0.5});
		/* setup hover to switch images */
		$(this).parents('li').hover(function(){
			$(this).find('span p').stop().fadeTo(170,1);		
			$(secondImg).stop().fadeTo(170,1);
			$(firstImg).stop().fadeTo(240,0);
		  }, function(){
			$(this).find('span p').stop().fadeTo(170,0.5);					  			  
			$(secondImg).stop().fadeTo(240,0);
			$(firstImg).stop().fadeTo(170,1);
		});
	  });
	 
	  
}	 
	 
	
	
	
});
