// variables

// listeners
$(document).ready(function() {
	loadPngFix();
	setContentMinHeight();
	setProgramAnimation();
	setNavigatioAnimation();
	setFlashContent();
});
$(window).resize(function() {
});

// functions
function loadPngFix() {
	if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == '6') {
		$.getScript("js/jquery.supersleight.js", function() {
			$('body').supersleight();
		});
		$('body').prepend($('<a/>',{
			id:'IE6warning',
			text:'You are using an outdated browser. Click here and update free.',
			href:'http://www.microsoft.com/windows/Internet-explorer/default.aspx',
			target:'_blank'
		}));
	}
}
function setContentMinHeight() {
	var sidebar = $('#sidebar');
	var content = $('#content');
	var sHeight = sidebar.height() + 40;
	var cHeight = content.height();
	if (cHeight < sHeight) {
		content.height(sHeight);
	}
}
function setProgramAnimation() {
	var prog = $('#prog');
	var curr = 1;
	var aNext = $('.programme_buttons a.next');
	var aPrev = $('.programme_buttons a.prev');
	aNext.removeAttr('href').css('cursor', 'pointer').click(function() {
		if (curr < 10) {
			curr++;
			var prevHeights = 0;
			var forFocus = $('#day' + curr);
			forFocus.prevAll().each(function() {
				prevHeights += ($(this).height() + 16);
			});
			prevHeights = (prevHeights + 1) + 'px';
			prog.find('div').each(function() {
				var div = $(this);
				div.animate( {
					bottom : prevHeights
				}, 'normal', 'swing');
			})
		} else {
			curr = 10;
		}
	});
	aPrev.removeAttr('href').css('cursor', 'pointer').click(function() {
		if (curr > 1) {
			curr--;
			var prevHeights = 0;
			var forFocus = $('#day' + curr);
			forFocus.prevAll().each(function() {
				prevHeights += ($(this).height() + 16);
			});
			prevHeights = (prevHeights + 1) + 'px';
			prog.find('div').each(function() {
				var div = $(this);
				div.animate( {
					bottom : prevHeights
				}, 'normal', 'swing');
			})
		} else {
			curr = 1;
		}
	});
}
function setNavigatioAnimation() {
	$('#nav li.drop').each(function() {
		$(this).hover(function() {
			if ($(this).is(':not(.busy)')) {
				var drop = $(this);
				var ul = drop.find('ul');
				var lis = ul.find('li');
				drop.addClass('busy')
				lis.each(function() {
					var li = $(this);
					li.hide().fadeIn('fast');
				});
				drop.css('bottom', '12px').delay(10).animate( {
					bottom : '30px'
				}, 'fast');
				ul.hide().delay(10).slideDown('fast');
			}
		}, function() {
			if ($(this).is('.busy')) {
				var drop = $(this);
				var ul = drop.find('ul');
				var lis = ul.find('li');
				lis.each(function() {
					var li = $(this);
					li.show().delay(10).fadeOut();
				});
				drop.animate( {
					bottom : '12px'
				}, 'normal', 'linear', function() {
					$(this).removeClass('busy');
				});
				ul.slideUp();
			}
		});
	});
}
function setFlashContent() {
	$('#flash').append($('<div/>', {
		id : 'topFlash'
	}));
	$('#player').append($('<div/>', {
		id : 'fPlayer'
	}));
	var flashvars = {};
	var params = {
		wmode : 'transparent'
	};
	var attributes = {};
	swfobject.embedSWF("swf/top_flash.swf", "topFlash", "960", "260", "9.0.0",
			"", flashvars, params, attributes);
	swfobject.embedSWF("swf/player.swf", "fPlayer", "350", "129", "9.0.0", "",
			flashvars, params, attributes);
}
