// Plugins

// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || [];   // store logs to an array for reference
log.history.push(arguments);
arguments.callee = arguments.callee.caller; 
if(this.console) console.log( Array.prototype.slice.call(arguments) );
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info, log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

//var color = ~~(Math.random()*18);

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
// jQuery/helper plugins

/*!
 * HTML5 Placeholder jQuery Plugin v1.8.2
 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
 * @author Mathias Bynens <http://mathiasbynens.be/>
 */
 
;(function($) {

	var isInputSupported = 'placeholder' in document.createElement('input'),
	    isTextareaSupported = 'placeholder' in document.createElement('textarea');
	if (isInputSupported && isTextareaSupported) {
		$.fn.placeholder = function() {
			return this;
		};
		$.fn.placeholder.input = $.fn.placeholder.textarea = true;
	} else {
		$.fn.placeholder = function() {
			return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
				.bind('focus.placeholder', clearPlaceholder)
				.bind('blur.placeholder', setPlaceholder)
			.trigger('blur.placeholder').end();
		};
		$.fn.placeholder.input = isInputSupported;
		$.fn.placeholder.textarea = isTextareaSupported;
	}

	function args(elem) {
		// Return an object of element attributes
		var newAttrs = {},
		    rinlinejQuery = /^jQuery\d+$/;
		$.each(elem.attributes, function(i, attr) {
			if (attr.specified && !rinlinejQuery.test(attr.name)) {
				newAttrs[attr.name] = attr.value;
			}
		});
		return newAttrs;
	}

	function clearPlaceholder() {
		var $input = $(this);
		if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) {
			if ($input.data('placeholder-password')) {
				$input.hide().next().attr('id', $input.removeAttr('id').data('placeholder-id')).show().focus();
			} else {
				$input.val('').removeClass('placeholder');
			}
		}
	}

	function setPlaceholder(elem) {
		var $replacement,
		    $input = $(this),
		    $origInput = $input,
		    id = this.id;
		if ($input.val() === '') {
			if ($input.is(':password')) {
				if (!$input.data('placeholder-textinput')) {
					try {
						$replacement = $input.clone().attr({ type: 'text' });
					} catch(e) {
						$replacement = $('<input>').attr($.extend(args(this), { type: 'text' }));
					}
					$replacement
						.removeAttr('name')
						// We could just use the `.data(obj)` syntax here, but that wouldn’t work in pre-1.4.3 jQueries
						.data('placeholder-password', true)
						.data('placeholder-id', id)
						.bind('focus.placeholder', clearPlaceholder);
					$input
						.data('placeholder-textinput', $replacement)
						.data('placeholder-id', id)
						.before($replacement);
				}
				$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
			}
			$input.addClass('placeholder').val($input.attr('placeholder'));
		} else {
			$input.removeClass('placeholder');
		}
	}

	$(function() {
		
		/* Begin get last tweet (@geryit)*/
		            $.getJSON('http://twitter.com/statuses/user_timeline/unitseven.json?callback=?', function(data) {
		                var html = "<b><a href='http://twitter.com/unitseven/status/" + data[0].id_str + "'>" + relative_time(data[0].created_at) + "</a></b> " + linkify(data[0].text);
		                $("#twitterPost").html(html);
		            });
		            /* End get last tweet */
		
		
		var rand = Math.random();
					$.get("weather.xml?v="+rand, {},
					   function(data){
					     
						var condition = $(data).find("current_conditions").find("condition").attr('data');

						$("#weatherInfo").html("<span id='wCondition'>"+condition + "</span> " + $(data).find("current_conditions").find("temp_c").attr('data') +"&deg; C <br/>  " +$(data).find("current_conditions").find("humidity").attr('data') +"<br/><img class='wIcon' src='http://google.com/"+$(data).find("current_conditions").find("icon").attr('data')+"' alt='"+condition+"'> " )
					   });
	
	//$("#weatherInfo")
	
	
	$("#weatherDesc").hoverIntent(
	  function () {
		  $("#weatherInfo").fadeIn('slow');
	    //$("#weatherInfo").css('display', 'block');
	    //$("#weatherDesc").html($("#wCondition").html());
	  }, 
	  function () {
		  $("#weatherInfo").fadeOut('slow');
	   // $("#weatherInfo").css('display', 'none');
	//$("#weatherDesc").html("Sunny");
	  }
	);
	
	
	
	//setInterval("changeColor()", 3000 );
	


		
	
		// Look for forms
		$('form').bind('submit.placeholder', function() {
			// Clear the placeholder values so they don’t get submitted
			var $inputs = $('.placeholder', this).each(clearPlaceholder);
			setTimeout(function() {
				$inputs.each(setPlaceholder);
			}, 10);
		});
	});
	
	
	/* Begin Convert Str to Url */
	        function linkify(txt){
	            var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
	            return txt.replace(regexp,'<a href="$1">$1</a>');
	        }
	        /* End Convert Str to Url */

	        /* Begin Convert Tweet Time */
	        function relative_time(time_value) {
	            var values = time_value.split(" ");
	            time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	            var parsed_date = Date.parse(time_value);
	            var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	            var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	            delta = delta + (relative_to.getTimezoneOffset() * 60);
	            var r = '';
	            if (delta < 60) {
	                r = 'a minute ago';
	            } else if (delta < 120) {
	                r = 'couple of minutes ago';
	            } else if (delta < (45 * 60)) {
	                r = (parseInt(delta / 60)).toString() + ' minutes ago';
	            } else if (delta < (90 * 60)) {
	                r = 'an hour ago';
	            } else if (delta < (24 * 60 * 60)) {
	                r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
	            } else if (delta < (48 * 60 * 60)) {
	                r = '1 day ago';
	            } else {
	                r = (parseInt(delta / 86400)).toString() + ' days ago';
	            }
	            return r;
	        }
	        /* End Convert Tweet Time */

	// Clear placeholder values upon page reload
	$(window).bind('unload.placeholder', function() {
		$('.placeholder').val('');
	});

}(jQuery));

function changeColor() {
  $("html").removeClass( 'color' + color % 18 );
  color++;
  $("html").addClass( 'color' + color % 18 ); 
}
