
jQuery(document).ready(function(){
	
	
	
	
	// init for round corners
		jQuery('.comment-content').positiveCorners();
	
	
	// live region (events)
		jQuery('#events').show();
		jQuery('#events .content').liveRegion({
			container : '#events',
			source : 'http://clansnap.com/api/events-upcoming/',
			interval  : 301000 // 5 minutes and 1 second
			//interval  : 3000 // 3 seconds for testing loading/updating CSS
		});
	
	
	// live region (members)
		jQuery('#online').show();
		jQuery('#online .content').liveRegion({
			container : '#online',
			//source : 'http://clansnap.com/assets/includes/online.php',
			source : 'http://clansnap.com/api/steam-who/',
			interval  : 301000 // 5 minutes and 1 second
			//interval  : 3000 // 3 seconds for testing loading/updating CSS
		});
		
	
	// live region (teamspeak status)
		jQuery('#teamspeak').show();
		jQuery('#teamspeak #teamspeak-status').liveRegion({
			container : '#teamspeak',
			source : 'http://clansnap.com/api/teamspeak-status/',
			interval  : 301000 // 5 minutes and 1 second
			//interval  : 3000 // 3 seconds for testing loading/updating CSS
		});
		
	// live region (teamspeak total)
		jQuery('#teamspeak #teamspeak-total').liveRegion({
			container : '#teamspeak',
			source : 'http://clansnap.com/api/teamspeak-total/',
			interval  : 301000 // 5 minutes and 1 second
			//interval  : 3000 // 3 seconds for testing loading/updating CSS
		});
		
	// live region (teamspeak total)
		jQuery('#teamspeak #teamspeak-who').liveRegion({
			container : '#teamspeak .users',
			source : 'http://clansnap.com/api/teamspeak-who/',
			interval  : 301000 // 5 minutes and 1 second
			//interval  : 3000 // 3 seconds for testing loading/updating CSS
		});
	
	
	// Countdown timer
		pad = function (value, width, padchar) {
			value = value + '';
			while (value.length < width) {
				value = padchar + value;
			}
			return value;
		}
		
		secondsToCountdown = function (a) {
			days    = Math.floor (a / (3600*24));
			hours   = Math.floor (a / 3600) - (days*24);
			minutes = Math.floor (a / 60) - (days*24*60) - (hours*60);
			seconds = a  - (days*24*3600) - (hours*3600) - (minutes*60);
			
			days    = pad(days, 2, '0');
			hours   = pad(hours, 2, '0');
			minutes = pad(minutes, 2, '0');
			seconds = pad(seconds, 2, '0');
			
			return days+':'+hours+':'+minutes+':'+seconds;
		};
	
		dateToCountdown = function (dateStr) {
			return secondsToCountdown( (Math.round((Date.parse(dateStr)-new Date())/(1000))*1) );
		};
		/*
		if ($('#portal-2-countdown .inner').size() > 0) {
			
			$('#portal-2-countdown .inner')
				.empty()
				.css({
					'display': 'block'
				})
				.countdown({
					format: 'dd:hh:mm:ss',
					startTime: dateToCountdown($('#release-portal-2 .date').text()), //'01:00:00:00',
					digitWidth: 53,
					digitHeight: 77,
					timerEnd: function() {
						//$('#portal-2-countdown').fadeOut().slideUp();
						alert('Portal 2 has dropped. Get playing!!');
					},
					image: '/assets/images/ui/digits.png'
				})
			;
		}*/
		
		if ($('#portal-2-countdown .inner').size() > 0) {
			countdown = $('#portal-2-countdown .inner').text();
			
			$('#portal-2-countdown .inner')
				.empty()
				.css({
					'display': 'block'
				})
				.countdown({
					format: 'dd:hh:mm:ss',
					startTime: countdown, //'01:00:00:00',
					digitWidth: 53,
					digitHeight: 77,
					timerEnd: function() {
						//$('#portal-2-countdown').fadeOut().slideUp();
						alert('Portal 2 is unlocked. Get playing!!');
					},
					image: '/assets/images/ui/digits.png'
				})
			;
		}
	
	
	
	// butterfly lightbox
	// automatically apply lightbox to all media links
		jQuery('a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"], a[href$=".swf"], a[href$=".m4v"]').butterfly(options={
			closeButtonImage: '/wp/wp-content/themes/snap-3.0/images/close.png',
			preloadLoadingImage: '/wp/wp-content/themes/snap-3.0/images/loading-black-on-white.gif',
			preloadGalleryControlsSprite: '/wp/wp-content/themes/snap-3.0/images/gallery-controls-sprite.png',
			galleryMode: 'all', // navigate through all lightboxed content
			galleryLoops: true // once you get to the end of the gallery, start again (and vice versa)
		});
	
	
	// init large content resize
		jQuery('object, table, pre').largeContent(); // define large content types here
	
	
	// coloured menu items
		jQuery('#skin-header').css('backgroundColor', '#ffffff'); // init colour as white for webkit's sake
		animSpeed = 250;
		jQuery('#navigation li:eq(0) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#00ff18' }, animSpeed);
		});
		jQuery('#navigation li:eq(1) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#fffc00' }, animSpeed);
		});
		jQuery('#navigation li:eq(2) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#00c6ff' }, animSpeed);
		});
		jQuery('#navigation li:eq(3) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#ff0000' }, animSpeed);
		});
		jQuery('#navigation li:eq(4) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#ad00b8' }, animSpeed);
		});
		jQuery('#navigation li:eq(5) a').bind('mouseover',function(){
			jQuery('#skin-header').stop().animate( { backgroundColor: '#ffb400' }, animSpeed);
		});
	
	
	
	
	
	
	// listen for page resize and ensure #page-container is long enough to encompass #tertiary-content
		enforceContainment = function () {
			if (jQuery('body').is('.layout-medium')) {
				contHeight = jQuery('#page-container').height();
				tertHeight = jQuery('#tertiary-content').height();
				
				//console.log(contHeight);
				//console.log(tertHeight);
				
				if (contHeight < tertHeight) {
					jQuery('#page-container').height(tertHeight);
				}
			} else {
				jQuery('#page-container').height('auto');
			}
		};
		ResizeEvents.bind (
			'x-initial-sizes x-text-resize x-window-resize',
			enforceContainment
		);
	
	
	
	
});


