// NAVIGATION
$(function() {
	$(".tab1").click(function() {
		$(this).addClass("active");
		$(".tab2").removeClass("active");
		$(".tab3").removeClass("active");
	});
	
	$(".tab2").click(function() {
		$(this).addClass("active");
		$(".tab1").removeClass("active");
		$(".tab3").removeClass("active");
	});
	
	$(".tab3").click(function() {
		$(this).addClass("active");
		$(".tab1").removeClass("active");
		$(".tab2").removeClass("active");
	});
	
	$(".up").click(function() {
		$(".tab1").addClass("active");
		$(".tab2").removeClass("active");
		$(".tab3").removeClass("active");
	});
	
	$(".down").click(function() {
		$(".tab1").addClass("active");
		$(".tab2").removeClass("active");
		$(".tab3").removeClass("active");
	});
});


// NAV SCROLL
$(function() {
	$("a.tab1").smoothScroll();
	$("a.tab2").smoothScroll();
	$("a.tab3").smoothScroll();
	$("a.up").smoothScroll();
	$("a.down").smoothScroll();
	$("a.link").smoothScroll();
});


// BACK TO TOP
$(function() {
	$(window).scroll(function() {
		if($(this).scrollTop() <= 0) {
			$("#backtotop").fadeOut('slow');
			$("#backtotop-btn").css('display', 'none');
			$(".tab1").addClass("active");
			$(".tab2").removeClass("active");
			$(".tab3").removeClass("active");
		} else {
			$("#backtotop").fadeIn('slow');
			$("#backtotop-btn").css('display', 'block');
		};
	});
	
	$('#backtotop-btn').click(function() {
		$('html,body').animate({scrollTop:0},800);
	});
	
	$('#logo').click(function() {
		$('html,body').animate({scrollTop:0},800);
	});
});


// SMOKING SIGN
$(function() {
	$(window).scroll(function() {
		if($(this).scrollTop() <= 900) {
			$("#no-smoking").fadeOut('slow');
		} else {
			$("#no-smoking").fadeIn('slow');
		};
	});
});


// TOOLTIPS
$(function() {
	$(".tooltip-trigger-one").click(function() {	
		$(".tooltip-one").fadeIn();
		$(".tooltip-two").fadeOut();
		$(".tooltip-three").fadeOut();
		$(".tooltip-four").fadeOut();
		
		$(this).addClass("active");
		$(".tooltip-trigger-two").removeClass("active");
		$(".tooltip-trigger-three").removeClass("active");
		$(".tooltip-trigger-four").removeClass("active");
	});
	
	$(".tooltip-one").click(function() {	
		$(this).fadeOut();
		$(".tooltip-trigger-one").removeClass("active");
	});
	
	$(".tooltip-trigger-two").click(function() {	
		$(".tooltip-one").fadeOut();
		$(".tooltip-two").fadeIn();
		$(".tooltip-three").fadeOut();
		$(".tooltip-four").fadeOut();
		
		$(".tooltip-trigger-one").removeClass("active");
		$(this).addClass("active");
		$(".tooltip-trigger-three").removeClass("active");
		$(".tooltip-trigger-four").removeClass("active");
	});
	
	$(".tooltip-two").click(function() {	
		$(this).fadeOut();
		$(".tooltip-trigger-two").removeClass("active");
	});
	
	$(".tooltip-trigger-three").click(function() {	
		$(".tooltip-one").fadeOut();
		$(".tooltip-two").fadeOut();
		$(".tooltip-three").fadeIn();
		$(".tooltip-four").fadeOut();
		
		$(".tooltip-trigger-one").removeClass("active");
		$(".tooltip-trigger-two").removeClass("active");
		$(this).addClass("active");
		$(".tooltip-trigger-four").removeClass("active");
	});
	
	$(".tooltip-three").click(function() {	
		$(this).fadeOut();
		$(".tooltip-trigger-three").removeClass("active");
	});
	
	$(".tooltip-trigger-four").click(function() {	
		$(".tooltip-one").fadeOut();
		$(".tooltip-two").fadeOut();
		$(".tooltip-three").fadeOut();
		$(".tooltip-four").fadeIn();
		
		$(".tooltip-trigger-one").removeClass("active");
		$(".tooltip-trigger-two").removeClass("active");
		$(".tooltip-trigger-three").removeClass("active");
		$(this).addClass("active");
	});
	
	$(".tooltip-four").click(function() {	
		$(this).fadeOut();
		$(".tooltip-trigger-four").removeClass("active");
	});
	
	$(".smoking-trigger").mouseover(function() {	
		$(".tooltip-smoking").fadeIn();
	});
	
	$(".smoking-trigger").mouseout(function() {	
		$(".tooltip-smoking").fadeOut();
	});
});


// PORTFOLIO REVEAL
$(function() {
	$(".showmemore").hide(); 

	$(".showmebtn").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});
});


// LOGO FADE
$(function(){
	$("img.off").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, "slow");
			$("img.on").stop().animate({"opacity": "1"}, "slow");
		},
		
		function() {
			$(this).stop().animate({"opacity": "1"}, "slow");
			$("img.on").stop().animate({"opacity": "0"}, "slow");
		});
});


// WINDOW RESIZE
$(function() {
	$(window).resize(function(){
        $("#responsive-alert").fadeOut();
    });
});


// CONTACT BOX - SLIDE
$(function(){
	$(".contact-btn").click(function(){
		$("#contact-form").slideToggle("slow");
		$(this).toggleClass("contact-active");
	});
});


// CONTACT BOX - CLOSE
$(function(){
	$(".contact-close").click(function(){
		$("#contact-form").slideToggle("slow");
		$(".contact-btn").toggleClass("contact-active");	
	});
});


// CONTACT BOX - VALIDATION
$(function(){
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var url = $('input[name=url]');
		var comment = $('textarea[name=comment]');
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var emailaddressVal = $("#email").val();
        var themessage = "Don\'t be a stranger. I need to know: ";
		var hasError = false;

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			name.addClass("hightlight");
			themessage = themessage + " - Your name";
			hasError = true;
		} else name.removeClass("hightlight");
		
		if (email.val()=='') {
			email.addClass("hightlight");
            themessage = themessage + " - Your email address";
            hasError = true;
        } else email.removeClass("hightlight");
 
        if (!emailReg.test(emailaddressVal)) {
        	email.addClass("hightlight");
            themessage = themessage + " - Your real email address";
            hasError = true;
        }
		
		if (comment.val()=='') {
			comment.addClass('hightlight');
			themessage = themessage + " - Why you\'re contacting me";
			hasError = true;
		} else comment.removeClass("hightlight");
		
		if (url.val()!='') {
            themessage = "You are not human! No form for you!";
            hasError = true;
        }

        if (hasError == true) {
        	alert(themessage);
        	return false;
        }
		
		else {
			//organize the data properly
			var data = 'name=' + name.val() + '&email=' + email.val() + '&comment='  + encodeURIComponent(comment.val());
			
			//disabled all the text fields
			$(".text").attr('disabled','true');
			
			//show the loading sign
			$(".loading").show();
			
			//start the ajax
			$.ajax({
				//this is the php file that processes the data and send mail
				url: "output.php",	
				
				//GET method is used
				type: "GET",
	
				//pass the data			
				data: data,		
				
				//Do not cache the page
				cache: false,
				
				//success
				success: function (html) {				
					//hide the form
					$(".form").hide();		
					
					//show the success message
					$(".done").fadeIn('slow');
					
					//close the contact box
					setTimeout('$("#contact-form").slideToggle("slow");$(".contact-btn").removeClass("contact-active");', 4000);
				}		
			});
			
			//cancel the submit button default behaviours
			return false;
		}
	});	
});


// TWITTER
getTwitters('tweet', { 
	id: 'julesfrog', 
	count: 6, 
	enableLinks: true, 
	ignoreReplies: true, 
	clearContents: true,
	template: '<span class="twitter-time">%time% : </span>%text%'
});


// OPEN TWITTER LINKS IN NEW TAB
$("#tweet ul li a[href]").live(
	"click",
	function(event)
	{
		window.open($(this).attr("href"));
		event.preventDefault();
	}
);
