// TWITTER PLUGIN
(function($){
	$.fn.lastTwitterMessage = function(username){

	var $base = this;
	if(!username || username == "") return this; // username required
	var url = "http://twitter.com/statuses/user_timeline.json?callback=?";
	$.getJSON( url, { count: 10, screen_name: username },
	function(data){
	
		if(data && data.length >= 1){
			try{
				var item = null;
					for(var i = 0; i < data.length; i++){
						if(/^@/i.test(data[i].text)) continue;
						item = data[i]; break;
					}
				if(!item) return;
				var $tweet = $("<p></p> ").text(item.text);
				$tweet.html(
				$tweet.html()
				.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>')
				.replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>')
				.replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>')
				)
				$tweet.append(" &nbsp;<a href='http://twitter.com/" + username + "'>(&#8734;)</a>&nbsp; ").wrapInner("<span>");
				$base.empty().append($tweet).show();
				} catch (e) { };
		};
	});
	return this; // Don't break the chain
	};
})(jQuery);
// LOAD TWITTER
$(function() {
	$("<div id='tweet'></div>").hide().appendTo("#twitter-wdg")
	.lastTwitterMessage('stylozero');
});
// FAQ ACCORDION
$(document).ready(function(){	
	$("#faq p:not(:first)").hide();
		
	$("#faq h3").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
	});
	
});
// PROCESS INFO BUBBLES
$(document).ready(function(){
	$("#smallsteps a").hover(function() {
		$(this).next("div").animate({opacity: "show", top: "100"}, "slow");
	}, function() {
		$(this).next("div").animate({opacity: "hide", top: "110"}, "fast");
	});
});
// STAY TUNED SHIFTING EFFECT
$(document).ready(function(){
	$('ul#staytuned li').mouseover(function() {
		$(this).animate( { paddingLeft:"6px" }, { queue:false, duration:300 });
		
	}).mouseout(function() {
		$(this).animate( { paddingLeft:"0" }, { queue:false, duration:300 });
		
	}).click(function() {
		$(this).animate( { }, { queue:false, duration:300 }); // This is useless, take it off
		
	});
});
// SMALLSTEPS BG
$(document).ready(function(){
	$('input#show2').click(function() {
		if ($('input#show2:checked').length <=0 ) // The <=0 makes the checking on/off work properly with jqtransform (which styles the element)
		{	
        	$("ul#smallsteps").css("background", "url(http://stylozero.com/site/wp-content/themes/stylozero/images/smallsteps-bg.png) no-repeat 5px 34px");
    	}
    	else
    	{
        	$("ul#smallsteps").css("background", "none");
  		}
	});
});
// FIELDS: TEXT DISAPPEARING WHEN CLICKED
$(document).ready(function(){	
	/**
	 * Written by Rob Schmitt, The Web Developer's Blog
	 * http://webdeveloper.beforeseven.com/
	 */
	
	/**
	 * The following variables may be adjusted
	 */
	var active_color = '#666'; // Colour of user provided text
	var inactive_color = '#ccc'; // Colour of default text
	
	/**
	* No need to modify anything below this line
	*/
	
	  $("input.default-value, textarea.default-value, input#search-input").css("color", inactive_color);
	  var default_values = new Array();
	  $("input.default-value, textarea.default-value, input#search-input").focus(function() {
	    if (!default_values[this.id]) {
	      default_values[this.id] = this.value;
	    }
	    if (this.value == default_values[this.id]) {
	      this.value = '';
	      this.style.color = active_color;
	    }
	    $(this).blur(function() {
	      if (this.value == '') {
	        this.style.color = inactive_color;
	        this.value = default_values[this.id];
	      }
	    });
	  });
});
// THE SYNTAX CODE
$(document).ready(function(){	
	$("pre").hover(function() {
		var codeInnerWidth = $("code", this).width() + 10;
	    if (codeInnerWidth > 545) {
			$(this)
				.stop(true, false)
				.css({
					zIndex: "100",
					position: "relative"
				})
				.animate({
					width: codeInnerWidth + "px"
				});
			}
		}, function() {
				$(this).stop(true, false).animate({
					width: 545
			});
		});
});