/* RESEN */
/* Custom Javascript
----------------------------------------------------------------------------- */

	
	$(document).ready(function() {
	
		markup();
		cufon();
		directory();
	
	});
	
	$(window).load(function() {
	
	
	
	});
	
	
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */


	function markup() {
	
		$('#pullers .byline').each(function() {
		
			$(this).text($(this).text().replace(/^by /i, ''));
	
		});
		
		$('#sidebar #videos .next a').text('Next');
		$('#sidebar #videos .back a').text('Prev');

		$('#videos div.player').each(function() {

			embedVideo($(this).html());
		
		});
		
		$('#page-puller .body h1:contains("Stats"), #page-profile .body h1:contains("Stats")').each(function() {
		
			$(this).nextUntil('h1,h2,h3,h4,h5,hr').wrapAll('<div class="stats"></div>');
			$(this).prependTo($(this).next('.stats'));
		
		});

	}
	
	
/* FUNCTION: CUFON
----------------------------------------------------------------------------- */


	function cufon() {
	
		var replace = [
		
			'#content > div > div > h3',
			'h4',
			'ul.tabs a',
			'ul.actions a'
		
		];
	
		Cufon.replace(replace.toString(), { hover: true });
		$(replace.toString()).css('visibility', 'visible');

	}
	
	
/* FUNCTION: EMBED VIDEO
---------------------------------------------------------------------------- */


	function embedVideo(url) {
	
		// Trim whitespace
		var url = url.replace(/^\s+|\s+$|\n+|\r+/g,'');
	
		if (url.match(/^http:\/\//) && url.match(/\.flv$/) || url.match(/^http:\/\//) && url.match(/\.mp4$/)) {
						
			// JW Player
			$('div.player').attr('id', 'flash');
			
			if ($.browser.msie) {
			
				swfobject.embedSWF('/flash/player.swf', 'flash', '100%', '100%', '9', false, { file: url, autostart: false, fullscreen: true, volume: '10', bufferlength: 5 }, { allowfullscreen: true, allowscriptaccess: 'always', id: 'player' });

				setTimeout(function() {
				
					var player = document.getElementById('flash');
					player.sendEvent('play');
					
				}, 500);
			
			} else {
			
				swfobject.embedSWF('/flash/player.swf', 'flash', '100%', '100%', '9', false, { file: url, autostart: false, fullscreen: true, volume: '10', bufferlength: 5 }, { allowfullscreen: true, allowscriptaccess: 'always', id: 'player' });

			}
			
		} else if (url.match(/youtube/i)) {
				
			// YouTube
			// var videoID = $('#sidebar #videos embed').attr('src') + "&autoplay=1";
			// $('#sidebar #videos embed').attr('src', videoID);
		
		}
	
	}
	
	
/* FUNCTION: DIRECTORY
---------------------------------------------------------------------------- */


	function directory() {
	
	
/* Region Selector */


		$('#world select').change(function() {
		
			var variable = $(this).attr('name');
			var value = $(this).val();
			window.location = "?" + variable + "=" + value;
		
		});
		
		
/* Entry Form */


		$('a[href=#directory_submit]').click(function() {
		
			$('#overlay').show();
			return false;
		
		});
		
		$('#overlay .close').click(function() {
		
			$('#overlay').hide();
			return false;
		
		});
	
	}
