/* MIKE SHINODA */
/* JAVASCRIPT
----------------------------------------------------------------------------- */


/* CHARACTER LIMIT COUNTER
----------------------------------------------------------------------------- */


	function characterCount(editor,max) {
		
		var count = max - editor.val().length - 1;
		
		if (count > 0) {
			$(editor).parent().children('strong').children('var').html(count);
			$(editor).parent().children('strong').children('var.error').removeAttr('class');
		}
		else {
			$(editor).parent().children('strong').children('var').html('0');
			$(editor).parent().children('strong').children('var').attr('class','error');
		}
		
	}


/* LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {


/* sIFR TEXT REPLACEMENTS
----------------------------------------------------------------------------- */


		replace();


/* CUSTOMIZE GOOGLE SEARCH
----------------------------------------------------------------------------- */


	$('#cse-search-box input[type=text]').addClass('text');
	$('#cse-search-box input[type=submit]').addClass('button');
	$('#search').show();


/* CHANGE COMMENT PAGINATION LINK
----------------------------------------------------------------------------- */


	if (page == "comments") {

		$('#comments ul.paging a').each(function() {

			$(this).attr('href', $(this).attr('href') + '#comments');

		});

	}
			

/* LIMIT CHARACTERS IN COMMENT BOX
----------------------------------------------------------------------------- */


		var max = 700;
		$('#comment textarea').after('<strong><var>' + max + '</var> characters left / ' + max + ' maximum</strong>');
		$('#comment textarea').keypress(function() { characterCount($(this),max) });
		$('#comment textarea').change(function() { characterCount($(this),max) });


/* KILL PROFILE PAGE LINKS
----------------------------------------------------------------------------- */


		if (page == "blog") {

			$('span a').attr('href','#');

		}
		
		
/* AUTO-HIGHLIGHT EMBED AND SHARE LINKS
----------------------------------------------------------------------------- */


		if (page == "video") {

			$('textarea').click(function() {
			
				this.select();
			
			});
		
		}		


/* HIDE RELATED VIDEOS LINK
----------------------------------------------------------------------------- */


		if (page == "video") {

			$('div.widget-media dt:last').hide();
			$('div.widget-media dd:last').hide();			
		
		}
		

/* BROWSE MUSIC
----------------------------------------------------------------------------- */


		if (page == "music") {

			$('#music ul.clips li div').each(function() {
			
				$(this).children('a.comments, p').wrapAll('<div class="info hide"></div>');
	
			});

			$('#music ul.clips li a.details').click(function() {
				
				if ($(this).parent().parent().siblings('div.info').hasClass('hide')) {

					$('div.info').addClass('hide');
					$(this).parent().parent().siblings('div.info').removeClass('hide');
				
				}
				
				else {

					$(this).parent().parent().siblings('div.info').addClass('hide');
					
				}
				
				return false;
			
			});
			
		}
		

/* POPUP EXTERNAL LINKS
----------------------------------------------------------------------------- */


		$('a[rel=external]').click(function() {
		
			link = $(this).attr('href');
			window.open(link);
			return false;

		});


/* ADD SHARETHIS BUTTONS
----------------------------------------------------------------------------- */


		$('div.widget-editorial ul.leads > li').each(function() {

			$(this).append('<div class="sharethis">Share It</div>');

			$(this).children('div.sharethis').attr('innerHTML',
			
				'<script type="text/javascript">' +
		
					' SHARETHIS.addEntry({ ' +
					' title: "Share me", ' +
					' summary: "Sharing is good for the soul.", ' +
					' icon: "http://path.to/icon" ' +
				
					' }, {button:true} ); ' +
		
				'<\/script>'
			
			);

		});


/* ADD HOVER CLASS TO VIEWER
----------------------------------------------------------------------------- */


		$('div.right div.widget-photo.browse.thumbnails ul.photos > li, div.widget-tag').each(function() {
		
			$(this).hoverIntent(
			
			function() {

				$(this).addClass('hover');

			},
			function() {

				$(this).removeClass('hover');

			});
			
		});


/* END LOAD FUNCTION
----------------------------------------------------------------------------- */


	});