/*
	Autor: Grzegorz Jaworek
	E-mail: grzegorz.jaworek@gmail.com
	www: http://gjaworek.pl 
	Tel.: +48 519 133 159
*/


$(document).ready(function(){
	var dt1 = new Date(); 
	var dday = dt1.getDate();
	var dmon = dt1.getMonth();
	var dyear = dt1.getFullYear();
	if (dt1.getDay()==1) {
		if (dt1.getHours()>=13) { dday = dday+7; }
	} else {
		for (i=0;i<=6;i++) {
			var dt2 = new Date(dt1.getTime() + i*86400000);
			if (dt2.getDay() == 1) { 
				dday = dt2.getDate();
				dmon = dt2.getMonth();
				dyear = dt2.getFullYear();
			}
		}
	}
	var liftoffTime = new Date( dyear, dmon, dday , 13, 00, 00); // rok, miesiąc-1,dzień, fodzina, minuta, sekunda
	$('#countdown').countdown({
		until: liftoffTime, 
		format: 'dHMS', 
		layout: '<span class="day">{dn}</span><span class="sep">dni</span><span class="hour">{hnn}</span><span class="sep">:</span><span class="min">{mnn}</span><span class="sec">{snn}</span><span class="sep">godzin</span>', 
		compact: true, 
		description: ''
	});
	
	$('form.rating :radio.star').rating(); 
	// Cufon.replace('#menu a', {
		// fontFamily: 'UnitRounded',
		// color: '-linear-gradient(#CA3F69, #E8A29B, #D25A79, rgb(0, 0, 0))',
		// hover: {
			// color: '#CA3F69'
		// }
	// });
	Cufon.replace('#footer-1 a', {
		fontFamily: 'UnitRounded',
		hover: {
			color: '-linear-gradient(#CA3F69, #D25A79, #E8A29B, rgb(0, 0, 0))'
		}
	});
	Cufon.replace('#content h3', {
		fontFamily: 'UnitRounded'
	});
	Cufon.replace('.hero h4', {
		fontFamily: 'UnitRounded'
	});
	Cufon.replace('#content h5', {
		fontFamily: 'UnitRounded'
	});
	Cufon.replace('.unitrounded', {
		fontFamily: 'UnitRounded',
		hover: true
	});
	// Radio and CheckBoxes
	$('input.checkbox,input.radio').checkBox();
	$('textarea').autogrow({
		minHeight: 90,
		maxHeight: 350,
		lineHeight: 16
	});
	
	$('.episode-photos .br-photos a').lightBox();
	
	$('ul.photos').galleria({
		history   : false, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Nastęne zdjęcie >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});
});