/* BRAVADO */
/* Javascript Functions
--------------------------------------------------------------------------------- */

	
	$(window).load(function() {
	
		$('#footer div.widget-alert').insertBefore('#mailing-list'); 	
		flash();

	});

	
/* FUNCTION: FLASH
--------------------------------------------------------------------------------- */


	function flash() {
	
		
/* Header */


		if ($('#header').length > 0) {

			var _color = "";
			switch (section) {
				case "services":
					_color = "yellow";
				break;
				
				case "news":
					_color = "red";
				break;
				
				case "contact":
					_color = "blue";
				break;
			}
			
			var tagString = (getTags( "tags" ) == "undefined")?tag.split("-").join(";"):getTags( "tags" );
			var so = new SWFObject(asset_host + "/flash/bravado_header.swf", "header", "100%", "100%", 9, "#000000");

			so.addParam("allowScriptAccess", "always");
			so.addVariable( "sectionName", section );
			so.addVariable( "color", _color );
			so.addVariable( "tagString", tagString );
			so.addVariable( "XMLLoc", asset_host + '/xml/header_backgrounds.xml');
			so.addVariable("assetHost", asset_host);
			so.addParam( "wmode", "transparent" );
			so.write("flash");
		
		}
	
	
/* Featured Merch */

	
		if ($('#featured').length > 0) {
		
			/*
			var so = new SWFObject(asset_host + "/flash/featuredmerch.swf", "featuredmerch", "100%", "100%", 9, "#ffffff");
			so.addParam("allowScriptAccess", "always");
			so.write("featured");
			*/
			
		}


	}
	
	
/* FUNCTION: GET URL TAGS */


	function getTags( variable ) {
		var query = window.location.search.substring( 1 );
		var vars = query.split("&");
		var ret = "undefined";
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
			 	ret =  pair[1];
			}
		} 
		return ret;
	}
	
	
/* FUNCTION: MARKUP
--------------------------------------------------------------------------------- */


	function markup() {
	
		
/* Add Dates to News Headlines */


		// LEADS
		$('#news').children('ul.leads').children('li').each(function() {
		
			var date = $(this).children('strong').text().replace(', 2008','').replace(', 2009','').replace(', 2010','').replace(', 2011','');
			$(this).children('h4').children('a').text(date + ' - ' + $(this).children('h4').children('a').text());
			
			$(this).children('ul.actions').children('li:first-child').children('a').appendTo($(this).children('div.story').children('*:last-child'));
		
		});
		
		// STORY
		$('#story').each(function() {
		
			var date = $(this).children('strong').text().replace(', 2008','').replace(', 2009','').replace(', 2010','').replace(', 2011','');
			$(this).children('h4').text(date + ' - ' + $(this).children('h4').text());
					
		});
		
		
/* Add Prompt to Mailing List Opt-In */

		
		if ($('#story').length > 0) {
		
			$('#story').append('<a href="#back">Go Back</a>');
		
		}
		
		
/* Artist Page */

		
		if (page == "artists") {
		
			// ALTERNATING STYLES
			$('#artists div.story > p:even').addClass('alt');
			
			// LINK CONTAINER
			$('#artists div.story > p').each(function() {
			
				$(this).children('a, small').wrapAll('<span></span>');
			
			});
			
			// TARGET=BLANK
			$('#artists div.story a').each(function() {
			
				$(this).attr('target', '_blank');
			
			});
		
		}
		
		
	
	}
	
	
/* FUNCTION: LINKS
--------------------------------------------------------------------------------- */


	function links() {
	
	
/* Back */


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


	function artists() {

		$('#artists p').hover(function() {
		
			$(this).addClass('hover');
		
		}, function() {
		
			$(this).removeClass('hover');

		});
	
	}
