(function($) {
	$(document).ready(function() {
		
		// Add .hover Classes
			jQuery('.projectTools li, .resumeTable tr.content').hover(
			   function(){ $(this).addClass('hover') },
			   function(){ $(this).removeClass('hover') }
			)
			
		$('.portfolio-item').live('mouseenter', function() { // mousein
			$(this).find('.portfolio-meta').fadeIn(350);
		}).live('mouseleave', function() { // mouseout
			$(this).find('.portfolio-meta').fadeOut(350);
		});
		
		$('#top .portfolio-slider').cycle({
			'fx' : 'scrollHorz',
			'timeout' : 6500,
			'pager' : '#portfolio-pager',
			pause: 'true',
			prev: '#left-arrow',
    		next: '#right-arrow'
		});
		
		$('.portfolio-single .portfolio-item-images .portfolio-images').cycle({
			'fx' : 'fade',
			'timeout' : 5000,
			//'before': onAfter,
			'pager' : '#portfolio-pager',
			pause: 'true',
			prev: '#left-arrow',
    		next: '#right-arrow'
		});

			function onAfter(curr, next, opts, fwd) {
			var index = opts.currSlide;
			$('#prev')[index == 0 ? 'hide' : 'show']();
			$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
			//get the height of the current slide
			var $ht = $(this).height();
			//set the container's height to that of the current slide
			$(this).parent().animate({
				'height' : $ht
			});
			}
			
			// PrettyPhoto
		  	jQuery("a[rel^='prettyPhoto']").prettyPhoto({social_tools: false, deeplinking: false, modal: false, overlay_gallery: false,theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
});

		
		// Superfish Menu

		
		$('#navigation li ul li:nth-child(2)').addClass('second-item');
		$('#navigation li ul li:last-child').addClass('last-item');
		$('#navigation li ul li:first-child').removeClass('last-item').addClass('first-item');
		
		//center menu under main menu item
		$('.sf-menu > li').each(function() {
			var $ul = $(this).children('ul');
			//console.log($ul);
			var width = $(this).width();
			//console.log(width);
			$ul.css('left', (-((151 - width - 40) / 2)) + 'px')
		});
		
		$('#navigation li ul').each(function() {
			if ($(this).children('li').length == 1) {
				//console.log($(this).children().length);
				$(this).addClass('single');
			}
		});


		
		
		// tabs
		//When page loads...
		$(".tab-content").hide(); //Hide all content
		$("ul.sidebar-tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab-content:first").show(); //Show first tab content

		//On Click Event
		$("ul.sidebar-tabs li").click(function() {

			$("ul.sidebar-tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab-content").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});	
		
		$.validator.setDefaults({
			submitHandler: function() {
				$('#contact-form').remove('.responseText');
				$('#contact-form').append('<h3 class="responseText">Sending message...</h3>');
				
				var name = $("#name").val();  
				var email = $("#email").val(); 
				var message = $("#comment").val(); 

				var dataString = 'name='+ name + '&email=' + email + '&message=' + message;  

					$.ajax({

					url: "mail.php",
					data: dataString,
					type: "GET",
					success: function(responseText) {
							$('.responseText').text(responseText);

							}
					});
			}
		});

		$("#contact-form .comment-form").validate();
		
	});
	
	
	
	
})(jQuery);
