/**
 * @author 
 */


$(document).ready(function(){
	
	
	Cufon.replace('h1', {fontFamily: 'BauhausC'});
	Cufon.replace('h2', {fontFamily: 'BauhausC'});
	Cufon.replace('h3', {fontFamily: 'BauhausC'});
	Cufon.replace('h4', {fontFamily: 'BauhausC'});
	Cufon.replace('h5', {fontFamily: 'BauhausC'});
	Cufon.replace('h6', {fontFamily: 'BauhausC'});
	Cufon.replace('dt', {fontFamily: 'BauhausC'});
	
	if (($.browser.msie) && ($.browser.version < 7))
	{
		if ($('.main-page .main-back').get(0)) $('.main-page .main-back').height($('.main-page').height()-600)
		else
			$('.page .main-back').height($('body').height()-500);
	};
	
	if (($.browser.msie) && ($.browser.version == 7))
	{
		if ($('.main-page .main-back').get(0)) $('.main-page .main-back').height($('.main-page').height()/2)
		else
			$('.page .main-back').height($('.columns').height()-200);
	};
	
	$('.content h1 a').hover(
		function(){
			Cufon.replace($(this).parent(), {fontFamily: 'BauhausC', color: '#48d6ff'});
		},
		function(){
			Cufon.replace($(this).parent(), {fontFamily: 'BauhausC', color: '#b5ebff'});
		}
	);
	
	$('.content h2 a').hover(
		function(){
			Cufon.replace($(this).parent(), {fontFamily: 'BauhausC', color: '#48d6ff'});
		},
		function(){
			Cufon.replace($(this).parent(), {fontFamily: 'BauhausC', color: '#b5ebff'});
		}
	);
	
	$('.thickbox').fancybox({ 
		'zoomSpeedIn': 200, 
		'zoomSpeedOut': 200,
		'frameWidth': 100,
		'frameHeight': 100,
		'overlayShow': true,
		'hideOnContentClick' :false,
		'centerOnScroll' : false
	});
	
	$('table').each(function(){
		if (!$(this).hasClass('files') && !$(this).hasClass('direction') && !$(this).parent().hasClass('timetable'))
			$(this).find('tr:odd').addClass('odd');
	})
	
	$('.timetable table:first').each(function(){
		$(this).find('table').each(function(){$(this).find('.odd').removeClass('odd');});
	});
	
	$('.filter-buttons a').click(function(){
		var rel = $(this).attr('href');
		
		if ($(this).attr('class').indexOf('active') == -1)
		{
			$('.filter-buttons a').each(function(){
				$(this).attr('class',$(this).attr('class').split(' ')[0]);	
			});
			$(this).addClass($(this).attr('class')+'-active');
		}
		
		
		var spans = $('.timetable').find('.title');
		spans.removeAttr('style');
		spans.each(function(){
			if (rel == "all")
			{
				spans.removeAttr('style');
				$(this).find('i').css('display','block');
				$(this).removeClass('shadowed');
			}
			else if ($(this).attr('rel') && ($(this).attr('rel') != rel))
			{
				$(this).css('opacity','0.2');
				$(this).find('i').css('display','none');
				$(this).addClass('shadowed');
			}
			else
			{
				$(this).find('i').css('display','block');
				$(this).removeClass('shadowed');
			}
		});
		return false;
	});
	
	function paint_time(item,rel)
	{
		if (!$(item).hasClass('time'))
		switch (rel)
		{
			case 'mix': $(item).css('background','#D77300'); break;
			case 'power': $(item).css('background','#5DA400'); break;
			case 'dance': $(item).css('background','#B30B0B'); break;
			case 'odd':
			{
				if (!$(item).hasClass('right-last') && !$(item).parent().hasClass('last-row'))
					$(item).css('background', '#2A5D7D');
				break;
			}
			default:
			{
				if (!$(item).hasClass('right-last') && !$(item).parent().hasClass('last-row'))
					$(item).css('background','#154562'); 
				break;
			}
		}
	};	
	
	
	
	$('.timetable td').hover(
	function(){
	    
		if ($(this).find('table').get(0))
		{
			$(this).find('td').hover(
				function(){
					
					var info_box = $(this).find('.info');
					
					var offset = ($(info_box).width()+$(this).offset().left) - ($('.timetable').offset().left+$('.timetable').width());
					if (offset > 0)
					{
						offset += $(this).width();
						$(info_box).css('margin-left',-offset+'px');
						if (($.browser.msie) && ($.browser.version <= 8))
						{
							$(info_box).css('margin-left',-offset-100+'px');
						}
					}	
					if ($(this).find('span').attr('rel')) {
						if (!$(this).find('.shadowed').get(0))
							paint_time(this, $(this).find('span').attr('rel'));
					}
					else {
						if ($(this).parents('.odd').get(0)) {
							paint_time(this, 'odd');
						}
						else {
							paint_time(this);
						}
					}
					if (!$(this).find('.shadowed').get(0))
						$(info_box).fadeIn(100);
					
					if (($.browser.msie) && ($.browser.version == 8)) {
						if (!$(this).find('.shadowed').get(0)) 
							$(info_box).css('display','block');
					}
					 
				},
				function(){
					$(this).find('.info').fadeOut(100); 
					if ($(this).parents('.odd').get(0)) {
						paint_time(this, 'odd');
					}
					else {
						paint_time(this);
					}}
			);				
		}
		else
		{
			var info_box = $(this).find('.info');
					
			var offset = ($(info_box).width()+$(this).offset().left) - ($('.timetable').offset().left+$('.timetable').width());
			
			if (($.browser.msie) && ($.browser.version == 8)) {offset += 200};
			
			if (offset > 0)
			{
				offset += $(this).width();
				$(info_box).css('margin-left',-offset+'px');	
				if (($.browser.msie) && ($.browser.version <= 8))
				{
					$(info_box).css('margin-left',-offset-100+'px');
				}
			}	
			if ($(this).find('span').attr('rel')) {
				if (!$(this).find('.shadowed').get(0))
					paint_time(this, $(this).find('span').attr('rel'));
			}
			else {
				if ($(this).parents('.odd').get(0)) {
					paint_time(this, 'odd');
				}
				else {
					paint_time(this);
				}
			}
			if (!$(this).find('.shadowed').get(0))
					$(info_box).fadeIn(100);
					
			if (($.browser.msie) && ($.browser.version == 8)) {
				if (!$(this).find('.shadowed').get(0)) 
					$(info_box).css('display','block');
			}		
		}
	},
	function(){
		$(this).find('.info').fadeOut(100); 
		if ($(this).parents('.odd').get(0)) {
			paint_time(this, 'odd');
		}
		else {
			paint_time(this);
	}
	}
	);
	
	$('.content .card-types').click(function(){
		$(this).parent().next('.card-list').slideToggle(250);
		return false;
	})
	
});
