/* Javascript
----------------------------------------------------------------------------- */


/* Ready Function
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
	
		$('#post').hide();
		
		
/* Enlarged Image Display
----------------------------------------------------------------------------- */
		
		
		$('div.browse ul.content a[rel=lightbox], div.browse-stories ul.content a[rel=lightbox]').click(function() {

			$('body').append('<div id="enlarged"></div>');
			$('#enlarged').append('<a href="#"></a>');
			$('#enlarged').css('width','100%');
			$('#enlarged').css('height','100%');
			$('#enlarged').css('position','fixed');
			$('#enlarged').css('top','0');
			$('#enlarged').css('left','0');
			$('#enlarged a').css('display','block');
			$('#enlarged a').css('width','100%');
			$('#enlarged a').css('height','100%');
			$('#enlarged a').css('text-align','center');


			// GET ENLARGED IMAGE URL
			var img = $(this).children('img').attr('src').replace('thumb_','img_');
			var size = ".jpg";
			img = img.replace('_s.jpg',size).replace('_t.jpg',size).replace('_m.jpg',size);
			
			imgLoader = new Image();
			imgLoader.src = img;
			
			imgLoader.onload = function() {  
			
				var height = imgLoader.height;
				var top = ($('#enlarged').height() - imgLoader.height) / 2;
				$('#enlarged a').append('<img src="' + img + '" alt="" />');
				$('#enlarged a img').css('display','inline');
				$('#enlarged a img').css('margin-top',top + 'px');
			
			}
			
			$('#enlarged a').click(function() {
			
				$(this).parent().remove();
				return false;
			
			});
			
			return false;
		
		});
		
		
/* Internet Explorer 6 */

		
		$('.module-images.browse ul.content a[rel=lightbox_ie]').click(function() {

			var img = $(this).children('img').attr('src').replace('thumb_','img_');
			window.open(img);
			return false;
		
		});
				
	
/* Language Changes
----------------------------------------------------------------------------- */
	
	
		$('.section-guestbook a.comment').text("Sign Guestbook");
		$('.section-guestbook #post h3').text("Sign Guestbook");
		$('.section-guestbook #browsecomments h3').text("Guestbook Entries");
		

/* Toggle Comments
----------------------------------------------------------------------------- */

	
		$('a.action.comment').click(function() {
	
			$('div#post').slideToggle('fast');
			return false;
			
		});
		
		
/* Back Link
----------------------------------------------------------------------------- */


		$('a.action.back').click(function() {
		
			history.go(-1);
			return false;
		
		});
		
	
/* Share Links
----------------------------------------------------------------------------- */


		if ($('ul.share').length > 0) {
		
			var itemTitle = $('ul.share').parent().children('h4').text();
		
			$('ul.share .delicious a').attr('href', 'http://del.icio.us/post?v=4&noui&jump=close&url=' + location.href + '&title=' + itemTitle);
			$('ul.share .stumbleupon a').attr('href', 'http://www.stumbleupon.com/submit?url=' + location.href + '&title=' + itemTitle);
			$('ul.share .digg a').attr('href', 'http://digg.com/submit?phase=2&url=' + location.href + '&title=' + itemTitle);

		}
		
		
/* Hide THumbnail for Video Post
----------------------------------------------------------------------------- */


		if ($('object').length > 0) {
		
			$('.module-editorial.display img').hide();
		
		}


/* End Ready Function
----------------------------------------------------------------------------- */


	});


/* Load Function
----------------------------------------------------------------------------- */


	$(window).load(function() {
	
		
/* External Links
----------------------------------------------------------------------------- */


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


/* End Load Function
----------------------------------------------------------------------------- */


	});
	
	
/* Function: Fix Tab Paging
----------------------------------------------------------------------------- */


	function fixPaging(pane) {

		$(pane + ' ul.paging a').each(function() { 
		
			var $this = $(this); 
			$this.attr('href', $this.attr('href') + pane); 
	
		});

	}
		