/* RESEN */
/* Javascript Functions
----------------------------------------------------------------------------- */
	
/* FUNCTION: LIGHTBOX
----------------------------------------------------------------------------- */
		
		
	function lightbox() {
		
		$('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();
				imgLoader = null;
				return false;
			
			});
			
			return false;
		
		});
		
		
/* Internet Explorer 6 Exception */

		
		$('.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;
		
		});
		
	}
				
	
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */
	
	
	function markup() {
	
	
/* Remove Empty Tabs */


		$('.tabbed > ul.tabs').children('li').each(function() {
		
			var pane = $(this).find('a').attr('href');
			if ($(this).parent().siblings(pane).length === 0) {
			
				$(this).remove();
				$(this).parent().siblings(pane).remove();

			}
	
		});
		
		// REMOVE ENTIRE TABBED PANEL IF EMPTY
		$('.tabbed').children('ul.tabs').each(function() {
		
			if ($(this).children('li').length === 0) { $(this).parent().remove(); }
	
		});
	

/* Format Dates */


		$('.module-events.browse ul.content > li > em').each(function() {
						
			var date = $(this).text().replace(', ', '').replace(/[0-9]{4}/, '');			
			var month = date.match(/[a-zA-Z]{3}/);
			var day = date.match(/\d{1,2}/);		
		
			$(this).text('');
			$(this).prepend('<abbr>' + month + '</abbr> ');
			$(this).append('<span>' + day + '</span>');
			$(this).show();
			
		});
		
		
/* News Leads */


		$('#main #news > ul.content > li:gt(1)').addClass('short');
		
		
/* Thumbnail Detector */


		$('#main #news > ul.content > li:not(.short)').each(function() {
		
			if ($(this).find('a.image').length > 0) { $(this).addClass('image'); }
		
		});

	}
	

/* FUNCTION: ACTION BEHAVIORS
----------------------------------------------------------------------------- */

	
	function actions() {
	
		
/* Back Link */


		$('a[href=#back]').click(function() {
		
			history.go(-1);
			return false;
		
		});
		
		
/* Mailing List Placeholder */

		
		$('.mailinglist #qutud-qutud').each(function() {
		
			var placeholder = "Enter your email address";
			if ($(this).attr('value') === "") { $(this).attr('value', placeholder); }
			
			$(this).focus(function() { 
			
				if ($(this).attr('value') == placeholder) { $(this).attr('value', ''); }
				$(this).removeClass('placeholder');
				
			});
			
			$(this).blur(function() {
			
				if (!$(this).attr('value')) {
				
					$(this).attr('value', placeholder);
					$(this).addClass('placeholder');

				}
			
			});

		});		
		
	}
		
		
/* FUNCTION: TABS
----------------------------------------------------------------------------- */


	function tabs() {
	

/* Javascript */


		$('.tabbed:not(.ajax):not(.static) > ul.tabs').tabs({
		
			fxSlide: false
			
		});
		
		
/* Fix Javascript Paging */
	

		$('.tabbed:not(.ajax):not(.static) ul.paging a').each(function() { 
			
			var pane = $(this).parents('div.pane').attr('id'); 
			$(this).attr('href', $(this).attr('href') + '#' + pane); 
		
		});

	}
	
	
/* FUNCTION: TABS
----------------------------------------------------------------------------- */


	function ie() {
	
		var isIE = (navigator.userAgent.match('MSIE 6') ? true : false);
		if (isIE) {
		
			$('body').prepend('<div class="alert"><h3>Please upgrade your browser</h3><p>This site no longer supports Internet Explorer 6. We recommend using <a href="http://www.google.com/chrome" target="_blank">Google Chrome</a> or <a href="http://www.getfirefox.com/" target="_blank">Mozilla Firefox</a>.</p></div>');
			$('a.resen').remove();
		
		}
		
	}
	
	
/* 
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		markup();

	});
	
	$(window).load(function() {

		lightbox();
		actions();
		tabs();
		ie();

	});