/* BLOOD PACT - STANDARD TEMPLATE SKIN */
/* Common Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {

	});


/* POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */


	$(window).load(function() {


/* INITIALIZE TABS
----------------------------------------------------------------------------- */


	$('div.tabbed').show();
	$('div.tabbed > ul').tabs({

		show: function() {

			if (page == 'index') {
				photoSlideshow();
			}
			truncate();

		}

	});

	$('ul.tabs').each(function() {

		$(this).wrap('<div class="constrain"></div>');

		var computed = $(this).width();
		var parent = $(this).parent().css('width');
		var padding = parseInt(parent) - parseInt(computed);
		var padding = padding / 2;
		var width = parseInt(parent) - parseInt(padding);

		$(this).css('padding-left', padding + 'px');
		$(this).css('width', width + 'px');

	});
	

/* HIDE VIDEO PROMO CATEGORY
----------------------------------------------------------------------------- */


	if (page == "videos") {
	
		$('div.widget-tag a:contains("Promo")').parent('li').hide();
	
	}


/* HIDE POLITICS & RELIGION DEFINITION LIST
----------------------------------------------------------------------------- */


	if (page == "profile") {
	
		$('dt:contains("Politics"), dt:contains("Politics") + dd').hide();
		$('dt:contains("Religion"), dt:contains("Religion") + dd').hide();
	
	}


/* FANS DROPDOWN
----------------------------------------------------------------------------- */


	$('ul#navigation li.fans').hover(function() {
	
		$(this).children('ul').addClass('hover');
	
	}, function() {
	
		$(this).children('ul').removeClass('hover');

	});


/* REWORDING
----------------------------------------------------------------------------- */


	$('#page-going div.placeholder p').text("You haven't RSVP'd for any events yet. Been to a show? Find it and let us know!");
	$('div.widget-member.info dt.comments').text("Comments");


/* SIGN IN PAGE
----------------------------------------------------------------------------- */


	if (page == 'login') {

		$('div.benefits div').cycle({
	
			fade: true,
			speed: 400,
			timeout: 6000
		
		});
		
		$('a#watch').click(function() {

			$('div.benefits').hide();
			$('div.video').show();

			var player = $('div.video div.flash div').attr('id');			
			eval(player)();
		
		});
		
		$('a#benefits').click(function() {
		
			var player = $('div.video div.flash div').attr('id');			

			$('#' + player).empty();
			$('div.video').hide();
			$('div.benefits').show();
		
		});

	}
	
	
/* TABBED AJAX PAGING
----------------------------------------------------------------------------- */


	paging();


/* TRUNCATE TEXT
----------------------------------------------------------------------------- */


	truncate();

	
/* COMMENTS
----------------------------------------------------------------------------- */
	
	
	comments();


/* Load Forum Threads
----------------------------------------------------------------------------- */


	// Load Forum Feed
/*	$.get('/feeds/external/forum.xml', function(data) {
	
		$(data).find('item').each(function() { 

			var title = $(this).children('title').text();
			var link = $(this).children('link').text();
											
			$('<li><h4><a href="' + link + '">' + title + '</a></h4></li>').appendTo('#forum ul.threads');

		});
		
		$('#forum ul.threads li:last').addClass('last');
		$('#forum ul.threads li:odd').addClass('alt');
		
		// Truncate Thread Titles
		$('#forum ul.threads > li').each(function(){
			
			if ($(this).children().children('a').text().length >= 36) {
							
				var text = $(this).children().children('a').text().slice(0,36);

				$(this).children().children('a').text(text);
				$(this).children().children('a').append('<var>&hellip;</var>');
			
			}
						
		});
		
				
	});*/


/* END POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */

	
	});
	

/* FUNCTION: TABBED AJAX PAGING
----------------------------------------------------------------------------- */


	function paging() {

		$('.tabbed ul.pages a').livequery('click', function(event) {


			$(this).parents('div.pane').load($(this).attr('href'), function(data) {

				truncate();

			});
						
			return false;

		});
		
	}


/* FUNCTION: COMMENTS
--------------------------------------------------------------------------- */


	function comments() {

		// ADDS CANCEL BUTTON FUNCTIONALITY
		$('#comment a.cancel').click(function() {

			$('#comment textarea').val('');
			$('#comments').siblings('div.constrain').children('ul').tabsClick(1);				
			return false;

		});
		
		
		// SWITCH TO ADD COMMENT TAB ON CLICK
		$('#firstcomment').click(function() {

			$('#comments').siblings('div.constrain').children('ul').tabsClick(2);
			return false;

		});
	
	}
	
	
/* FUNCTION: TRUNCATE TEXT
----------------------------------------------------------------------------- */

	function truncate() {

		// VIDEO TITLES
		$('ul.clips li div > a:first-child').each(function() {
		
			if ($(this).text().length >= 25) {
		
				var text = $(this).text().slice(0,25);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});
		
		// MEMBER STATUS
		$('div.grid.split .member dd.status').each(function() {
		
			if ($(this).text().length >= 40) {
		
				var text = $(this).text().slice(0,40);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
		
			}
		
		});	
	
		$('div.grid.two_thirds .member dd.status').each(function() {
		
			if ($(this).text().length >= 25) {
		
				var text = $(this).text().slice(0,25);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});	

		// MEMBER ALIAS
		$('div.grid.split .member a.alias strong').each(function() {
		
			if ($(this).text().length >= 11) {
		
				var text = $(this).text().slice(0,11);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
		
			}
		
		});	
	
		$('div.grid.two_thirds .member a.alias strong').each(function() {
		
			if ($(this).text().length >= 12) {
		
				var text = $(this).text().slice(0,12);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});	

	}
