// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Title : custom.js
// Author : Máté Tóth - zgravity
// URL : http://themeforest.net/user/zgravity
//
// Description : This files contains custom jQuery codes and it starts all of the plugins
//
// Created : 2010.12.02.
// Modified : 2010.12.02.
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


jQuery(document).ready(function(){
	
	// Call cufon font replacement for .welcometitle, and add a little bit of shadow
	Cufon.replace('.welcometitle', {textShadow: '3px 3px #210522'}); 
	// Also replace heading fonts
	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('.sharetitle');
	Cufon.replace('.error404big');

	// Set navigation container div for cycle
	var bc = $('.welcomenav');
	
	// Starts cycle plugin with fade effect - For more options visit http://jquery.malsup.com/cycle/options.html
	var $container = $('.slideshow').cycle({ 
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		pager: '.welcomenav', 
		// callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<a href="#" class="slidenavbutton">&nbsp;</a>'; 
		},
		cleartype: true,
		cleartypeNoBg: true, 
		pause:  true,
    	timeout:  5000
	});
	
	// Call fancybox plugin
	$("a[rel*=lightbox]").fancybox({
		'titlePosition'	: 'inside'
	});
	
	// Animate sidebar lists on hover
	$(".widget li a").stop().mouseenter(function(){
		$(this).animate({
			paddingLeft : '+=10px'
		}, "fast");
	}); 
	$(".widget li a").stop().mouseout(function(){
		$(this).animate({
			paddingLeft : '-=10px'
		}, "fast");
	});
	
	// Call tweet plugin
	$(".tweet").tweet({
    	username: "mojo_themes",
        count: 3,
        loading_text: "loading tweets..."
   });
	
	// Add darker background to every second comment
	$(".comment:odd").css("background-color", "#fcfcfc");	
	
	// Call superfish for the drop-down menus
	jQuery(function(){
		jQuery('ul.sf-menu').superfish();
	});
	
	// Fade out portfolio images on hover
	$(".portfoliopostv1 img, .portfoliopostv2 img, .portfoliopostv3 img").hover(
	function() {
		$(this).stop().animate({"opacity": "0.4"}, "medium");
	},
	function() {
		$(this).stop().animate({"opacity": "1"}, "medium");
	});
	
	// Function to fade the scroll to top button in and out
	$(window).scroll(function(){
		var scroll_timer;
		var displayed = false;
		var $message = $('#totop');
		var $window = $(window);
		var top = $(document.body).children(0).position().top;
	 
		/* react to scroll event on window */
		$window.scroll(function () {
				if($window.scrollTop() <= top) // hide if at the top of the page
				{
					displayed = false;
					$message.fadeOut(500);
				}
				else if(displayed == false) // show if scrolling down
				{
					displayed = true;
					$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
				}
		});
	});
	
	// Function to scroll page when scroll to top button is clicked
	$("#totop").click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	// Function to scroll page when scroll to top button is clicked
	$(".notifbox").click(function() { 
    	$(this).fadeOut("slow"); 
		return false;
	})
	
	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".trigger").click(function(){
		$(this).toggleClass("activetoggle").next().slideToggle("fast");
		return false; //Prevent the browser jump to the link anchor
	});
	
	// This function controls the comment form (Don't edit if you don't know what you're doing)
	$("#commentform").submit(function() {
		$('.contacterror').hide();
		$('#result').html('');
        $('#loading').append('<img src="images/loading.gif" alt="" />Processando, aguarde...');
        var name = $("input#Nome").val();
		if (name == "") {
		  $('#loading').fadeOut(300);
		  $("label#name_error").fadeIn();
		  $("input#Nome").focus();
		  return false;
		}
        var email = $("input#E-mail").val();
		if (email == "") {
		  $('#loading').fadeOut(300);
		  $("label#email_error").fadeIn();
		  $("input#E-mail").focus();
		  return false;
		}
        var phone = $("input#Telefone").val();
		if (phone == "") {
		  $('#loading').fadeOut(300);
		  $("label#phone_error").fadeIn();
		  $("input#Telefone").focus();
		  return false;
		}
		var captcha = $("input#captcha").val();
		if (captcha != 5) {
		  $('#loading').fadeOut(300);
		  $("label#captcha_error").fadeIn();
		  $("input#captcha").focus();
		  return false;
		}
        /*
        var data = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "form/contact.php",
			data: data,
			success: function(msg) {
				$('#loading').fadeOut(300);
				$('#result').html('<div class="notifbox success">E-mail sent successfully!</div>');
				$('#result').fadeIn();
			}
		});
        return false;
        */
    });
	
});


