$('html').addClass('js');
$(document).ready(function() {
	
	// external links
	
	$("p a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
  	}).addClass('external')
		.attr('target','_blank')
		.attr('title','Open in New Window');

	$("ul#real-weddings-services a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
  	}).addClass('external')
		.attr('target','_blank')
		.attr('title','Open in New Window');
		
	// Single image div width
	
	$('div.post-images-1').find('img').each(function() {
		var img_width = $(this).width();
		$('div.post-images-1').css('width',img_width);
	});
	
	// subscribe form
	
	$('form#subscribe-form input#user_email')
		.focus(function() {
			if ($(this).val() == 'ENTER YOUR EMAIL ADDRESS') {
				$(this).val('');
			};			
		})
		.blur(function() {
			var formCurrent = $(this).val();
			formCurrent = formCurrent.replace(/\s/g,'');
			if (formCurrent == '') {
				$(this).val('ENTER YOUR EMAIL ADDRESS');
			};
		});
	
	// hide extra tags
	
	$('ul#nav li').hover(function() {
		var index_hide = false;
		var tag_length = $(this).find('li').length;
		var tag_width = 0
		for (var i=0; i < tag_length; i++) {
			var this_tag = $(this).find('li:eq('+i+')');
			tag_width = tag_width + this_tag.outerWidth();
			if (tag_width > 825) {
				index_hide = true;
				this_tag.hide();
			}
		};
		if (index_hide) {
			$(this).find('ul').prepend('<li class="tags-more"><a href="#">More&hellip;</a></li>');
			// console.log($(this).find('li.tags-more a').outerWidth());
			$(this).find('li.tags-more a').click(function(e) {
				e.preventDefault();
				$(this).parent('li').siblings().fadeIn();
				return false;
			});			
		};
	}, function() {
		$(this).find('li.tags-more').remove().parent();
		$(this).find('li').show();
	});
	
	// comments reveal

	if ($('#comments-list').length) {
		$('#comments').hide();
		$('.post-tools .comments')
			.append('<span class="sprite reveal"><div class="sprite read-comments"></div></span>')
			.attr('title','Read Comments')
			.hover(function() {
					$('.post .post-tools a.comments div.read-comments').show();
				}, function() {
					$('.post .post-tools a.comments div.read-comments').hide();
				})
			.toggle(function() {
					$('#comments').slideDown('400');
					$('.post-tools .comments span.reveal').toggleClass('hide');
				}, function() {
					$('#comments').slideUp('400');
					$('.post-tools .comments span.reveal').toggleClass('hide');
				});
	};
	
	// scroll to location (for comments)
	
	$(function(){ 
		var target = location.hash && $(location.hash)[0]; 
		if( target ) {
			$('#comments').show();
			$.scrollTo(target,{speed:1000});
		}
	});
	
});
