Cufon.set('fontFamily', 'HelveticaNeue').replace('div#moods');
Cufon.set('fontFamily', 'HelveticaNeue').replace('div.courseoverview_headerimage');
Cufon.set('fontFamily', 'Primus').replace('div#moods div p');
Cufon.set('fontFamily', 'Primus').replace('div.courseoverview_headerimage div p');

var origSearchValue = '';

$(document).ready(function()
{
	// Startseite schriften
	Cufon.now();
	
	// do this fast
	$('a.file_event').click( function() {
	   _gaq.push(['_trackEvent', 'Link Click', 'File Link', $(this).attr('href')]);
	   //console.log('tracking');
	});
	$('a.email_event').click( function() {
	   _gaq.push(['_trackEvent', 'Link Click', 'Email Link', $(this).html()]);
	   //console.log('tracking');
	});
	$('a.external_event').click( function() {
	   _gaq.push(['_trackEvent', 'Link Click', 'External Link', $(this).attr('href')]);
	   //console.log('tracking');
	});
	
	$('div.filters').advanced_filter();
	
	// MOODS ANIMATION STARTSEITE
	$('div#moods').moods();
	
	// MOODS ANIMATION COURSEOVERVIEW
	$('div.courseoverview_headerimage').moods();
	
	// MOODS ANIMATION COURSEOVERVIEW
	$('div.wteye').wt_eye();
	
	//console.log($('.wt_eye'));

	$('div.nav').hover(
		function() {
			$(this).addClass('simpleOver');
		},
		function () {
			$(this).removeClass('simpleOver');
		}
	);
	$('div.nav, div.navActive').click(
		function() {
			gotoByLink(this);
		}
	);

	$('a.plusLink').hover(
		function() {
			$(this).addClass('plusLinkOver');
		},
		function () {
			$(this).removeClass('plusLinkOver');
		}
	);


	$('a.normalMode').hover(
		function() {
			var container = $('div.listMode');
			$(container).attr('class', 'listMode normalMode');
		},
		function () {
			var container = $('div.listMode');
			if ($(container).attr('id') != 'normalMode') {
				$(container).attr('class', 'listMode extendedMode');
			}
		}
	);
	$('a.extendedMode').hover(
		function() {
			var container = $('div.listMode');
			$(container).attr('class', 'listMode extendedMode');
		},
		function () {
			var container = $('div.listMode');
			if ($(container).attr('id') != 'extendedMode') {
				$(container).attr('class', 'listMode normalMode');
			}
		}
	);


	$('#credits').click(
		function() {
			if ($('#creditsBig').css('display') != 'none') {
				$('#creditsBig').fadeOut(800);
			} else {
				$('#creditsBig').fadeIn(300);
			}

		}
	);

	// setup search form
	setupSearchForm();

	$(window).resize(resize);
	resize();

	/* fix namenwurscht */
	if ($.browser.mac() && $.browser.firefox()) {
		$('a.person img').css('top', '5px');
	}
	if ($.browser.msie() && $.browser.version.number() < 8) {
//		$('a.person').css('background-position', '0px 4px');
	}
	if ($.browser.safari()) {
		$('a.person img').css('top', '5px');
	}

});

function setupSearchForm() {

	origSearchValue = $('input.nccr-searchbox').attr('value');
	$('input.nccr-searchbox').click(function() {
		if(this.value == 'Search for...' || this.value == origSearchValue) {
			this.value = '';
		}
	});

	$('input.nccr-searchbox').blur(function() {
		if(this.value == '') {
			this.value = 'Search for...';
		}
	});
}

function resize() {
	if ($(window).height() > $('#container').height()+$('#topLine').height()) {
		$('#credits').css({position:'absolute', bottom:'0px', left:'23px'});
	} else {
		$('#credits').css({position:'relative', bottom:'', left:''});
	}
}

function prepareHomeStuff() {

	// top items
	$('div.homeTopItem').hover(
		function() {
			$(this).addClass('simpleOver');
		},
		function () {
			$(this).removeClass('simpleOver');
		}
	);
	$('div.homeTopItem').click(
		function() {
			gotoByLink(this);
		}
	);

	// right items
	$('div.titleBar a').hover(
		function() {
			$(this).addClass('over');
		},
		function () {
			$(this).removeClass('over');
		}
	);
	$('div.homeRightItem').hover(
		function() {
			$(this).addClass('simpleOver');
		},
		function () {
			$(this).removeClass('simpleOver');
		}
	);
	$('div.homeRightItem').click(
		function() {
			gotoByLink(this);
		}
	);

}

function genericROPrepare(which) {

	// top items
	$(which).hover(
		function() {
			$(this).addClass('simpleOver');
		},
		function () {
			$(this).removeClass('simpleOver');
		}
	);
	$(which).click(
		function() {
			gotoByLink(this);
		}
	);
}


function gotoByLink(element) {
	var a = $(element).find('a');
	document.location.href = $(a).attr('href');
}


