jQuery.noConflict();
var $j = jQuery;


$j(document).ready(function() {
	
	$j(document).keypress(function(ev){
		if(ev.altKey && ev.which == 103){
			$j('#grid').css({'display': $j('#grid').css('display') == 'block' ? 'none' : 'block'});
			}
	});
	

	// fix png for IE
	// $j('img[@src$=.png], div').ifixpng();


	// remove any borders on last LI element
	$j("ul").not('#ie6-message ul').each(function(){
		 $j(this).children("li:last").css({borderRight:"0",borderBottom:"0",background:"none",paddingRight:"0",marginRight:"0"});
	});

	// hide layers
	$j('#tweet').hide();

	
	$j(".lightview").click(function(){
		var id = this.id;
		//window.location.hash = id;
	});
	
	$j(".dsq-button").click(function(){
		$j('.addthis_toolbox').hide();
		return false;

	});
	
	$j('a[href*=#]').not('#twitter').click(function() {
		var target = $j(this.hash);
		var id = this.hash.substr(1);
		var targetOffset = target.offset().top-10;
		$j('html,body').animate({scrollTop: targetOffset}, 1000);
		return false;
	});
	
	
	// input default text
	$j('input.default_text').focus(function(){
		if(!this._init_text){
			this._init_text = this.value;
			this.value = '';
			}
		else
			if( this.value == this._init_text )
				this.value = '';
	}).blur(function(){
		if( this.value == '' )
			this.value = this._init_text ? this._init_text : '';
	});
	
	//Fix movie height
	$j('.post-video object').each( function(){ 
		$j(this).height( $j(this).attr('height') - parseInt(($j(this).attr('width') - $j(this).width()) * 100 / $j(this).attr('width') / 100 * $j(this).attr('height')) ) 
	});
	
	
	
	$j('.dsq-comment-count').unbind();
	

	
	//Remove tailling / from tags
	$j('.post-tags').each(function(){
		$j(this).html( $j(this).html().substr(0, $j(this).html().length - 2 ) );
	});
	
	
	
	// handle tweet
	$j('#twitter').hover(
		function(){
			$j('#twitter').qtip("hide");
			$j('#tweet').fadeIn();
		},
		function(){
			$j('#tweet').fadeOut();
		}
	);
	
	$j('ul#twitter_update_list').find("li").prepend('<img style="position:relative; top:-3px;" src="http://tomblyth.com/images/prototip/quote.png" /> ');
	var twitterContent = $j('ul#twitter_update_list').html();
	var twitterLink = '<p><a href="http://twitter.com/tomblyth">Follow me on Twitter</a></p>';
	
	new Tip('twitter', twitterLink, {
		title: twitterContent,
		style: 'protogrey',
		stem: 'bottomLeft',
		hook: { tip: 'bottomLeft' },
		offset: { x: 20, y: 0 },
		width: 287,
		hideOn: false,
		hideAfter: 2
	});

	
	/*$j('#twitter').qtip({
		content:{
			text: '<div id="twitter_div"> <ul id="list">' + $j('ul#twitter_update_list').html() + '</ul> <a target="twitter-website" href="http://twitter.com/tomblyth" id="twitter-link">Follow me on Twitter</a> </div>'
		},
		show: { when: 'click'/*, delay: 500 },
		hide: { when: { event: 'unfocus' }, fixed: true, delay: 1000 },
		style: {
			tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
			border: {
			   width: 1,
			   radius: 1
			},
			name: 'light', // Use the default light style
			width: 270, // Set the tooltip width
			padding: 10
		},
		position:{
			corner: {
				target: 'topRight',
				tooltip: 'bottomLeft'
		   }
		},
		api: {
			onShow: function(){
				// do shaking via ease
				var posLeft = parseFloat($j('.qtip').css('left')); // get initial position on the x axis
				$j('.qtip').css('top', parseInt($j('.qtip').css('top')) + 2 + 'px');
				var newPosLeft = $j('.qtip').css('left',posLeft+40); // move 40px to the right
				$j('.qtip').animate({ "left": posLeft + 1 },{ queue:false, duration:800, easing: 'easeOutBounce'}); // animate the whole qtip
					
				try{
					}
				catch(e){};
			},
			onRender: function(){
				// replace the tip
				$j('.qtip-tip').empty().html('<img src="'+ ($j.siteBaseURI ? $j.siteBaseURI : '') +'images/backgrounds/tip.png" />').css({left:0,bottom:1,zIndex:60001});

				$j('ul#list li:first span').prepend('<img src="'+ ($j.siteBaseURI ? $j.siteBaseURI : '') +'images/backgrounds/quote.png" />');

				// add close button
				$j('.qtip').append('<a href="#" id="qtip-close"></a>');

				// hide qtip
				$j('a#qtip-close').click(function(){
					$j('#twitter').qtip('hide');
					return false;
				});
			}
		}
	}).click(function(){
		$j('#tweet').hide();
		return false;
	});
*/
	

	var i = 0;
	$j('.flickr_badge_image').each(function(){
		if( ! ( ++i % 2 ) )
			$j(this).addClass('odd');
	});
	
	
	
	$j('.ie6-close').attr('href', '').mousedown(function(ev){
		ev.preventDefault();
		$j('#ie6-message').hide();
		return false;
	});
		
	$j("#dsq-content .dsq-sharing-options").mouseover(function(){
		$j(this).find(".dsq-button-small").css("cssText", "border-bottom: 1px #F5F5F5 solid !important");
	})
	
		
	$j("#dsq-content .dsq-sharing-options").mouseout(function(){
		$j(this).find(".dsq-button-small").css("cssText", "border-bottom: 1px #999999 solid !important");
	})
});





// Define indexOf for IE
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};

//Preload Images
$j.preload([ 
	'images/arrows/blue-up.png',
	'images/arrows/blue-down.png',
	'images/arrows/squared-up-blue.png',
	'images/arrows/squared-down-blue.png',
	'images/arrows/blue-up-active.png',
	'images/arrows/blue-down-active.png',
	'images/arrows/top-blue.png',
	'images/backgrounds/more-dots.gif',
	'images/backgrounds/back_to_top_hover.png',
	'images/backgrounds/new_skip_mouseover.gif',
	'images/backgrounds/quote.png',
	'images/backgrounds/tip.png',
	'images/buttons/close-tip.png',
	'images/contact_form/cor.png',
	'images/icons/i-blue.png',
	'images/loadingAnimation.gif'
	], {
		'base': $j.siteBaseURI
	});
