/* THE KILLERS */
/* Javascript Master
-------------------------------------------------------------------------------- */
	

	$(document).ready(function() {

		// Remove New Window Attribute from Pre-sale Link
		$('#event a.presale').attr('target','');

		getTime();
	   	
		if (page != "member-nav") {
	
			flash();
		
		}
		
		// Member Nav Links Reload Page instead of in iframe
		if (page == "member-nav") {
			
			$('a').each(function() {
				
				$(this).attr('target', '_parent');
				
			});
			
		}

	});


	$(window).load(function() {

		// Remove New Window Attribute from Pre-sale Link
		$('#event a.presale').attr('target','');
	
		tabs();
		markup();
	

/* REMOVE NEW WINDOW ATTRIBUTE FROM PRE-SALE LINK
----------------------------------------------------------------------------- */


		$('#event a.presale').attr('target','');


/* REMOVE LINK FROM EDITORIAL STORY 
----------------------------------------------------------------------------- */
	
	
		$('#qa ul li h4 a').attr('href', '');
		
		
/* HAVE MUSIC SECTION'S VIDEO LINKS OPEN UP IN NEW WINDOW
----------------------------------------------------------------------------- */


		$('#tracks td.action.watch a').attr('target', '_blank');
		
		
/* CHANGE WORDING FOR EVENT HEADINGS
--------------------------------------------------------------------------- */

	if (page == "victims") {
		
		$('#presales th.location').text('City');
		$('#presales th.details').text('Venue');
		
	}



/* FUNCTION CALLS
--------------------------------------------------------------------------- */
		

		paging();
		links();
		comment();
		target();
		cufon();
		calendar();
		
	});
	
	
/* FUNCTION: KILL FLASH INTRO WHEN DONE
----------------------------------------------------------------------------- */


	function introComplete() {

		$('div#intro').fadeOut('fast', function() {
		
			$(this).remove();
			$('body').css('overflow', 'auto');
		
		});

	}
	
	
/* FUNCTION: PAGING
----------------------------------------------------------------------------- */


	function paging() {


/* AJAX PAGING: LATEST NEWS */

	
		// INITIAL CONTENT LOAD
		$('.section-home #news').load('/index-news', function(data) {
		
			markup();
			cufon();
				
		});
		
		
		// PAGING
		$('.section-home #news ul.paging a').livequery('click', function(event) {
		
			$(this).parents('div#news').load($(this).attr('href'), function(data) {
	
				markup();
				cufon();

			});
						
			return false;
	
		});
	
	
/* TABBED AJAX PAGING */
			
			
		$('.tabbed.ajax ul.paging a').livequery('click', function(event) {
		
			loading('start');

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

				markup();
				cufon();
				loading('stop');

			});
						
			return false;

		});
		
		
/* TABBED 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); 
		
		});

	
	}
	
	
/* FUNCTION: FLASH EMBEDS
----------------------------------------------------------------------------- */
	
	
	function flash() {
	

/* SECTION: HOME */


		if (section == "home") {
		
			// INTRO
			/*
			if ($('#intro').length > 0 && $.cookie('beenHome') != "true" ) {
			
				// KILL SCROLLBAR
				$('body').css('overflow', 'hidden');

				// UNHIDE DIV
				$('#intro').css('display', 'block');
			
				// SPLASH
				var so = new SWFObject( asset_host + "/flash/killers_splash.swf", "introSWF", "100%", "100%", 9, "0x000000" );
				so.addParam( "allowScriptAccess", "always" );
				so.write( "intro" );
				
				// SET COOKIE
				$.cookie('beenHome', 'true', { expires: .25 })
				
			}
			*/
			
			// HEADER
			var head = ($('body').hasClass('day')) ? "/flash/components/dayHead.swf" : "/flash/components/nightHead.swf";
			var head_so = new SWFObject( asset_host + head, "headSWF", "100%", "100%", 9, "#000000" );
			head_so.addParam( "wmode", "transparent" );
			head_so.addParam( "allowScriptAccess", "always" );
			head_so.addVariable( "shadowMaskY", 20 );
			head_so.addVariable( "site_host" , site_host + '/' );
			head_so.addVariable( "logged_in" , logged_in );
			head_so.write( "header" );
			
			// SIGNAGE: LEFT SIDE
			var sl = ($('body').hasClass('day')) ? "/flash/components/leftDayStrut.swf" : "/flash/components/leftNightStrut.swf";
			var sl_so = new SWFObject( asset_host + sl, "slSWF", "100%", "100%", 9, "#000000" );
			sl_so.addParam( "wmode", "transparent" );
			sl_so.write( "left" );
			
			// SIGNAGE: RIGHT SIDE
			var sr = ($('body').hasClass('day')) ? "/flash/components/rightDayStrut.swf" : "/flash/components/rightNightStrut.swf";
			var sr_so = new SWFObject( asset_host + sr, "srSWF", "100%", "100%", 9, "#000000" );
			sr_so.addParam( "wmode", "transparent" );
			sr_so.write( "right" );
		
		} else {
		
			// CROP SHADOW
			if (section == "road") var shadowMaskY = 19;
			if (section == "band") var shadowMaskY = 128;
			if (section == "gallery") var shadowMaskY = 0;
			if (section == "victims") var shadowMaskY = 19;
			if (section == "music") var shadowMaskY = 49;
			if (section == "extras") var shadowMaskY = 19;
			if (section == "contact") var shadowMaskY = 128;
			if (section == "account") var shadowMaskY = 19;
			if (section == "legal") var shadowMaskY = 19;
			if (page == "placeholder") var shadowMaskY = 19;

			// NAVIGATION
			var _nav = ( $('body').hasClass('day')) ? "/flash/components/dayNav.swf" : "/flash/components/nightNav.swf";
			var nav_so = new SWFObject( asset_host + _nav, "navSWF", "100%", "100%", 9, "#000000" );
			nav_so.addParam( "allowScriptAccess", "always" );
			nav_so.addParam( "wmode", "transparent" );
			nav_so.addVariable( "site_host" , site_host + '/' );
			nav_so.addVariable( "logged_in" , logged_in );
			nav_so.addVariable( "shadowMaskY", shadowMaskY );
			if ( section == "contact" ) nav_so.addVariable( "noShadow", "true" );
			nav_so.write( "header" );
			
			
			if ( section == "band" ) {
			
				var bio_so = new SWFObject( asset_host + "/flash/killers_bio.swf", "bioSWF", "100%", "100%", "9", "#000000" );
				bio_so.addParam( "wmode", "transparent" );
				bio_so.addVariable( "xmlLoc", asset_host + "/xml/bios.xml" );
				bio_so.write( "main" );
			
			}
			
			if ( section == "contact" ) {
			
				contact_so = new SWFObject( asset_host + "/flash/mailingList.swf", "contactSWF", "700", "100%", "9", "#000000" );
				contact_so.addParam( "wmode", "transparent" );
				contact_so.write( "main" );
			
			}
			
			if ( page == "music" ) {
				marquee_so = new SWFObject( asset_host + "/flash/music_marquee.swf" , "marqueeSWF", "774", "76", "9", "#000000" );
				marquee_so.addVariable( "xmlLoc", asset_host + "/xml/marquee.xml" );
				marquee_so.write( "marquee" );
			}
			
		}
	
	}
	
	
/* FUNCTION: TABS
----------------------------------------------------------------------------- */
		
		
	function tabs() {


/* JAVASCRIPT TABS */


		$('.tabbed:not(.static):not(.ajax) > ul.tabs').tabs({
			
			fxSlide: false,
			
			click: function() {	
					
			}, load: function() {

			}, show: function() {
			

			}
	
		});
		
		
/* AJAX TABS */

		
		$('.tabbed.ajax > ul.tabs').tabs({
			
			fxSlide: false,
			
			click: function() {	
			
				loading('start');
				cufon();
				
			}, load: function() {
		
				loading('stop');
				cufon();

			}, show: function() {
			
				loading('stop');

			}
	
		});
		
	}

	
/* FUNCTION: GET TIME OF DAY
----------------------------------------------------------------------------- */


	function getTime() {
	
		if (typeof(time) == "undefined") {
	
			var hour =  new Date().getHours();
			
			if (hour < 6) {
			
				$('body').addClass('night');
			
			} else if (hour < 8) {
			
				$('body').addClass('dawn');
	
			} else if (hour < 16) {
			
				$('body').addClass('day');
	
			} else if (hour < 18) {
			
				$('body').addClass('dusk');
	
			} else {
			
				$('body').addClass('night');
	
			}
		
		} else {
		
			$('body').addClass(time);
		
		}
		
	}

	
/* FUNCTION: LINK BEHAVIORS
----------------------------------------------------------------------------- */


	function links() {
	

/* CHAT ROOM */


		$('a[href=#chat]').click(function() {
		
			window.open('/chat', 'chat', 'width=750, height=550, scrollbars=0, status=1, toolbar=0, location=0, resizable=1, menubar=0');
			return false;

		});
		
		
/* BACK LINKS */


		$('a[href=#back]').click(function() {
		
			history.go(-1);
			return false;
		
		});
		
	}
	

/* FUNCTION: MARKUP CHANGES
-------------------------------------------------------------------------------- */
	
	
	function markup() {
		
		
/* HOME PAGE */


		if (section == "home") {
		
			// SIFR HEADLINES
			$('#news ul.headlines > li').each(function() {
			
				$(this).children('span').remove();
				$(this).children('strong').append(' - ');
				$(this).children('strong, a:not(.comments)').wrapAll('<div></div>');
				
				// TRUNCATE NEWS HEADLINES (47/46) w/ comment tally
				if ($(this).children('div').children('a').text().length > 46) {
				
					$(this).children('div').children('a').text($(this).children('div').children('a').text().substring(0, 45) + '...');
				
				}
				
			});
			
			// PRESALE LABELS
			if ($('#presales').length > 0) {
			
				$(this).find('th.location').text('City');
				$(this).find('th.starts').text('Pre-Sales Start');
				$(this).find('th.ends').text('Pre-Sales End');

			}
			
		}
		
		
/* TRUNCATE SIFR WELCOME MESSAGE */


		//$('#membernav li.welcome var').each(function() {

			if ($('#membernav li.welcome var').text().length > 18) {
			
				$('#membernav li.welcome var').text($('#membernav li.welcome var').text().substring(0, 15) + '...');
				
			}
			
		//});
	

/* SEARCH DISCLAIMER */


		if ($('#search').length > 0 && $('#search').find('p').length < 1) $('div.group.specific').prepend('<p>Note that some members will not appear in search results due to their privacy preferences. Members who have not been active in the past 90 days will also not appear.</p>');
		

/* ADDING CLASS NAMES TO IMAGES  */


		$('#photos ul li a img').each(function(){
	
			$(this).parent().parent().addClass('landscape');
	
		});
		
		$('#photos ul li a img.portrait').each(function(){
	
			$(this).parent().parent().removeClass('landscape');
	
		});
		
	
	}
	
	
/* COPY AUDIO LISTEN LINK INTO DISPLAY_PAGE LINK
----------------------------------------------------------------------------- */


	function target() {

		$('ul.clips > li').each(function() {
	
			var audio = $(this).find('a.listen').attr('href');
			$(this).children('div').children('a').attr( {href: audio, target: '_blank'} );
			$(this).find('a.listen').attr( {target: '_blank'} );
	
		});
		
	}

	
/* FUNCTION: COMMENT FORM TOGGLE
----------------------------------------------------------------------------- */


	function comment() {

		$('a.prompt.post').toggle(function() {
		
			$(this).parent().find('div.modify').slideDown('normal');
		
		}, function() {
		
			$(this).parent().find('div.modify').slideUp();
		
		});
	
	}
	
	
/* FUNCTION: LOADING INDICATOR
----------------------------------------------------------------------------- */


	function loading(event) {
	
		if (event == "start") {
		
			$('#loading').animate({
			left: '0px'
			}, 300);
		
		} else {
		
			$('#loading').animate({
			left: '-54px'
			}, 300);
			
		}
	
	}
	
	
/* FUNCTION: CUFON REPLACEMENTS
----------------------------------------------------------------------------- */


	function cufon() {

		var din_condbold = [
		
			'.welcome var',
			'.section-victims #main div h3:not(#member h3)',
			'.section-home #comments .browse h3',
			'#page-account #main h3',
			'#comments .browse h3',
			'#page-story #story h4',
			'body:not(.section-home):not(#page-login):not(#page-login) *:not(.upsell) #main div:not(#member) h3',
			'body.section-legal #main h3'
						
		];
		
		var din_condblack = [
		
			'body.section-music #release h3',
			'body.section-home #news ul.headlines li div'
		
		];

		var futura_extrabold = [
		
			'body.section-join #main h3',
			'#account h4', 
			'#friendship h4',
			'#update-profile h4',
			'#upload-photo h4',
			'#upload-artwork h4',
			'#event h4',
			'#entry h4',
			'#entries h4',
			'#news-victims li h4 a',
			'#profile h4',
			'#photo h4',
			'#main h4:not(body.section-join h4)',
			'#presales h3',
			'.section-victims #sidebar h3',
			'#page-account #sidebar h3',
			'body.section-join #sidebar h3',
			'#sidebar h3',
			'#page-page div.widget-event h3',
			'div.plan h3'
		
		];
		
		var licenseplate = [
		
			'#online em'		
		];


		Cufon.replace(din_condbold, { fontFamily: 'DINCond-Bold', hover: true });
		Cufon.replace(din_condblack, { fontFamily: 'DINCond-Black', hover: true });
		Cufon.replace(futura_extrabold, { fontFamily: 'Futura', hover: true });
		Cufon.replace(licenseplate, { fontFamily: 'License-Plate', hover: true });
	
		$(din_condbold.toString()).css('visibility', 'visible');
		$(din_condblack.toString()).css('visibility', 'visible');
		$(futura_extrabold.toString()).css('visibility', 'visible');
		$(licenseplate.toString()).css('visibility', 'visible');
				
	}
	
	
/* CALENDAR FLIPBOOK STYLING
----------------------------------------------------------------------------- */


	function calendar() {
	
		if ($('#page-page div.widget-event ul.events').length > 0) {

			$('#page-page div.widget-event ul.events li > strong').each(function() {

				var date = $(this).text();
				var month = date.match(/[a-zA-Z]{3}/); 
				var day = date.match(/\d{1,2}/);
				var year = date.match(/\d{4}/);

				$(this).text('');
				$(this).prepend('<abbr>' + month + '</abbr> ');
				$(this).append('<span>' + day + '</span>').append('<abbr>' + year + '</abbr>');

			});

		}
		
	}

