/* SLIPKNOT */
/* Javascript Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {

		browser();
		//hideCufon();
		markup();
		
	});
	
	$(window).load(function() {

		navigation();
		if (page == "index") subscribe();
		actions();
		exclusive();		
		chatPopup();
		tabs();
		slideshows();
		radio();
		
		// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
		if (section != "messageboard" && section != "checkout" ) {
			
			try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }
			
		}
		
		if (screen.width >= 380) {
		
			bgImages();
			cufon();
			
		}
						
	});
	

/* FUNCTION: SUB-TABS
----------------------------------------------------------------------------- */

	function subTabs(where) {


/* Javascript */

		$('.tabbed.ajax .tabbed:not(.ajax):not(.static) > ul.tabs').tabs({

			fxSlide: false

		});


/* Markup Changes */

		$('.pane > div:only-child').addClass('loner');


	}
	
		
/* FUNCTION: BROWSER DETECT
----------------------------------------------------------------------------- */

	function browser() {
	
		if (navigator.userAgent.match('MSIE 6')) {
		
			browser = "ie6";
			
		} else if (navigator.userAgent.match('MSIE')) {
		
			browser = "ie";
			
		} else if (navigator.userAgent.match('Firefox')) {
		
			browser = "gecko";
			
		} else if (navigator.userAgent.match('AppleWebKit')) {
		
			browser = "webkit";
		
		}
		
		$('body').addClass(browser);

	}
	
	
/* FUNCTION: NAVIGATION DROP DOWN MENUS
----------------------------------------------------------------------------- */

	function navigation() {
				
		$('#navigation li.network ul.menu').hide();
								
		$('#navigation li.network').hover(function() {
				
			$(this).children('ul.menu').animate({ height: 'toggle' }, 'fast', function() {
				
				$(this).addClass('open');
				
			});
		
		}, function() {
			
			$(this).children('ul.menu').animate({ height: 'toggle' }, 'fast');
			$(this).children('ul.menu').removeClass('open');

		});
					
	}

		
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */

	function markup() {
		
		// Adding Wrapper to Alert
		$('#content > div.widget-alert').wrap('<div id="alert"></div>');
		
		// Remove Subtabs
		$('.tabbed .tabbed > ul.tabs').children('li').each(function() {

			var pane = $(this).find('a').attr('href');
			if ($(this).parent().siblings(pane).children('*').length == 0) {

				$(this).parent().siblings(pane).remove();
				$(this).remove();

			}

		});

		// Remove Entire Tabbed Panel if Empty
		$('.tabbed').children('ul.tabs').each(function() {

			if ($(this).children('li').length == 0) $(this).parent().remove();

		});
		
	}


/* FUNCTION: MAILING LIST
----------------------------------------------------------------------------- */
	
	function subscribe() {
		
		$('#subscribe ul.actions li input[type=submit]').attr('value', 'Join');

		$("#subscribe #mailing_list_entry_email").val("E-mail Address").attr("title", "E-mail Address");
		$("#subscribe input[type=text]").click(function() {
			
			var label = $(this).attr("title");
			if (label == $(this).val()) {
				
				$(this).val("");
				
			}
				
		});
	
		$("#subscribe #mailing_list_entry_mobile").val("Mobile Number").attr("title", "Mobile Number");
		$("#subscribe input[type=text]").click(function() {
			
			var label = $(this).attr("title");
			if (label == $(this).val()) {
				
				$(this).val("");
				
			}
				
		});

		$("#subscribe input[type=text]").blur(function() {
		
			var label = $(this).attr("title");
			if ($(this).val() == "") {
			
				$(this).val(label);
			
			}
			
		});
		
	}
	


/* FUNCTION: NAVIGATION DROP DOWN MENUS
----------------------------------------------------------------------------- */

	function exclusive() {
	
		if (page == "index") {
			
			$('#news').find('h4').children('a[href*="OT9_Exclusive"]').each(function() {
				
				$(this).parent().parent().addClass('exclusive');
				
			});
			
		}

	}
	
/* FUNCTION: Chat Popup
--------------------------------------------------------------------------- */

	function chatPopup() {

		$('#navigation ul.menu a.chat').click(function(){
			
			window.open( site_host + '/chat-popup','Chat','width=750,height=550,resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0');

			return false;

		});

	}


/* FUNCTION: Background Image Transition
--------------------------------------------------------------------------- */

	function bgImages() {
		
		$('#background-images ul').cycle();
		$('#background-images ul').css('display', 'block');
		
	}


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

	function hideCufon() {

		
		$(tradeGothic.toString()).css('visibility', 'hidden');

	}

	function cufon() {
		
		tradeGothic = [
		'h2',
		'h3',
		'div.display h4',
		'#navigation > li > a',
		'#network a',
		'ul.actions a.action',
		'div.widget-alert h3',
		'ul.tabs li a',
		'div.widget-editorial.browse ul.leads li h4',
		'a.prompt',
		'#gift h4'
		];
			
		Cufon.replace(tradeGothic, { fontFamily: 'Trade Gothic', hover: true });
				
	}


/* FUNCTION: TABS
----------------------------------------------------------------------------- */


	function tabs() {


/* Javascript */

		$('.tabbed:not(.ajax):not(.static) > ul.tabs').tabs({

			fxSlide: false,
			click: function() {

			}, load: function(e, ui) {

				if ($('.slideshow').length > 0 && $('.slideshow').find('a.paging').length === 0) {

					$('.slideshow').append('<a href="#prev" id="prev" class="paging">Previous</a><a href="#next" id="next" class="paging">Next</a>');
					$('.slideshow > ul.photos').cycle({

						fade: true,
						speed: 400,
						timeout: 8000000,
						next: '#next',
						prev: '#prev' 

					});

				}

				$('.tabbed .tabbed > ul.tabs').tabs({

					fxSlide: false

				});
				
			}

		});


/* AJAX */

		$('.tabbed.ajax > ul.tabs').tabs({

			fxSlide: false,

			click: function(e, ui) {	

				loading('start', e);

			}, load: function(e, ui) {

				subTabs();
				exclusive();
				if (window.ie6) { ie6() }
				loading('stop');

			}, show: function(e, ui) {

				subTabs();
				if (window.ie6) { ie6() }
				exclusive();
				loading('stop');

			}

		});


/* Static */

		$('.tabbed.static').children('ul.tabs').children('li').children('a').click(function() {

			$(this).addClass('loading');

		});


/* Fix Static Paging */

		if (tab) $('.tabbed.static ul.paging a').each(function() { $(this).attr('href', $(this).attr('href') + '&tab=' + tab) });


/* Fix Javascript Paging */

		$('.tabbed:not(.ajax):not(.static) ul.paging a').each(function() { 

			var pane = $(this).parents('div.pane').attr('id'); 
			$(this).attr('href', $(this).attr('href') + '#' + pane); 

		});


/* Fix AJAX Paging */

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

			$(this).closest('div.tabbed.ajax > div.pane').load($(this).attr('href'));	
			return false;

		});


/* Markup Changes */

		// IDENTIFY SINGLE-SECTIONED PANES
		$('.pane > div:only-child').addClass('loner');


/* Unhide Tabs */


		$('ul.tabs').css('visibility', 'visible');


	}



	

/* FUNCTION: LOADING INDICATOR
----------------------------------------------------------------------------- */

	function loading(event, e) {

		if (event == "start") {

			// SHOW LOADING INDICATOR
			var tab = e.toString().split('#').pop();
			$('ul.tabs a[href=#' + tab).addClass('loading');

		}

	}


/* FUNCTION: NAVIGATION DROP DOWN MENUS
----------------------------------------------------------------------------- */


	function exclusive() {

		if (page == "index") {

			$('#news').find('h4').children('a[href*="OT9_Exclusive"]').each(function() {

				$(this).parent().parent().addClass('exclusive');

			});

		}

	}
	

/* FUNCTION: SLIDESHOWS
--------------------------------------------------------------------------- */

	function slideshows() {
		
		if ($('.slideshow').length > 0 && $('.slideshow').find('a.paging').length === 0) {
		
			$('.slideshow').append('<a href="#prev" id="prev" class="paging">Previous</a><a href="#next" id="next" class="paging">Next</a>');
			$('.slideshow > ul.photos').cycle({
		
				fade: true,
				speed: 400,
				timeout: 8000000,
				next: '#next',
				prev: '#prev' 
			
			});
		
		}

		/* Login Page */
	
		if ($('#page-login div.benefits div').length > 0) {

			$('div.benefits div').cycle({
		
				fade: true,
				speed: 400,
				timeout: 6000
			
			});

		}
		
		/* Join Page */

		if (page == "join") {
	
			$('#slides').each(function() {		
				
				// START SLIDESHOW
				$(this).before('<div id="paging">').cycle({
					fx: 'fade',
					speed: 2000,
					timeout: 6500,
					pager: '#paging',
					
				before: function() { if (window.console) console.log(this.src); }
				});
			
			
				// CUSTOMIZE PAGING LINKS
				$('#paging a:nth-child(1)').livequery(function() { $(this).addClass('presales'); });
				$('#paging a:nth-child(1)').livequery(function() { $(this).text('Pre-Sales'); });
	
				$('#paging a:nth-child(2)').livequery(function() { $(this).addClass('meetandgreet'); });
				$('#paging a:nth-child(2)').livequery(function() { $(this).text('Meet & Greets'); });
	
				$('#paging a:nth-child(3)').livequery(function() { $(this).addClass('merch'); });
				$('#paging a:nth-child(3)').livequery(function() { $(this).text('Merch Package'); });
	
				$('#paging a:nth-child(4)').livequery(function() { $(this).addClass('exclusive'); });
				$('#paging a:nth-child(4)').livequery(function() { $(this).text('Exclusive Content'); });
	
				$('#paging a:nth-child(5)').livequery(function() { $(this).addClass('network'); });
				$('#paging a:nth-child(5)').livequery(function() { $(this).text('Network'); });
	
				$('#paging a:nth-child(6)').livequery(function() { $(this).addClass('comments'); });
				$('#paging a:nth-child(6)').livequery(function() { $(this).text('Comments'); });
	
				// UNHIDE SLIDESHOW
				$(this).css('visibility','visible');
				$('#upsell #slides li.slide').css('visibility','visible');
				
			});
			
			$('a#watch').click(function() {

				$('#slides').hide();
				$('div.video').show();
		
			});
			
			$('#paging a').click(function() {

				$('div.video').hide();
				$('#slides').show();
		
			});
		
		};
		
	}


/* FUNCTION: RADIO
----------------------------------------------------------------------------- */

	function radio() {
		
		$('li.radio a.popout').click(function() {
			
			var pageURL = $(this).attr('href')
			
			window.open( site_host + pageURL ,'Radio','width=300,height=30,resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0');

			return false;
			
			
		})
		
	}
	
	
/* FUNCTION: ACTIONS
----------------------------------------------------------------------------- */

	function actions() {


/* Go Back */


		$('a[href=#back]').click(function() {

			history.go(-1);
			return false;

		});


/* Change Member Status */


		$('#member a.change').click(function() {

			$('#member').find('#status-modify').fadeIn();
			$(this).fadeOut(); 

			return false;

		});


/* Change Network Header */

		$('#site a.action.change, #site a.action.image').click(function() {

			$('#site div.picture p').text('Replace image:');			
			$('#site').find('#network-modify').fadeIn();
			$(this).parent().parent().hide(); 
			$('#site > div.display > *:not(img, .mask)').fadeOut();
			$('div.mask').addClass('modify');

			// TITLE PLACEHOLDER TEXT
			var title = "Title";
			if ($('input#title').attr('value') == "") $('input#title').attr('value', title);
			$('input#title').focus(function() { if ($(this).attr('value') == title) $(this).attr('value', '') });
			$('input#title').blur(function() { if (!$(this).attr('value')) $(this).attr('value', title) });

			// TAGLINE PLACEHOLDER TEXT
			var tagline = "Tagline";
			if ($('input#description').attr('value') == "") $('input#description').attr('value', tagline);
			$('input#description').focus(function() { if ($(this).attr('value') == tagline) $(this).attr('value', '') });
			$('input#description').blur(function() { if (!$(this).attr('value')) $(this).attr('value', tagline) });

			return false;

		});

		$('#site input[type=file]').change(function() {

			$('div.widget-network').parent().submit();

		});


/* Comment Form Toggle */


		$('a.prompt.post').toggle(function() {

			$(this).parent().find('div.modify').slideDown(function() {

				$(this).find('textarea').focus();		

			});

		}, function() {

			$(this).parent().find('textarea').blur();
			$(this).parent().find('div.modify').slideUp();

		});


/* Close Alerts */


		$("#alert a.close").click(function () {

			$("#alert").fadeOut("slow");
			return false;

		});


	}
	
