$.preloadImages = function() {
    for(var i = 0; i < arguments.length; i++) {
        $('<img />').attr('src', arguments[i]);   
    } 
}

$(document).ready(function() {	
	$.preloadImages(
        'wp-content/themes/mohldesign/images/caruselimg/slide2.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide3.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide4.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide5.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide6.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide7.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide8.png',
        'wp-content/themes/mohldesign/images/caruselimg/slide9.png'
    );
    
    
    
    /* --- Here starts the twitter feed --- */
    
    
	
    $(".tweet").tweet({
        join_text: null,
        avatar_size: 32,
        count: 3,
        auto_join_text_default: "we said,",
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied to",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
    });
    
    
    
    /* --- Here starts the horizontal gallery scroll --- */
    
    
    
	$("#slider").easySlider({
		auto: true,
		continuous: true
	});
	
	
	
	/* --- Here starts the scroll code for same page links --- */
	
	
    
	$(document).ready(function() {
      $('.scroll').smoothScroll();

	      $('p.subnav a').click(function(event) {
	        event.preventDefault();
	        var link = this;
	        $.smoothScroll({
	          scrollTarget: link.hash
	        });
	      });
	
	      $('button.scrollsomething').click(function() {
	        $.smoothScroll({
	          scrollElement: $('div.scrollme'),
	          scrollTarget: '#findme'
	        });
	        return false;
	      });
      });
      
      
      
      /* --- Top of page plugin --- */
      
      
      
      jQuery.fn.topLink = function(settings) {
		settings = jQuery.extend({
				min: 1,
				fadeSpeed: 200
			}, settings);
			return this.each(function() {
				//listen for scroll
				var el = $(this);
				el.hide(); //in case the user forgot
				$(window).scroll(function() {
					if($(window).scrollTop() >= settings.min)
					{
						el.fadeIn(settings.fadeSpeed);
					}
					else
					{
						el.fadeOut(settings.fadeSpeed);
					}
				});
			});
		};
		
		//usage w/ smoothscroll
		$(document).ready(function() {
			//set the link
			$('#top-link').topLink({
				min: 400,
				fadeSpeed: 500
			});
			//smoothscroll
			$('#top-link').click(function(e) {
				e.preventDefault();
				$.scrollTo(0,300);
			});
		});
		
		
		
		/* --- Tooltip --- */
		
		
		
		$(document).ready(function() {  
  
			//Select all anchor tag with rel set to tooltip  
			$('a[rel=tooltip]').mouseover(function(e) {  
			      
			    //Grab the title attribute's value and assign it to a variable  
			    var tip = $(this).attr('title');      
			      
			    //Remove the title attribute's to avoid the native tooltip from the browser  
			    $(this).attr('title','');  
			      
			    //Append the tooltip template and its value  
			    $(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');       
			      
			    //Set the X and Y axis of the tooltip  
			    $('#tooltip').css('top', e.pageY + 5 );  
			    $('#tooltip').css('left', e.pageX + 5 );  
			      
			    //Show the tooltip with faceIn effect  
			    $('#tooltip').fadeIn('500');  
			    $('#tooltip').fadeTo('10',1);  
			      
			}).mousemove(function(e) {  
			  
			    //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse  
			    $('#tooltip').css('top', e.pageY - 50 );  
			    $('#tooltip').css('left', e.pageX - 30 ); 
			      
			}).mouseout(function() {  
			  
			    //Put back the title attribute's value  
			    $(this).attr('title',$('.tipBody').html());  
			  
			    //Remove the appended tooltip template  
			    $(this).children('div#tooltip').remove();  
			      
			});  
			
		});  


});

