// Custom Javascript
jQuery(document).ready(function() {
	
	// Main Navigation
	function mainmenu(){
	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(200);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
	}
	
	$(document).ready(function(){
	    mainmenu();
	});

	// Slider
	$(document).ready(function() {
    $('.slide-area').cycle({
		fx: 'fade',
		cleartypeNoBg: true,
		cleartype: true,
		pager:   '#pager',
		pause:   true,
		pauseOnPagerHover: 0
	});
    });
	
	// Carousel
	$(function() {
    $(".photo-slide").jCarouselLite({
        btnNext: ".photo-slide-next",
        btnPrev: ".photo-slide-prev",
		visible: 3
    });
	});
	
	// Social Media
	$(function() {
        var offset = $("#social-box").offset();
        var topPadding = 15;
        $(window).scroll(function() {
            if ($(window).scrollTop() > offset.top) {
                $("#social-box").stop().animate({
                    marginTop: $(window).scrollTop() - offset.top + topPadding
                });
            } else {
                $("#social-box").stop().animate({
                     marginTop: 0
                });
            };
        });
    });
	
	// Scroll to Top
	$('.top a').click(function () {
	    $('body,html').animate({
		    scrollTop: 0
		}, 800);
		return false;
	});
	
	// toggle content
	$(".toggle-content").hide(); 
	
	$("h4.toggle").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});
	
	$("h4.toggle").click(function(){
		$(this).next(".toggle-content").slideToggle();
	});
	
	// Tab
	$(document).ready(function() {

	//Default Action
	$(".tab-content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab-content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.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 rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

    });

});

//Ajax Contact Form
$(function(){
	
	//Do what we need to when form is submitted.	
	$('#form-submit').click(function(){
	
	//Setup any needed variables.
	var input_name = $('#form-name').val(),
		input_email = $('#form-email').val(),
		input_subject = $('#form-subject').val(),
		input_message = $('#form-message').val(),
		response_text = $('#response');
		//Hide any previous response text 
		response_text.hide();
		
		//Change response text to 'loading...'
		response_text.html('Loading...').show();
		
		//Make AJAX request 
		$.post('./php/contact-send.php', {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
			response_text.html(data);
		});
		
		//Cancel default action
		return false;
	});

});
