/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var common = {
	
	blinkOn: true,
	
	
	start: function() {
		
		// launch the date reveal doodad
		common.datemaker();
		
		// assess the width of the page
		common.confirmPageSize();
		
		// set the blink on the time doodad
		setInterval( 'common.blinker()', 700 );
		
		// launch a gallery 
		if ( $('.inline_gallery a').length ) $('.inline_gallery a').lightBox();
		
		if ( $('.imageBlock').length ) {
			
			$('.imageBlock').hover( function() {
				
				var thisBlock = $(this);
				
				thisBlock.find('.revealContainer').slideDown( 'fast', function() {
					thisBlock.find('.revealContainer div').animate({ opacity: 1});
				});
				
			}, function() {
				
				var thisBlock = $(this);
				thisBlock.find('.revealContainer div').animate({ opacity: 0}, function() {
					thisBlock.find('.revealContainer').slideUp( 'fast' );
				});
				
			});
		} 
	},
	
    
	/**
	 * Reveal the span in the timer
	 */
	datemaker: function() {
    
		var monthNames = [ "January", "February", "March", "April", "May", "June",
		"July", "August", "September", "October", "November", "December" ];
		var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
        
      
		var newDate = new Date();
        
		var meridien = ( newDate.getHours() >= 12 ) ? 'pm' : 'am';
		var hours = ( newDate.getHours() >= 12 ) ? newDate.getHours() - 12 : newDate.getHours();
		hours = ( hours == 0 ) ? 12 : hours;
		
		var minutes = ( newDate.getMinutes() < 9 ) ? '0' + newDate.getMinutes() : newDate.getMinutes();

        
		var textSuffix = 'th';
        
		switch( newDate.getDate() ) {
                
			case(1):
			case(21):
			case(31):
                
				textSuffix = 'st';
				break;
                
			case(2):
			case(22):
                 
				textSuffix = 'nd';
				break;
                 
			case(3):
			case(23):
                 
				textSuffix = 'rd';
				break; 
                
		}
 		
		$('#mhDate').html(
			dayNames[newDate.getDay()] + " " + 
			newDate.getDate() + textSuffix + ' ' + 
			monthNames[newDate.getMonth()] + ', ' + 
			hours + '<span>.</span>' + 
			minutes + 
			meridien

			);    
		
		setTimeout( 'common.datemaker()', 30000 );

    
	},
	
	
	/**
	 * Hide and show the span in the timer
	 */
	blinker: function() {
		
		if ( common.blinkOn ) {

			$('#mhDate span').css({
				opacity: .1
			});
		
			common.blinkOn = false;
			
			
		} else {

			$('#mhDate span').css({
				opacity: 1
			});
		
			common.blinkOn = true;


		}
		
		
		
		
		
	},
	
	/**
	 * Applies the .smallFrame class to narrow pages
	 * 
	 * now removes is when browser window width increased // Kelvin 27January2012
	 */
	confirmPageSize: function() {
		
		var minWidth = 1100;
		// var minWidth = 3000;
		var actualWidth = $(window).width();

		if ( actualWidth < minWidth ) {
			$( 'body' ).addClass( 'smallFrame' );
			return false;
		} else {
			$( 'body' ).removeClass( 'smallFrame' );
		}
		
		return true;
	}

};


$(common.start);

$(window).resize(common.confirmPageSize);
