(function($) {
	
	//dynamic span tag on first word of Bio
	var para = $('body.about #main-col p:first');
	
	if(para.length) {
		para.html(para.html().replace(/^(\w+)/, '<span class="firstWord">$1</span>'));
	}
	
	
	//lasts
	$('li.widget_twitter ul li:last', '#sidebar').addClass('last');
	$('li.vevent:last', '#sidebar').addClass('last');
	
	
	//lyrics  - hide unused meta boxes
	
	var uls = $('li.album ul', 'body.lyrics');
	
	uls.find('li').each(function() {
		var li = $(this);
		var title = li.find('.song-title');
		
		if ( title.text() == '') {
			li.addClass('hide');
		}
	});
	
	//lyrics - create song title cols
	var breakpoint = 6;
	
	uls.each(function() {
		$(this).find('li:lt(' + breakpoint + ')').wrapAll('<div class="col1" />');
		$(this).find('li:gt(' + (breakpoint - 1) + ')').wrapAll('<div class="col2" />');
	});	
	
	// lyrics - show
	var lyricsHolder = $('#lyrics-holder'),
	    lyricsHolderInner = lyricsHolder.children('#lyrics-holder-inner');
	
	$('.song-title').click(function(e) {
		var song = $(this),
			lyrics = song.next('.lyrics-container').html(),
			li = song.parents('li.album'),
		 	position = li.position(),
			active = song.hasClass('.active');
		    
		
		e.preventDefault();
		
		if (!active) {
			$('.song-title').removeClass('active');
			lyricsHolderInner.empty();
		
			song.addClass('active');
		
			lyricsHolder
			  .addClass('hide')
			  .css('marginTop', (position.top - 25))
			  .children('#lyrics-holder-inner')
			    .append(lyrics)
			    .end()
			  .fadeIn(900);
		} else {
			return;
		}
	});
	
	
	//covers expand
	var coversList = $('ul#albums');
		covers = coversList.find('img.cover'),
		dims = '';
		
	
	dims = {
			small: { width: 136, height: 136 },
			big: { width: 280, height: 280 }
	}
	
	covers.each(function(i) {
		var cover = $(this),
			coords = cover.offset(),
			copy = $('<img>', {
				id: cover.attr('id').split('-')[0],
				src: cover.attr('src'),
				width: cover.width(),
				height: cover.height()
			});
			
		cover.attr('id', 'cover' + (i + 1) + '-thumb');
			
		$('<div></div>', {
			"class": 'cover-wrapper',
			css: {
				top: coords.top,
				left: coords.left,
				direction: "ltr"
			},
			html: copy,
			width: cover.width(),
			height: cover.height(),
			click: function() {
				if(!$(this).hasClass('high')) {
					$('div.cover-wrapper').removeClass('high');
					$(this).addClass('high');
				}
				
				var img = $(this).find('img');

				if(!img.hasClass('expanded')) {
					img.addClass('expanded').animate({
						width: dims.big.width,
						height: dims.big.height
					}, {
						queue: false
					});
				} else {
					img.animate({
						width: dims.small.width,
						height: dims.small.height
					}, {
						queue: false,
						complete: function() {
							$(this).removeClass('expanded');
						}
					});
				}
			}
		}).appendTo('body');
	});
	
	$(window).resize(function() {
		
		$("div.cover-wrapper").each(function(i) {
			
			//get new coords of original image
			var newCoords = $("#cover" + (i + 1) + "-thumb").offset();
			
			//realign
			$(this).css({
				top: newCoords.top,
				left: newCoords.left
			});
		});
	});		
			
			
		
	// elipsis
	//$('.products-list h3').textOverflow('...', true);
	
})(jQuery)
