jQuery.noConflict();
jQuery(document).ready(function(){

var username = 'rehabbeauty'; // set user name
var format = 'json'; // set format, you really don't have an option on this one
var url = 'http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?'; // make the url

	jQuery.getJSON(url,function(tweet){ // get the tweets
		jQuery("#last-tweet").html('Latest: <span>' + tweet[0].text + '</span>'); // get the first tweet in the response and place it inside the div
	});
	
	
	/*
	  * FORM ***
	*/

	
	
	jQuery("#form").delegate('#formMail', 'submit', function(e){
		
		e.preventDefault();
		
		var oldForm = jQuery('#formMail');
		
		jQuery('#formMail').animate({'opacity': 0}, 400,  function()
		{
			jQuery('#form').html('<div id="message-pending"></div>').find('#message-pending').animate({'opacity': 1}, 400);
			
			jQuery.ajax({
				type: "POST",
				url: "sendMail.php",
				 processData: false,
				data: jQuery(this).serialize(),
				success: function(response) 
				{
					console.log(response);
					jQuery('#message-pending').stop().animate({'opacity': 0}, 400, function()
					{
						console.log(response);
						
						if(response === 'ok')
						{
							jQuery('#form').html('<div id="message-success"><h2>Message Sent!</h2></div>').find('#message-success').animate({'opacity': 1}, 400);
						}
						else 
						{
							jQuery('#form').html('<div id="message-error"><h2>'+response+'</h2></div>').find('#message-error').animate({'opacity': 1}, 400).delay(3400).animate({'opacity': 0}, 400, function()
							{
								jQuery('#form').html(oldForm).find('#formMail').animate({'opacity': 1}, 400);
								
							});
							
						}
						
					});
					
				}
			});
			
		
		});
		
		
				
		
		return false;
		
		
		
	});
	
	var hideAlert = function(){
		clearInterval(interval);
		jQuery("#alert").stop().animate({opacity:0}, 400);
	};
	
	jQuery("#signup").submit(function(){
		jQuery.ajax({
			type: "POST",
			url: "signup.php",
			data: jQuery(this).serialize(),
			success: function(response) {
				jQuery("#alert").ajaxComplete(function() {
					if(response == 'ok') {
						jQuery(this).html('<p>Thank\'s for Signing Up!</p>');
						jQuery("#email").val('');
						jQuery(this).stop().animate({
								opacity: 1
							}, 400, function(){
							interval = setInterval(hideAlert, 8000);
						});
					} else {
						jQuery(this).html(response);
						jQuery(this).stop().animate({
								opacity: 1
							}, 400, function(){
							interval = setInterval(hideAlert, 4000);
						});
					}
				});
			}
		});
		return false;
	});
	
	var hideAlert = function(){
		clearInterval(interval);
		jQuery("#alert").stop().animate({opacity:0}, 400);
	};


	/*
	  * MENU ***
	*/


	jQuery(function(){
		jQuery("ul.sf-menu").superfish();
	});


	/*
	  * SLIDES ***
	*/

	if (jQuery("#featured img").length > 1){
		jQuery("#featured_button_prev, #featured_button_next").css({display:"block"});
		jQuery("#featured").cycle({
			fx: 'fade',
    		next: '#featured_button_next', 
    		prev: '#featured_button_prev',
    		timeout: 10000
    	});
    	jQuery("#featured").css({zIndex:0});
    	jQuery("#featured_button_prev").css({zIndex:1});
		jQuery("#featured_button_next").css({zIndex:2});
	}
	
	jQuery("#slide").cycle({
		fx: 'fade',
    	next: '#slide_button_next', 
    	prev: '#slide_button_prev',
    	timeout: 14000
    });
    
    jQuery("#news_ticker ul").cycle({
		fx: 'fade',
   		timeout: 14000
    });
    
   	jQuery("#gallery").css({zIndex:0});
   	if (jQuery("#gallery img").length > 1){
    	jQuery("#gallery").cycle({
			fx: 'fade',
   			timeout: 5000
    	});
    }


	/*
	  * GALLERIES ***
	*/


	jQuery(".slide_items a, #galleries a").contents("img").hover(function(){
		jQuery(this).stop().animate({opacity:0.5}, 400);
	}, function() {
		jQuery(this).stop().animate({opacity:1}, 400);
	});
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		"theme": 'light_square' /* light_rounded / dark_rounded / light_square / dark_square */																
	});
});
