/*
 * Scripts
 *
 */
 
jQuery(function($) {
 
	var Engine = {
		// work samples
		port : {
			init : function(){
				samplez = $('#port');
				this.count = samplez.find('div.project').size();
				
				if(this.count < 2) return;
				samplez.find('div.project:first').before('<ul class="index"><li class="prev"><a href="#prev">&laquo;</a></li><li class="next"><a href="#next">&raquo;</a></li></ul>');
				
				samplez.find('ul.index').click(function(e){
					e.preventDefault();
					
					if($(e.target).is('a') && samplez.find('div.project:animated').size() == 0){
						samplez.find('div.project:visible').fadeOut(700,function(){
							
							if($(e.target).parent().hasClass('prev')){
								var show = $(this).prev('div.project').size() > 0 ? $(this).prev('div.project') : samplez.find('div.project:last');
							} else {
								var show = $(this).next('div.project').size() > 0 ? $(this).next('div.project') : samplez.find('div.project:first');
							}
							show.fadeIn(700);
						});
					}
				});
			}
		},
		// testimonials
		testimonials : {
			init : function(){
				testimonialz = $('#testimonials');
				this.count = testimonialz.find('div.testimonial').size();
				
				if(this.count < 2) return;
				testimonialz.find('div.testimonial:last').after('<ul class="index"><li class="prev"><a href="#prev">&laquo;</a></li><li class="next"><a href="#next">&raquo;</a></li></ul>');
				
				testimonialz.find('ul.index').click(function(e){
					e.preventDefault();
					
					if($(e.target).is('a') && testimonialz.find('div.testimonial:animated').size() == 0){
						testimonialz.find('div.testimonial:visible').fadeOut(700,function(){
							
							if($(e.target).parent().hasClass('prev')){
								var show = $(this).prev('div.testimonial').size() > 0 ? $(this).prev('div.testimonial') : testimonialz.find('div.testimonial:last');
							} else {
								var show = $(this).next('div.testimonial').size() > 0 ? $(this).next('div.testimonial') : testimonialz.find('div.testimonial:first');
							}
							show.fadeIn(700);
						});
					}
				});
			}
		}
	}


	Engine.port.init();
	Engine.testimonials.init();
	
});





this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){

		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'><span>"+ this.t +"</span></p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});