
	/* Site Params / Please Configure These Parameters for your own purposes */
	
	// Countdown - Release Date of the Site / Date when countdown timer ends counting down!
	var release_date = "01-01-2012"; // Format MM-DD-YYYY
	
	// Already subscribed error message
	var subscribe_error_msg = "You are already subscribed with this email!";

	// Twitter User ID
	var twitter_id = "envatowebdesign";
	
	// Number of tweets to fetch/show
	var tweets_count = 10;
	
	// Time out for tweet switch (unit: seconds)
	var tweet_roller_timeout = 5;
	


	/* Rest of JS */
	
	var tweet_roller_index = 0;
	var total_tweets = 0;
	
	$(document).ready(function()
	{
		// Email Label Disappear
		var email_label = $(".subscribe-label");
		$(".subscribe-email").focus(function()
		{
			email_label.animate({marginLeft:20, opacity: 0}, 300);
		});
		
		// Email Label Reappear
		$(".subscribe-email").blur(function()
		{
			var $this = $(this);
			
			if( $this.val().length == 0 )
			{
				email_label.stop().animate({marginLeft:0, opacity: 1}, 300);
			}
		});
		
		// Social Icons Animation
		$(".social_icons img").each(function()
		{
			var img = $(this);
			
			img.hover(function()
			{
				img.stop(true).animate({top: -5}, 200);
			},
			function()
			{
				img.animate({top: 0}, 200);
			});
		});
		
		// Process Subscribe Form
		var subscribe_form = $(".subscribe-form");
		subscribe_form.find("> form").submit(function(ev)
		{
			ev.preventDefault();
			
			var email_field = $(this).find('input[name="subscribe-email"]');
			
			if( !email_field.val().match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/) )
			{
				var ms = 50;
				
				// Shake That Form
				subscribe_form.stop()
					.animate({left: 20}, ms)
					.animate({left: -10}, ms)
					.animate({left: 10}, ms)
					.animate({left: -5}, ms)
					.animate({left: 1}, ms)
					.animate({left: -15}, ms)
					.animate({left: 0}, ms);
				
				email_field.focus();
			}
			else
			{
				var subscribe_loader = $(".subscribe-loader");
				
				$.ajax(
					{
						url: "subscribe_process.php",
						type: "POST",
						data: {"subscribe_email": email_field.val(), "do_subscribe": true},
						beforeSend: function()
						{
							subscribe_loader.stop().fadeIn("slow");
						},
						success: function(data)
						{
							var status = Number(data);
							var subscribe_error = $(".subscribe-error");
							
							subscribe_loader.fadeOut("normal", function()
							{
								if( status == 1 )
								{
									var subscribe_success = $(".subscribe-success");
									subscribe_success.width(subscribe_form.width()).css("min-height", subscribe_form.height());
									
									if( subscribe_error.length == 1 )
										subscribe_error.fadeOut("normal");
									
									subscribe_form.animate({left: -400, opacity: 0}, {ducation: 500, easing: 'easeInBack', complete: function()
									{
										subscribe_success.fadeIn();
										subscribe_form.hide();
									}});
								}
								else
								if( status == 0 )
								{
									if( subscribe_error.length == 0 )
									{
										// Already Subscribed Error
										subscribe_form.append('<div class="subscribe-error"><span>'+subscribe_error_msg+'</span></div>');
										subscribe_error = $(".subscribe-error");
									}
									
									subscribe_error.fadeIn();
								}
							});
						}
					}
				);
			}
		});
		
		
		// Twitter Parser
		$(".twitter-statuses").tweets(
		{
			username: twitter_id, // Twitter Username
			tweets: tweets_count // Number of Tweets to Parse
		},
		function()
		{
			$(".twitter-statuses li").remove();
		},
		function()
		{
			var tweets = $(".twitter-statuses li");
			tweets.hide().first().fadeIn("slow");
			
			total_tweets = tweets.length;
			
			if( total_tweets > 1 )
			{
				tweet_roller_index = (tweet_roller_index+1)%total_tweets;
				
				setInterval(function()
				{
					// Auto Tweet Roller Function by Arlind Nushi
					tweets.stop().filter(':visible').fadeOut("normal", function()
					{
						tweets.filter(':nth-child('+(tweet_roller_index+1)+')').fadeIn("normal");
					});
					
					tweet_roller_index = (tweet_roller_index+1)%total_tweets;
					
				}, tweet_roller_timeout * 1000);
			}
		});
		
		
		// Setup Countdown Timer
		if( release_date )
		{
			var date_arr;
			if( date_arr = release_date.match(/^(0[0-9]|1[0-2])\-([0][0-9]|1[0-9]|2[0-9]|3[0-1])\-(20[0-9]{2})$/) )
			{
				var _month = date_arr[1];
				var _date = date_arr[2];
				var _year = date_arr[3];
				
				var _release_date = new Date(_year, _month-1, _date);
				
				$("#countdown_days .countdown_area").countdown({until: _release_date, layout: "{dn}"});
				$("#countdown_hours .countdown_area").countdown({until: _release_date, layout: "{hn}"});
				$("#countdown_minutes .countdown_area").countdown({until: _release_date, layout: "{mn}"});
				$("#countdown_seconds .countdown_area").countdown({until: _release_date, layout: "{sn}"});
			}
			else
			{
				alert("Invalid date format for countdown timer! Format: MM-DD-YYYY");
			}
		}
		
		// Center Layout

		
		centerLayout();
		$(window).resize(centerLayout);
	});
	
	
	// Browser Compability Options
	$(document).ready(function()
	{
		// Options for Firefox
		if( $.browser.mozilla )
		{	
			$(".subscribe-email").css("width", "-=6");
			$(".subscribe-submit").css("padding-top", "-=2");
			$(".subscribe-submit").css("padding-bottom", "-=3");
		}
		
		// Options for all MSIE browsers
		if( $.browser.msie )
		{
			$(".subscribe-email").css("line-height", "22px");
		}
		
		// Options for MSIE7
		if( $.browser.msie && parseInt($.browser.version, 10) == 7 )
		{
			$(".subscribe-email").css("width", "-=6");
			$(".subscribe-submit").css("padding-top", "-=2").css("padding-bottom", "-=3").width(108);
			$(".subscribe-form").height(40);
			
			$(".social_icons").css({position: 'relative', top: 0});
		}
	});
	
	// Miscellaneous functions
	jQuery.fn.autolink = function ()
	{
		return this.each( function()
		{
			var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
			$(this).html( $(this).html().replace(re, '<a href="$1" target="_blank" rel="nofollow">$1</a> ') );
		});
	}
	
	jQuery.fn.twitterlink = function ()
	{
		return this.each( function()
		{
			var re = /@([\w\_0-9]+)/g;
			$(this).html( $(this).html().replace(re, '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a> ') );
		});
	}
