// JavaScript Document

var $j = jQuery.noConflict();

$j(function($){
	
	/*CLEAR SEARCH FORM*/
	$('#searchform #s').click(function(){
		$(this).attr('value', '');								   
	});
	
	
	//MENU DROP DOWN
	$(".menu li").hover(function(){
		$(this).find('ul:first').slideDown('fast');
	},function(){
		$(this).find('ul:first').fadeOut('fast');
	});  
	$('.menu ul li .page_item').hover(function(){
		$(this).animate({left:10}, 200);										
	},function(){
		$(this).animate({left:0}, 200);
	});
	$('.menu ul li ul').append('<li class="menu-bottom"></li>');
	
	//TOP HEADER LINKS
	//MENU DROP DOWN
	$(".header-top-links li").hover(function(){
		$(this).find('ul:first').slideDown('fast');
	},function(){
		$(this).find('ul:first').fadeOut('fast');
	});  
	$('.header-top-links ul li .page_item').hover(function(){
		$(this).animate({left:10}, 200);										
	},function(){
		$(this).animate({left:0}, 200);
	});
	$('.header-top-links ul li ul').append('<li class="menu-bottom"></li>');
	
	
	//CONTACT FORM
	$('#contact_form #submitBtn').click(function(){
		var name = $('#contact_name').val();
		var email = $('#contact_email').val();
		var email_message = $('#email_message').val();
		var values = $('#contact_form').serialize();
		var path = $('#path').val();
		if(name.length == 0 || email.length == 0 || email_message.length == 0)
		{
			alert('All fields must be completed. Thank you');
		}
		else
		{
			$.ajax({
				type: 'GET',
				url: path+'/modules/contact_form/send_email.php',
				data: values,
				success: function(msg){
					if($('#message').length > 0)
					{
						$('#message').fadeOut('normal', function(){
							$(this).remove();
							$('#contact_form').prepend('<div id="message" class="updated" style="background-color: rgb(255, 251, 204);"><p><strong>Your email has been sent. Thank you.</strong></p></div>');
						});
					}
					else
					{
						$('#contact_form').prepend('<div id="message" class="updated" style="background-color: rgb(255, 251, 204);"><p><strong>Your email has been sent. Thank you.</strong></p></div>');	
					}
					$('#name').val('');
					$('#email').val('');
					$('#email_message').val('');
				},
				error: function(){
					alert('Error: Could not send email.');	
				}
			});
		}
		return false;
	});
	
	//LOADING GIF
	if($('#loading').length > 0)
	{
		$("#loading").ajaxStart(function(){ 
		  $(this).show(); 
		});
		$("#loading").ajaxStop(function(){ 
		  $(this).hide(); 
		});
	}
	
	//SOCIAL ICONS DANCE 
	$('.social_widget ul > li').hover(function(){
		$(this).find('a')
		.css('position', 'relative')
		.animate({'top' : '-10px'});												   
	},function(){
		$(this).find('a')
		.animate({'top' : '0'});
	});
	$('.knil').prepend('<a href="http://empoweredblogs.com" title="Empowered Blogs for Wordpress by The Empowered Tribe">Empowered Blogs for Wordpress by the Empowered Tribe</a>');
	
	//HIDE SEARCH FORM IF IT EXISTS IN WIDGET
	var sidebar_search = $('.side-bar #searchform');
	if(sidebar_search.length > 0)
	{
		$('.header .search').hide();	
	}
});
