/* WOLFMOTHER */
/* Javascript Triggers and Custom Functions
----------------------------------------------------------------------------- */


	$(window).load(function() {

		if (section != "messageboard" && section != "checkout" ) {
		
			navigation();
		//	login();
			if (page == "index" || page == "news" || section == "client") readmore();
			tabs('removeEmptyTabs');
			truncate();
			comments();
			paging();
			markup();
			twitter();
			videoPlayer();
			
			// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
			try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }

			// Initializing Cufon
			cufon();
			
			// Photos Page
			if (page == "photos") {
			
				photoSlideshow();

				$('div#features div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(function() {

					$('a#photos_back').show();
					$('a#photos_next').show();

				}, function() {

					$('a#photos_back').hide();
					$('a#photos_next').hide();

				});
						
			}

		}

	});
	

/* FUNCTION: Twitter
----------------------------------------------------------------------------- */


	function twitter() {
			
		if (page == "thewolfies") {
					
			$('#twitter-blurb div.tweets').tweet({

				username: "positron76",
	          	count: 1,
	          	loading_text: "Loading tweets..."

			});
			
		}
		
		if (page == "thewolfies" || page == "news" || page == "story") {
		
			$('#twitter div.tweets').tweet({

				username: "positron76",
	          	count: 6,
	          	loading_text: "Loading tweets..."

			});
		
		}
					
	}


/* FUNCTION: Markup Changes
----------------------------------------------------------------------------- */


	function markup() {
		
		// Removing Profile Link from Comments
		$('#comments ul.comments > li').each(function() {
			
			$(this).children('div.member').children('a').attr('href','#').click(function() {
				
				return false;
				
			});
			
			$(this).children('div.post').children('strong').children('span').children('a').attr('href','#').click(function() {
				
				return false;
				
			});
			
			
		});

		$('div.player object, div.player embed').attr('width','100%');
		$('div.player object, div.player embed').attr('height','100%');

	}
	

/* FUNCTION: Cufon
----------------------------------------------------------------------------- */

	function cufon() {
		
		var futura = [
		
		'#header h2', 
		'#title h3', 
		'#content h3', 
		'#discography h3', 
		'#page-account #sidebar h3', 
		'#page h4',
		'#h4 a',
		'ul.tabs li a',
		'a.action.details', 
		'a.action.tickets', 
		'a.action.browse', 
		'a.action.join', 
		'a.action.follow', 
		'a.action.redeem',
		'#page-account a.action',
		'ul#navigation li a',
		'ul#sub-navigation li a',
		'ul.paging a'
		
		];
		
   		Cufon.replace(futura, { fontFamily: 'Futura-Medium', hover: true });
   		
   		$(futura.toString()).css('visibility', 'visible');

		
	}
	
	
/* FUNCTION: LOGIN PAGE PROMO
----------------------------------------------------------------------------- */

	function login() {
	
		if (page == "login") {
	
			// APPEND NOTE TO SIGN IN BUTTON
			$('div.widget-account.signin em.email').append(' *');
			$('div.widget-account.signin ul.actions').after('<small class="note">* You must now use your email address to sign in. Contact <a href="mailto:support@allaccesstoday.com" target="_blank">customer support</a> if you do not remember the email address on your account.</small>');
	
			// START PACKAGE TIER SLIDESHOW
			$('ul.tiers').before('<div id="paging">').cycle({
	
				fade: true,
				speed: 400,
				timeout: 9000,
				pager: '#paging',
				before: function() { if (window.console) console.log(this.src); }
	
			});
	
			// START UPSELL BENEFITS SLIDESHOW
			$('div#benefits ul').cycle({
	
				fade: true,
				speed: 400,
				timeout: 6000
	
			});
	
			// CUSTOM PAGING LINKS
			$('#paging a:nth-child(1)').livequery(function() { $(this).addClass('basic'); });
			$('#paging a:nth-child(1)').livequery(function() { $(this).text('Basic'); });
			$('#paging a:nth-child(2)').livequery(function() { $(this).addClass('deluxe'); });
			$('#paging a:nth-child(2)').livequery(function() { $(this).text('Deluxe'); });
			$('#paging a:nth-child(3)').livequery(function() { $(this).addClass('premier'); });
			$('#paging a:nth-child(3)').livequery(function() { $(this).text('Premier'); });
			
		}
		
	}
	
	
/* FUNCTION: TABS
----------------------------------------------------------------------------- */

	function tabs(removeEmptyTabs) {

		// KILL EMPTY TABS AND PANES
		if (removeEmptyTabs == "removeEmptyTabs") killTabs();

		// FEATURES BOX TABS
		if (page == 'thewolfies' || page == 'photos') {

			$('div#features > ul.tabs').tabs({

				show: function() {

					Cufon.refresh();

					// PHOTOS TAB
					if ($('#photos:visible').length > 0) {

						$('#video div.flash div').empty();
						$('#radio div.flash div').empty();

						photoSlideshow();

						$('div#features div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(function() {

							$('a#photos_back').show();
							$('a#photos_next').show();

						}, function() {

							$('a#photos_back').hide();
							$('a#photos_next').hide();

						});

					} 

					// RADIO TAB
					else if ($('#radio:visible').length > 0) {

						$('#video div.flash div').empty();

						photoSlideshow();

						var radio_player = $('#radio div.flash div').attr('id');
						eval(radio_player)();

					}

					// VIDEO TAB
					else if ($('#video:visible').length > 0) {

						$('#radio div.flash div').empty();

						photoSlideshow();

						var video_player = $('#video div.flash div').attr('id');
						eval(video_player)();

					}

					else {

					}

				}

			});

		}

		// JAVASCRIPT TABS
		$('div.tabbed').not("#features, .ajax, .static").children('ul.tabs').tabs({

			fxSlide: false,

			click: function() {

			}, load: function() {

				truncate();

			}, show: function() {

				truncate();
				Cufon.refresh();

			}

		});

		// AJAX TABS
		$('div.tabbed.ajax > ul.tabs').tabs({

			fxSlide: false,

			click: function() {

				loading('start');

			}, load: function() {

				truncate();
				loading('stop');

			}, show: function() {

				truncate();
				loading('stop');
				Cufon.refresh();

			}

		});
		
		
		/* Center Tabs */
			
			
		$('.tabbed:not(#featured.tabbed, #featured.tabbed .tabbed, .pane .tabbed) > ul.tabs').each(function() {
		
			var containerWidth = $(this).width();
			var tabsWidth = 0;
		
			$(this).children().each(function() {
			
				tabsWidth += $(this).width();
			
			});
			
			var paddingLeft = (containerWidth - tabsWidth) / 2;
			
			$(this).css('padding-left', paddingLeft + 'px');
			$(this).css('width', containerWidth - paddingLeft + 'px');
		
		});


	}


/* FUNCTION: VIDEO PLAYER
----------------------------------------------------------------------------- */


	function videoPlayer() {
	
		if (page == "thewolfies") {
	
			$('div.widget-media.player.video').each(function() {
			
				var $this = $(this);
			
				$('#features').hover(function() {
			
					$this.children().stop();
					$this.children('ul.controls').animate({ bottom: 0 });
					$this.children('div.details').animate({ top: 0 });
					
					// Internet Explorer
					if (navigator.userAgent.match('MSIE')) {
					
						$this.find('div.flash').children('div').animate({
						
							height: '206px',
							marginTop: '50px'
						
						});
					
					}
	
				}, function() {
				
					$this.children().stop();
					$this.children('ul.controls').animate({ bottom: '-34px' });
					$this.children('div.details').animate({ top: '-29px' });
	
					// Internet Explorer
					if (navigator.userAgent.match('MSIE')) {
	
						$this.find('div.flash').children('div').animate({
						
							height: '296px',
							marginTop: '0'
						
						});
					
					}
	
				});
				
			});
		
		} else if (page == "videos") {
	
			$('div.widget-media.player.video').each(function() {
			
				var $this = $(this);
			
				$('#features').hover(function() {
			
					$this.children().stop();
					$this.children('ul.controls').animate({ bottom: 0 });
					$this.children('div.details').animate({ top: 0 });
					
					// Internet Explorer
					if (navigator.userAgent.match('MSIE')) {
					
						$this.find('div.flash').children('div').animate({
						
							height: '320px',
							marginTop: '50px'
						
						});
					
					}
	
				}, function() {
				
					$this.children().stop();
					$this.children('ul.controls').animate({ bottom: '-34px' });
					$this.children('div.details').animate({ top: '-29px' });
	
					// Internet Explorer
					if (navigator.userAgent.match('MSIE')) {
	
						$this.find('div.flash').children('div').animate({
						
							height: '410px',
							marginTop: '0'
						
						});
					
					}
	
				});
				
			});
		
		}
	
	}

