// by Bramus! (3RDS)
// http://www.bram.us - http://www.3rds.be/
//
// Exodus 20.15 - "Thou shalt not steal"

/**
 * Thunderbirds.are.go!
 * -------------------------------------------------------------
 */

jQuery(function($) {
	
	// homepage (and other stuff)
	TF2010.homepage.init();
	
	// scrollbar (@ie6: no soup for you!)
	if(!$.browser.msie || ($.browser.msie && (parseInt($.browser.version, 10) > 6)))
	{
		
		// Put scrollbar on content (not for partners page though)
		if ($('body').attr('id') != 'b_558') $('#innerContent > div').jScrollPane({showArrows:true});
		
		// Put scrollbar on subnav (line-up only)
		if ($('body').attr('id') == 'b_531')
		{
			$('#mainMenu').wrapInner('<div class="scrolled">');
			$('#mainMenu .scrolled').jScrollPane({showArrows:true});
		}
		
	}
		
	// Play that funcky music!
	TF2010.soundScape.init();
	
	// hallenplan
	TF2010.hallenplan.init();
	
	// statstracker
	TF2010.statstracker.init();
	
	// here.be.dragons
	TF2010.dragonChaser.init();
	
	// Facebook
	$('.fbc_logout').bind('click', function (e) {
		FB.logout(function(){ });
		return false;
	});
	
	// Lightbox
	if ($.fn.lightBox) $('li.photo a').lightBox();
	
});



/**
 * TF2010 Object - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */

	var TF2010 = {}



/**
 * TF2010 Object - Homepage - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */
	
	TF2010.homepage = {
			
			
		/**
		 * Datamembers
		 * -------------------------------------------------------------
		 */
			
			// none!
			
			
		/**
		 * Init - go.go.go!
		 * @return void
		 * -------------------------------------------------------------
		 */			
			
			init				: function () {
				
				if ($('body').attr('id') == 'home') {
					
					// hover on title = hover on splash
					$('h1 a').attr('title', $('#enterTF').attr('title')).hover(
							function(e) {
								$('#enterTF').addClass('hover');
							},
							function (e) {
								$('#enterTF').removeClass('hover');
							}
					);
					
					// slide header up when clicking the splash/header
					$('h1 a, #enterTF').click(function(e) {
						e.preventDefault();
						$('#enterTF').addClass('hover');
						href = $(this).attr('href');
						$('#innerHeader').animate({height: '153px'}, 1200, function() { window.location.href = href; });
					});
					
				}
				
				$('#shop a').hover(
					function() {
						$.data(this, 'origContent', $(this).html());
						$(this).html('Koop ticket(s)');
					},
					function() {
						$(this).html($.data(this, 'origContent'));
					}
				);				
				
			},
	
	
		/**
		 * end of object - Bramus, you lazy programmer!
		 * @see http://www.bram.us/2009/02/22/the-lazy-programmer-at-work-_eoo-and-your-javascript-objects/
		 * -------------------------------------------------------------
		 */
		
			_eoo			: true
	
	}
	
	
/**
 * TF2010 Object - dragonChaser - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */

	TF2010.dragonChaser = {
		
		
		/**
		 * Datamembers
		 * -------------------------------------------------------------
		 */
		
			dragons			: null,
			
			
		/**
		 * Init - go.go.go!
		 * @return void
		 * -------------------------------------------------------------
		 */
			
			
			init				: function () {
				
				// get all dragons
				TF2010.dragonChaser.dragons = $('.dragons span');
				
				// fade in all dragons
				for (i = 0; i < TF2010.dragonChaser.dragons.length; i++)
				{
					$(TF2010.dragonChaser.dragons[i]).fadeTo(TF2010.dragonChaser.randomTime(5000), 1, function() {
						$(this).fadeTo(TF2010.dragonChaser.randomTime(), 0.7);
					});
				}
								
				// hook hover on dragons: highlight current dragon, fadeOut the siblings
				TF2010.dragonChaser.dragons.hover(function(e) {
					$.data($(this), 'origZindex', $(this).css('zIndex'));
					// $(this).css('zIndex', '10');
					$(this).stop().fadeTo(1000, 1);
					$(this).siblings().stop().fadeTo(1000, 0.2);
				}, function() {
					$(this).css('zIndex', $.data($(this), 'origZindex'));
					$(this).stop().fadeTo(1000, 0.7);
					$(this).siblings().stop().fadeTo(1000, 0.7);
				});
				
				// hook click
				TF2010.dragonChaser.dragons.click(function() {
					$(this).stop().fadeTo(100, 0.2, function() {
						$(this).fadeTo(100, 0.7);
					});
				});
				
				// animate a dragon
				/*
				window.setInterval(function() {
					TF2010.dragonChaser.animate(TF2010.dragonChaser.randomDragon(), TF2010.dragonChaser.randomOpacity(), TF2010.dragonChaser.randomTime());
				}, 1000);*/
				
			},
			
			
		/**
		 * Animates an element
		 * @param jQuery elem
		 * @param int opacity
		 * @param int time
		 * @return void
		 * -------------------------------------------------------------
		 */
			
			
			// fade a dragon tot he given opacity, and then boost it back
			animate				: function (elem, opacity, time) {
				
				$(elem).stop().fadeTo(time, opacity, function() {
					$(this).fadeTo(TF2010.dragonChaser.randomTime(), 1);
				});
						
			},
			
			
		/**
		 * Generates a random dragon link
		 * @return jQuery
		 * -------------------------------------------------------------
		 */
			
			
			randomDragon				: function () {
				
				return TF2010.dragonChaser.dragons[Math.floor(Math.random()*TF2010.dragonChaser.dragons.length)];
				
			},
				
			
		/**
		 * Generates a random opacity
		 * @return int
		 * -------------------------------------------------------------
		 */
			
			
			randomOpacity				: function () {
				
				return Math.floor(Math.random()*60+0)/100; // max 0.6
				
			},
		
			
		/**
		 * Generates a random time
		 * @return int
		 * -------------------------------------------------------------
		 */
		
		
			randomTime				: function (max, min) {
				
				min = (min == undefined) ? 1000 : min;
				max = (max == undefined) ? 2500 : max;
				
				return Math.floor(Math.random()*(max-min)+min);
				
			},
		
		
		/**
		 * end of object - Bramus, you lazy programmer!
		 * @see http://www.bram.us/2009/02/22/the-lazy-programmer-at-work-_eoo-and-your-javascript-objects/
		 * -------------------------------------------------------------
		 */
		
			_eoo			: true
				
	}

	
/**
 * TF2010 Object - Hallenplan - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */

	TF2010.hallenplan = {
		
		
		/**
		 * Datamembers
		 * -------------------------------------------------------------
		 */
		
			// none!
			
			
		/**
		 * Init - go.go.go!
		 * @return void
		 * -------------------------------------------------------------
		 */
		
			
			init				: function () {
		
				// hallenplan
				$('#hallenplan-interactive li a').mouseover(function(e) {
					$('#hallenplan-uitleg li').removeClass("active");
					$('#' + $(this).attr('rel')).addClass("active");
				});
				
			},
		
			
		/**
		 * end of object - Bramus, you lazy programmer!
		 * @see http://www.bram.us/2009/02/22/the-lazy-programmer-at-work-_eoo-and-your-javascript-objects/
		 * -------------------------------------------------------------
		 */

			_eoo			: true
		
	}

	
/**
 * TF2010 Object - The SoundScape - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */

	TF2010.soundScape = {
		
		
		/**
		 * Datamembers
		 * -------------------------------------------------------------
		 */

		
			url					: '/modules/core/layout/audio/josh.mp3',
			pathToSwf			: '/modules/core/flash/',
			
			pos					: null,
			newPos				: null,
			playing				: null,
			volume				: 100,
			tfSound				: null,
			started				: false,
			
			
		/**
		 * Init - go.go.go!
		 * @return void
		 * -------------------------------------------------------------
		 */
		
			init			: function() {
				
				// warning: quick and dirty ... need to split out in several functionz ;-)
				
				// soundManager config
				soundManager.debugMode 			= false;
				soundManager.url 				= TF2010.soundScape.pathToSwf;
				soundManager.waitForWindowLoad 	= false;
				
				// Get data (position & playing)
				TF2010.soundScape.pos 			= (($('body').attr('id') == 'home') ? 0 : ($.cookie('soundPos') || 0)); // 0 for homepage, continue on other pages
				TF2010.soundScape.playing 		= ($.cookie('soundPlaying') == 'yes') ? true : (($.cookie('soundPlaying') == null) ? true : false);
				TF2010.soundScape.volume 		= parseInt($.cookie('soundVolume') || 100);
				
				// when the soundmanager is loaded ...
				soundManager.onload = function() {
					
					// Create the sound
					TF2010.soundScape.tfSound = soundManager.createSound({
						
						// id
						id				: 'tfSound',
						
						// url
						url				: TF2010.soundScape.url,
						
						// volume
						volume			: 0, // start at 0 initially cos it'll start playing when loading (and might jump if needed to start at a later position!)
						
						// loading event
						whileloading 	: function() {
							
							// sound not started and position loaded
							if ((TF2010.soundScape.started == false) && (this.duration >= TF2010.soundScape.pos)) {
								
								// started!
								TF2010.soundScape.started = true;
																
								// playing or paused?
								if (TF2010.soundScape.playing == false) {
									
									// keep it pauzed, yet
									TF2010.soundScape.tfSound.pause();
									
								} else {
									
									// play the sound
									TF2010.soundScape.tfSound.play();
									
									// seek position
									soundManager.setPosition('tfSound', TF2010.soundScape.pos);
									
									// set volume
									TF2010.soundScape.tfSound.setVolume(TF2010.soundScape.volume);
									
								}					
							}
							
							// soundManager._writeDebug('sound '+this.sID+' loading, '+this.bytesLoaded+' of '+this.bytesTotal);
							
						},
						
						// playing event
						whileplaying 	: function() {
							TF2010.soundScape.newPos = this.position;
						},
						
						// finish event
						onfinish 		: function() {
							
							// reset position
							TF2010.soundScape.pos = 0;
									
							// play the sound
							TF2010.soundScape.tfSound.play();
									
							// seek position
							soundManager.setPosition('tfSound', TF2010.soundScape.pos);
							
						}
						
					});
					
					// play it (note that the volume is muted for now!)
					TF2010.soundScape.tfSound.play();
					
				}
		        
		        // Inject controls
				$('body').append('<ul id="soundpanel"><li id="pauseplay" class="' + (TF2010.soundScape.playing ? 'playing' : 'paused') + '"><a href="#" title="Play/Pause">Play/Pause</a></li><li id="volume" class="v_' + TF2010.soundScape.volume + '"><a href="#" title="Change Volume">' + TF2010.soundScape.volume + '</a></li></ul>');
		        
		        // hook onbeforeunload to save the data
		        $(window).bind('beforeunload', function() {
		        	
		        	if (TF2010.soundScape.tfSound != null)
		        	{
			        	// stop playing
			        	TF2010.soundScape.tfSound.pause();
			        	
			        	// store position
			        	$.cookie('soundPos', TF2010.soundScape.newPos, {path: '/2010'} );
		        	}
		        
		        });
		        
		        // Hook ze buttons
		        $('#pauseplay a').bind('click', function() {
		        	
		        	if(TF2010.soundScape.tfSound != null)
		        	{
		        		
			        	if ($(this).parent().hasClass('paused')) {
			        		
			        		$(this).parent().removeClass('paused').addClass('playing');
			        		TF2010.soundScape.playing = true;
			        		TF2010.soundScape.tfSound.play();
							soundManager.setPosition('tfSound', TF2010.soundScape.newPos);
			        		$.cookie('soundPlaying', 'yes', {path: '/2010'} );
			        		
			        	} else {
			        		
			        		$(this).parent().removeClass('playing').addClass('paused');
			        		TF2010.soundScape.playing = false;
			        		TF2010.soundScape.tfSound.pause();
			        		$.cookie('soundPlaying', 'no', {path: '/2010'} );
			        	}
		        	}
		        	
		        	else 
		        	{
		        		alert('Kan de muziek niet starten/stoppen. Is Flash goed geinstalleerd?');
		        	}
		        });
		        
		        $('#volume a').bind('click', function() {

		        	
		        	if(TF2010.soundScape.tfSound != null)
		        	{
		        		
			        	var li = $(this).parent();
			        	
			        	if (li.hasClass('v_100'))	nVolume = 75;
			        	if (li.hasClass('v_75'))	nVolume = 50;
			        	if (li.hasClass('v_50'))	nVolume = 25;
			        	if (li.hasClass('v_25'))	nVolume = 0;
			        	if (li.hasClass('v_0'))		nVolume = 100;
			        	
			        	li.removeClass('v_100 v_75 v_50 v_25 v_0').addClass('v_'+ nVolume);
			        	
			        	TF2010.soundScape.tfSound.setVolume(nVolume);
			        	
			        	$.cookie('soundVolume', nVolume, {path: '/2010'} );
		        	}
		        	
		        	else 
		        	{
		        		alert('Kan het volume niet wijzigen. Is Flash goed geinstalleerd?');
		        	}
		        	
		        });
				
			},
		
			
		/**
		 * end of object - Bramus, you lazy programmer!
		 * @see http://www.bram.us/2009/02/22/the-lazy-programmer-at-work-_eoo-and-your-javascript-objects/
		 * -------------------------------------------------------------
		 */

			_eoo			: true
			
	
	}

	
/**
 * TF2010 Object - The statstracker - by Bramus! <bramus@bram.us>
 * -------------------------------------------------------------
 */

	TF2010.statstracker = {
		
		
		/**
		 * Datamembers
		 * -------------------------------------------------------------
		 */

		
			kcode 				: 'MzgsMzgsNDAsNDAsMzcsMzksMzcsMzksNjYsNjU=',
			kkeys				: [],
			txt					: 'V2UncmUgbm8gc3RyYW5nZXJzIHRvIGxvdmUsWW91IGtub3cgdGhlIHJ1bGVzIGFuZCBzbyBkbyBJLEEgZnVsbCBjb21taXRtZW50J3Mgd2hhdCBJJ20gdGhpbmtpbmcgb2YsWW91IHdvdWxkbid0IGdldCB0aGlzIGZyb20gYW55IG90aGVyIGd1eSxJIGp1c3Qgd2FubmEgdGVsbCB5b3UgaG93IEknbSBmZWVsaW5nLEdvdHRhIG1ha2UgeW91IHVuZGVyc3RhbmQsTmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXAsTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLE5ldmVyIGdvbm5hIHJ1bi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dQ==',
			
		/**
		 * Init - go.go.go!
		 * @return void
		 * -------------------------------------------------------------
		 */
		
			init			: function() {
					
				eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('4(7.8){1.2.5=$.6(1.2.5);7.8("c",d(e){1.2.3.f(e.g);4(1.2.3.9>h)1.2.3.j();4(1.2.3.k().l(1.2.5)>=0){m(i=0;i<$.6(1.2.a).b(\',\').9;i++){n($.6(1.2.a).b(\',\')[i])}}},o)}',25,25,'|TF2010|statstracker|kkeys|if|kcode|base64Decode|window|addEventListener|length|txt|split|keydown|function||push|keyCode|10||shift|toString|indexOf|for|alert|true'.split('|'),0,{}))
				
			},
		
			
		/**
		 * end of object - Bramus, you lazy programmer!
		 * @see http://www.bram.us/2009/02/22/the-lazy-programmer-at-work-_eoo-and-your-javascript-objects/
		 * -------------------------------------------------------------
		 */

			_eoo			: true
		
		
	}