(function($) {
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
})(jQuery);

$(document).ready(function(){	
	$(document).ready(function () {
			$('#containerIndex').slideDown("slow");
			$('#containerIndex').animate({"opacity" : 0,"opacity" : .85 }, "normal");
			$('#slideshow').show();
			$('<img src="images/jpg/winter.jpg"/>')
			$('<img src="images/jpg/spring.jpg"/>')
			$('<img src="images/jpg/summer.jpg"/>')
			$('<img src="images/jpg/autumn.jpg"/>')
			$('<img src="images/jpg/space.jpg"/>')
		});
});


$(document).ready(function(){

	$('#listMenu a').click(function (selected) {
			
			var getName = $(this).attr("name");
			var getColor = $('#' + getName ).css('background-color');
			
			$('#containerIndex').hide()
			$('#containerDesigner').hide();
			$('#containerDeveloper').hide();
			$('#containerDatabase').hide();
			$('#containerVideo').hide();
			$('#containerAcademia').hide();
			$('#containerPhilosophy').hide();
			$('#containerAbout').hide();
			$('#containerContact').hide();

			$(function() {
				$("#" + getName ).show("normal");
				$('#header' ).css('background-color', getColor);
				$('#menuContainer').css('background-color', getColor);
				$('#slideshow' ).css('background-color', getColor);
				$('span').css('background-color', getColor);
				$('li.listMenu ul').hide();
				
			});
			
	});
			
});

$(document).ready(function() {
  var toggle = function(direction, display) {
    return function() {
      var self = this;
      var ul = $("ul", this);
      if( ul.css("display") == display && !self["block" + direction] ) {
        self["block" + direction] = true;
        ul["slide" + direction]("slow", function() {
          self["block" + direction] = false;
        });
      }
    };
  }


$(function () {
		$('#show_menu'). hover(function() {
		$('#listMenu').slideDown("slow");			
	});
});


$(function () {
		$('#reach_me'). click(function() {
		$('#header').css('background', '#3f6a97');	
		$('#containerContact').fadeIn("slow");
		$('#containerContact').animate({"opacity" : 0,"opacity" : .85 }, "normal");		
		$('#slideshow').css('background', '#3f6a97');
		$('#slideshow').animate({"opacity" : 0,"opacity" : .85 }, "normal");
		$("span").css('background', '#3f6a97');
		$("span").animate({"opacity" : 0,"opacity" : .85 }, "normal");
					
		$('#containerIndex').hide();
		$('#containerDesigner').hide();
		$('#containerDeveloper').hide();
		$('#containerDatabase').hide();
		$('#containerVideo').hide();
		$('#containerAcademia').hide();
		$('#containerPhilosophy').hide();
		$('#containerAbout').hide();
				
		$("li.listMenu ul").hide();
	});
});

  $("li.listMenu").hover(toggle("Down", "none"), toggle("Up", "block"));
  $("li.listMenu ul").hide();
});


$(document).ready(function(){
	$(function() {

		$('a#learnmore_php').hover(function(e) {
			var html = '<div id="info" class="">';
			html +=    '<h4>My PHP Web Site</h4>';
			html +=	   '<p>This site was designed in December 2009 and features PHP and MySQL.</p>';
			html +=		'</div>';
						
			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
			
		}, function() {
			$('#info').remove();
		});
	
		$('a').mousemove(function(e) {
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
		});
	});
});

$(document).ready(function(){
	$(function() {

		$('a#learnmore_flex').hover(function(e) {
			var html = '<div id="info" class="">';
			html +=    '<h4>My Flex Web Site</h4>';
			html +=	   '<p>This site was designed in August 2009 and features Flex Builder Professional.</p>';
			html +=		'</div>';
						
			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
			
		}, function() {
			$('#info').remove();
		});
	
		$('a').mousemove(function(e) {
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
		});
	});
});

$(document).ready(function(){
		$(function() {

		$('a#learnmore_homestead').hover(function(e) {
			var html = '<div id="info" class="">';
			html +=    '<h4>My First Web Site</h4>';
			html +=	   '<p>This site was designed in January 2001 and is hosted freely.</p>';
			html +=		'</div>';

			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);

		}, function() {
			$('#info').remove();
		});

		$('a').mousemove(function(e) {
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
		});
	});
});

$(document).ready(function(){
		$(function() {

		$('a#learnmore_agentdashboard').hover(function(e) {
			var html = '<div id="info" class="">';
			html +=    '<h4>My Agent Dashboard</h4>';
			html +=	   '<p>This App. was designed in December 2009 featuring Javascript, Ajax, PHP and MySQL.</p>';
			html +=		'</div>';

			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);

		}, function() {
			$('#info').remove();
		});

		$('a').mousemove(function(e) {
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
		});
	});
});

$(document).ready(function(){
		$(function() {

		$('a#learnmore_cms').hover(function(e) {
			var html = '<div id="info" class="">';
			html +=    '<h4>My Content Management System</h4>';
			html +=	   '<p>My CMS. was designed in December 2009 and features PHP and MySQL.</p>';
			html +=		'</div>';

			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);

		}, function() {
			$('#info').remove();
		});

		$('a').mousemove(function(e) {
			$('#info').css('top', e.pageY + +20).css('left', e.pageX + 10);
		});
	});
});

/*-- page themes --*/

$(function() {

	$('a#winter').hover(function(e) {
		var html = '<div id="info1" class="">';
		html +=    '<h4>Winter Theme</h4>';
		html +=	   '<img src="images/jpg/winter_popup.jpg" alt="image" />';
		html +=	   '</div>';
						
		$('body').append(html).children('#info1').hide().fadeIn(400);
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
			
	}, function() {
		$('#info1').remove();
	});
	
	$('a').mousemove(function(e) {
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
	});
});


$(function() {

	$('a#spring').hover(function(e) {
		var html = '<div id="info1" class="">';
		html +=    '<h4>Spring Theme</h4>';
		html +=	   '<img src="images/jpg/spring_popup.jpg" alt="image" />';
		html +=	   '</div>';
						
		$('body').append(html).children('#info1').hide().fadeIn(400);
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
			
	}, function() {
		$('#info1').remove();
	});
	
	$('a').mousemove(function(e) {
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
	});
});

$(function() {

	$('a#summer').hover(function(e) {
		var html = '<div id="info1" class="">';
		html +=    '<h4>Summer Theme</h4>';
		html +=	   '<img src="images/jpg/summer_popup.jpg" alt="image" />';
		html +=	   '</div>';
						
		$('body').append(html).children('#info1').hide().fadeIn(400);
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
			
	}, function() {
		$('#info1').remove();
	});
	
	$('a').mousemove(function(e) {
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
	});
});

$(function() {

	$('a#autumn').hover(function(e) {
		var html = '<div id="info1" class="">';
		html +=    '<h4>Autumn Theme</h4>';
		html +=	   '<img src="images/jpg/autumn_popup.jpg" alt="image" />';
		html +=	   '</div>';
						
		$('body').append(html).children('#info').hide().fadeIn(400);
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
			
	}, function() {
		$('#info1').remove();
	});
	
	$('a').mousemove(function(e) {
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
	});
});


$(function() {

	$('a#space').hover(function(e) {
		var html = '<div id="info1" class="">';
		html +=    '<h4>Space Theme</h4>';
		html +=	   '<img src="images/jpg/space_popup.jpg" alt="image" />';
		html +=	   '</div>';
						
		$('body').append(html).children('#info1').hide().fadeIn(400);
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
			
	}, function() {
		$('#info1').remove();
	});
	
	$('a').mousemove(function(e) {
		$('#info1').css('top', e.pageY + +10).css('left', e.pageX + 10);
	});
});

$(document).ready(function(){
function clearForms() 	{ 	  
	var i; 	  for (i = 0; (i < document.forms.length); i++) 
	{ 	    document.forms[i].reset(); 	  
		} 	
	} ;
});


$(document).ready(function(){
	$slideshow = {
	    context: false,
	    tabs: false,
	    timeout: 4000,      // time before next slide appears (in ms)
	    slideSpeed: 150,   // time it takes to slide in each slide (in ms)
	    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
	    fx: 'scrollRight',   // the slide effect to use
    
	    init: function() {
		
		
	        // set the context to help speed up selectors/improve performance
	        this.context = $('#slideshow');
        
	        // set tabs to current hard coded navigation items
	        this.tabs = $('ul.slides-nav li', this.context);
        
	        // remove hard coded navigation items from DOM 
	        // because they aren't hooked up to jQuery cycle
	        this.tabs.remove();
        
	        // prepare slideshow and jQuery cycle tabs
	        this.prepareSlideshow();
	    },
    
	    prepareSlideshow: function() {
	        // initialise the jquery cycle plugin -
	        // for information on the options set below go to: 
	        // http://malsup.com/jquery/cycle/options.html
	        $('div.slides > ul', $slideshow.context).cycle({
	            fx: $slideshow.fx,
	            timeout: $slideshow.timeout,
	            speed: $slideshow.slideSpeed,
	            fastOnEvent: $slideshow.tabSpeed,
	            pager: $('ul.slides-nav', $slideshow.context),
	            pagerAnchorBuilder: $slideshow.prepareTabs,
	            before: $slideshow.activateTab,
	            pauseOnPagerHover: true,
	            pause: true
	        });            
	    },
    

	    prepareTabs: function(i, slide) {
	        // return markup from hardcoded tabs for use as jQuery cycle tabs
	        // (attaches necessary jQuery cycle events to tabs)
	        return $slideshow.tabs.eq(i);
	    },

	    activateTab: function(currentSlide, nextSlide) {
	        // get the active tab
	        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
	        // if there is an active tab
	        if(activeTab.length) {
	            // remove active styling from all other tabs
	            $slideshow.tabs.removeClass('on');
            
	            // add active styling to active button
	            activeTab.parent().addClass('on');
	        }            
	    } 
          
	};

});

$(document).ready(function(){
	$(function() {
	    // add a 'js' class to the body
	    $('body').addClass('js');
    
	    // initialise the slideshow when the DOM is ready
	    $slideshow.init();
	}); 
});