/*
 * jQuery css clip animation support -- Jim Palmer
 * version 0.1.2
 * idea spawned from jquery.color.js by John Resig
 * Released under the MIT license.
 * 
 * http://www.overset.com/2008/08/07/jquery-css-clip-animation-plugin/
 * 
 * Updated with both (2.23.09 & 4.1.09) fixes from Martin
 */
/*
*/
(function(jQuery){
    jQuery.fx.step.clip = function(fx){
        //if ( fx.state == 0 ) { // this was the problem, it's not always 0
		if ( fx.start.constructor != Array) {
            var cRE = /rect\(([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)\)/;
            fx.start = cRE.exec( fx.elem.style.clip.replace(/[, ]+/g, ' ') );
			if (typeof fx.end !== 'object'){
				fx.end = cRE.exec( fx.end.replace(/[, ]+/g, ' ') );
			}
			
        }
        var sarr = new Array(), earr = new Array(), spos = fx.start.length, epos = fx.end.length,
            emOffset = fx.start[ss+1] == 'em' ? ( parseInt($(fx.elem).css('fontSize')) * 1.333 * parseInt(fx.start[ss]) ) : 1;
        for ( var ss = 1; ss < spos; ss+=2 ) { sarr.push( parseInt( emOffset * fx.start[ss] ) ); }
        for ( var es = 1; es < epos; es+=2 ) { earr.push( parseInt( emOffset * fx.end[es] ) ); }
        fx.elem.style.clip = 'rect(' +
            parseInt( ( fx.pos * ( earr[0] - sarr[0] ) ) + sarr[0] ) + 'px ' +
            parseInt( ( fx.pos * ( earr[1] - sarr[1] ) ) + sarr[1] ) + 'px ' +
            parseInt( ( fx.pos * ( earr[2] - sarr[2] ) ) + sarr[2] ) + 'px ' +
            parseInt( ( fx.pos * ( earr[3] - sarr[3] ) ) + sarr[3] ) + 'px)';
    }
})(jQuery);




$(document).ready(function() {

	/**
	 * This file should be a plugin along with other
	 * dropdown styles, that SSE can grab based on a pref
	 * or maybe certain templates work with certain menus?
	 * Or the template pre-parser looks for certain keywords
	 * to figure out which style of dropdown plugin to use?
	 * 
	 */
	
	//$('.nav ul').css({'height': '0px', opacity: '0.0', visibility: 'hidden'}); // old 
	//$('#logo').css({clip: 'rect(0px 100px 30px 0px)'}); // clip test
	
	// For IE 7
	$('.nav ul').css({visibility: 'visible'});
	
	$('.nav ul').css({'clip': 'rect(100px, 350px, 0px, 0px)',  opacity: '0.0'}); 
	//$('#menuBg').css({opacity: '0.0'});
	
	/**
	 * Put an arrow on all sub menus
	 */ 
	var subParent = $('.nav ul>li>ul');
	//subParent.parent().append(' <span style="font-weight: bold; color: yellow">&raquo;</span>');
	
	subParent.parent().children('a').each(function(){
	
		//var menuText = subParent.parent().children('a').html();
		var menuText = $(this).html();
		
		//subParent.parent().children('a').html( menuText + ' &raquo;');
		$(this).html(menuText + ' &raquo;');
		
	});
	
	
	/**
	 * Global vars for menu ani
	 */
	var aniDuration = 250; // orig was 500
	var hideDelay = 1200; //100;
	
	
	/*	
	if (!sse) var sse = {};
	if (!sse.menu) sse.menu = {
		primaryOpen: false,
		
		setTrue: function(){
			this.primaryOpen = true;
		},
		
		setFalse: function(){
			this.primaryOpen = false;
		},
		
		setClosing: function(el){
			doIt = function() {
				this.primaryOpen = false;
				$(el).css({visibility: 'hidden'});
			}
			setTimeout("doIt()", 550); // just enough time for the close animation to complete...hopefully
			
		}
	};
	*/
	
	
	/**
	 * First Level Enter - tab
	 * 
	 * NOTE:
	 * For callback to happen after animation, the callback
	 * must be wrapped in an anonymous function, as below.
	 * This feature/bug is used in the first level leave to
	 * set first level closing function immediately, so subs
	 * don't fly out while the menu is retracting.
	 * 
	 * Queue true is default
	 * 
	 * [a=v] checks for attr val
	 * [a] checks for attr
	 * .attr(a, v) sets attr val
	 * 
	 * second level has a margin left of 150,
	 * so that is added to the width to come up
	 * with the total clip val
	 * 
	 * The strange, doesn't always apply bug to this and the color
	 * animation library can apparently be killed with a 
	 * .stop(), .css(), .animate() ordering...for who knows why
	 * 
	 * 
	 * BUGS:
	 * Delay not working because we are not queing the animations (maybe they can go into their own queue, so we don't affect the global queue)
	 * 
	 */
	$('.nav>li').bind("mouseenter",
		function() {
			
			/*
			 * Timeout example 
			
			$("#text span").each(function(i, letter){
			setTimeout(function(){
				$(letter)
					.animate({ fontSize: "4em" }, 1000, "elasinout")
					.animate({ fontSize: "1em" }, 1000, "elasinout");
			}, i * 100);
			*/
			
			//$(this).stop(true); //, true);
			//$(this).stop(); //true, true);
			
			// this level is guaranteed to have children, so no need for a check
			var childUl = $(this).children('ul:eq(0)');
			/*
			*/
			var mapPadding = 0; //10;
			var childHeight = parseInt( childUl.height() ); // we'll go to 94 - this 
			var mapHeight = '';
			/**
			 * set max map height
			 * 
			 * 94 is the height of the yellow QAC header
			 */
			if (childHeight + mapPadding >= 94){
				mapHeight = 94 + 'px';
				//console.log('first level grow 1')
			}
			else{
				//mapHeight = 94 - childHeight + mapPadding + 'px';
				mapHeight = childHeight + mapPadding + 'px';
				//console.log('first level grow 2')
			}
			
			// Make the menu always go to the same height (some of the code above becomes obsolete
			mapHeight = '94px';
			
			var childLeft = childUl.offset().left;
			var menuBgLeft = childLeft - 75; // 75 is half of menuBg width (350) - ul width (200)
			childUl
				.stop() //true, true)
				.css({'clip': 'rect(100px, 350px, 0px, 0px)'}) // reset it prior to animation - clip/color plugin bug fix
				.animate({'clip': 'rect(0px, 350px, 150px, 0px)',  opacity: '1.0', top: '26px'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'} ); 
			$('#navMap')
				.animate({'top' : mapHeight}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'}); // was animating out to top 94px
			$('#menuBg')
				//.animate({'top' : mapHeight, 'left': menuBgLeft, opacity: '1.0'}, {queue: false, duration: 500, easing: 'easeOutCirc'});
				.animate({'top' : mapHeight, 'left': menuBgLeft }, {queue: false, duration: aniDuration, easing: 'easeOutCirc'});
	});
	
	
	/**
	 * First Level Leave
	 */
	$('.nav>li').bind("mouseleave",
		function(){
			//$(this).stop(true, true);
				//.stop(true, true)
			$(this).children('ul:eq(0)')
				.delay(3000)
				.animate({'clip': 'rect(100px, 350px, 0px, 0px)', 'top': '-60px', opacity: '0.0'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'} );  
	});
	

	
	
	/**
	 * Second Level Enter
	 * 
	 */
	$('.nav ul>li').bind("mouseenter",
		function() {
			//$(this).stop(true, true);
			
			var childUl = $(this).children('ul:eq(0)');
			// only if we found a child
			if (childUl.length){
				var childHeight = parseInt( childUl.height() ); // we'll go to 94 - this
				var childLeft = $(this).offset().left;
				var menuBgLeft = childLeft - 25; // move it over a bit to cover second level
				var mapTop = $('#navMap').position().top;
				var mapPadding = 10;
				var mapHeight = mapTop + 'px'; // default to existing position
				
				// if the sub menu is taller than the existing BG,
				if (childHeight > mapTop + mapPadding){
					//console.log('thinks to grows')
					if (childHeight + mapPadding >= 94){
						mapHeight = 94 + 'px';
					}
					else{
						mapHeight = 94 - childHeight + mapPadding + 'px';
					}
				}
				
				//// sub menu shorter & parent menu shorter, shrink -- FIXME not detecting if sub is shorter than parent correctly
				//else if ( (childHeight < mapTop + mapPadding ) && ( parseInt( $(this).parent().height() ) < mapTop ) ){
				//	console.log('thinks to shrinks')
				//	mapHeight = 94 - childHeight + mapPadding + 'px';
				//}
				
				
				
				$('#navMap')
					.animate({'top' : mapHeight}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'}); // was animating out to top 94px
				$('#menuBg')
					.animate({'top' : mapHeight, left: menuBgLeft}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'});
				childUl
					.stop(true, true)
					.animate({'clip': 'rect(0px, 350px, 150px, 0px)',  opacity: '1.0', left: '0px' },{queue: false, duration: aniDuration, easing: 'easeOutCirc'} );
			}
	});
	
	
	
	
	/**
	 * Second Level Leave
	 */
	$('.nav ul>li').bind("mouseleave",
		function(){
			//$(this).stop(true, true);
				//.stop(true, true)
			$(this).children('ul:eq(0)')
				.delay(hideDelay)
				.animate({'clip': 'rect(100px, 350px, 0px, 0px)', left: '-150px', opacity: '0.0'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'} );
			
			var childLeft = $(this).parent().offset().left;
			var menuBgLeft = childLeft - 75; // move it back
			$('#menuBg')
				.animate({left: menuBgLeft}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'});
	});

	
	
	
	/**
	 * Full Nav Close
	 */
	$('.nav').bind("mouseleave",
		function(){
			//console.log('left entire nav')
			//$(this).stop(true, true);
			$('#navMap')
				.delay(3000)
				.animate({'top': '-44px'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'});
			$('#menuBg')
				//.animate({'top' : '0px', opacity: '0.0'}, {queue: false, duration: 500, easing: 'easeOutCirc'});
				.delay(hideDelay)
				.animate({'top' : '-44px'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'}); 
			
		/**
		 *  Close the first level too (won't work here, needs to bind to each individual element
		$('.nav>li')
			.children('ul:eq(0)')
			.animate({'clip': 'rect(100px, 350px, 0px, 0px)', 'top': '-60px', opacity: '0.0'}, {queue: false, duration: aniDuration, easing: 'easeOutCirc'} );  
		 */
		
	});
	
	
	
	

	
	
	
	/**
	 * 
	 * 
	 * END OF MENU 
	 * 
	 * BEGINNING OF OTHER DOCUMENT.READY FUNCTIONS
	 * 
	 * 
	 * 
	 */
	
	
	
	
	
	
	
	
	/**
	 * Globally remove ugly focus border
	 */
	$('a').click(function() {
		
		this.blur();
			
	});
	

	

	/**
	 * Zebra stripe spec tables
	 */
	$(".specs_content tr:nth-child(odd)").addClass("specs_content_odd_row");




	/**
	 * Callout tooltip
	 * 
	 * On QAC, used in feature section callouts
	 */
	$('.sseTooltip').hover(
		
		function(){
			var currentPos = $(this).offset();
			var currentWidth = $(this).width();
			/** IE 7 'flicker' fix **/
			var containerTop = $('.features_container').offset().top;
			var containerLeft = $('.features_container').offset().left;
			var tipTop = currentPos.top - containerTop; // + 1;// + 28;
			var tipLeft = currentPos.left - containerLeft; // + currentWidth + 14;
			//var tipTop = 0;
			//var tipLeft = 0;
			/** end ie7 fix **/
			var tipText = $(this).attr('rel');
			
			// fade in the appropriate bg
			var tipTextLower = tipText.toLowerCase();
			//var overlayId = tipTextLower.replace(" ", "_", "g"); //doesn't work in ie/chrome
			var overlayId = tipTextLower.replace(/ /g, "_");
			
			// normal z-index is 7 for 3Q overlays (plane highlights in red)
			$('#' + overlayId)
				.css( { zIndex: '1', opacity: '0.0', visibility: 'visible' } )
				.animate( {opacity: '1.0' }, 400 );
			
			
			/** IE 7 'flicker' fix **/
			//var calloutClass = overlayId + "_callout";
			//$(document.body).append('<div class="callout" style="z-index: 300; left: ' + tipLeft + 'px; top: ' + tipTop + 'px;">' + tipText + '</div>');
			//$('.' + calloutClass).append('<div class="callout" style="left: ' + tipLeft + 'px; top: ' + tipTop + 'px;">' + tipText + '</div>');
			$('.features_container').append('<div class="callout" style="position: absolute; z-index: 5; left: ' + tipLeft + 'px; top: ' + tipTop + 'px;">' + tipText + '</div>');
			/** end ie7 fix **/
			
			$('.callout').css( { opacity: '0.0', 'clip': 'rect(0px, 0px, 50px, 0px)', visibility: 'visible' } );
			$('.callout').animate( {opacity: '.75', 'clip': 'rect(0px, 250px, 50px, 0px)' }, 400 );
		},
		
		function(){
			//$('.callout').animate( {opacity: '0.0', width: '0px'}, 500, function(){
			$('.callout').animate( {opacity: '0.0', 'clip': 'rect(0px, 0px, 50px, 0px)'}, 450, function(){
				//callback
				$(this).remove();

			} );
			
			
			// fade out the appropriate bg
			var tipText = $(this).attr('rel');
			var tipTextLower = tipText.toLowerCase();
			//var overlayId = tipTextLower.replace(" ", "_", "g"); //doesn't work in ie/chrome
			var overlayId = tipTextLower.replace(/ /g, "_");
			
			// normal z-index is 7 for 3Q overlays
			$('#' + overlayId)
				.animate( {opacity: '0.0' }, 450, function(){
					//callback
					$(this).css( { zIndex: '0'} );
				})
			
		}
	)
		


	
	/**
	 * SSE Vertical Drawer
	 * 
	 * TODO only works with one drawer on page (since drawerTopOld is a global)
	 * use data function to embed this instead. Also needs to have the animated
	 * (top and clip) values set here in the function...not good
	 * 
	 * Expects the button to be a direct decendent of the drawer
	 */
	var drawerTopOld; //dirty global FIXME
	
	$('.drawer_button').toggle(
		function(){
			
			var animateTopTo = 300;
			
			var currentButton = $(this);
			var currentDrawer = currentButton.parent();
			
			//var currentDrawerPos = currentDrawer.offset();
			//drawerTopOld = currentDrawerPos.top;
			drawerTopOld = currentDrawer.css("top");
			//alert(drawerTopOld);
				
			currentButton
				.removeClass("icon_arrow_up_lg")
				.addClass("icon_arrow_down_lg");
				
			currentDrawer
					//.css({ backgroundColor : '#fff' })
					.css({'clip': 'rect(0px, 460px, 21px, 0px)'}) // reset it prior to animation - clip/color plugin bug fix
					.animate( { top: animateTopTo + 'px', 'clip': 'rect(0px, 460px, 141px, 0px)' }, 500 );
			
		},
		
		function(){
			
			var currentButton = $(this);
			var currentDrawer = currentButton.parent();
			currentButton
				.removeClass("icon_arrow_down_lg")
				.addClass("icon_arrow_up_lg");
			
			currentDrawer
				.animate( { top: drawerTopOld, 'clip': 'rect(0px, 460px, 21px, 0px)' }, 500 );
			
		}
	)
	
	



	
	/**
	 * SSE SIMPLE VIDEO PLAYER
	 * 
	 * Replace a Link to a video file
	 * with a simple video player (play, pause, stop only)
	 * 
	 * 1. for simple video - remove file extension
	 * 2. get width and height
	 * 3. check for class - sseAutoPlay
	 * 
	 * UPDATE: To get this working in IE7, we had to append the flashvars to the end 
	 * of the container swf because IE7 was showing up with blank flashvars.
	 * 
	 */
	function sseSimpleVideo(el){
		// removed /beta
		var assetDir = '/assets/swf/';
		var vWidth = el.css('width');
		var vHeight = el.css('height');
		
		var videoFile = el.attr('href'); // we'll need to cut off the .flv from the filename here
		// If we don't check for null/undefined here, and no
		// video to play was found, it will come up undefined
		// and whine and stop working...blah blah blah
		if (videoFile != null){
			videoFile = videoFile.replace('.flv', '');
		}
		
		vWidth = parseInt(vWidth);
		vHeight = parseInt(vHeight);
		
		var videoPlayer = '<!-- Begin Flash Video for Progressive download -->' + 
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' +
		'width="' + vWidth + '" height="' + vHeight + '" id="FLVPlayer"><param name="movie" value="' + assetDir + 'FLVPlayer_Progressive.swf?&skinName=' + assetDir + 'videoSkin&streamName=' + videoFile + '&autoPlay=false" />' +
		'<param name="salign" value="lt" /><param name="quality" value="high" /><param name="scale" value="noscale" />' +
		'<param name="FlashVars" value="&skinName=' + assetDir + 'simpleVideoSkin&streamName=' + videoFile + '&autoPlay=true&autoRewind=false" />' +
		'<embed src="' + assetDir + 'FLVPlayer_Progressive.swf" flashvars="&skinName=' + 
		assetDir + 'simpleVideoSkin&streamName=' + videoFile + '&autoPlay=true&autoRewind=false" quality="high" ' +
		'scale="noscale" width="' + vWidth + '" height="' + vHeight + '" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" ' +
		'pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/></object><!-- End Flash Video for Progressive Download -->';
		
		el.replaceWith("<div>" + videoPlayer + "</div>");
		
	}
	
	// Run the auto video player
	sseSimpleVideo($('.sseSimpleVideo'));
	
	
	

	
	

	/**
	 * SSE NORMAL VIDEO PLAYER
	 * 
	 * Replace a Link to a video file
	 * with a normal video player 
	 * (play, pause, stop w/timeline, etc)
	 * 
	 * 1. for video - remove file extension
	 * 2. get width and height
	 * 3. check for class - sseAutoPlay
	 * 
	 * UPDATE: To get this working in IE7, we had to append the flashvars to the end 
	 * of the container swf because IE7 was showing up with blank flashvars.
	 * 
	 */
	function sseVideo(el){
		// removed /beta
		var assetDir = '/assets/swf/';
		var vWidth = el.css('width');
		var vHeight = el.css('height');
		var videoFile = el.attr('href'); // we'll need to cut off the .flv from the filename here
		
		if (videoFile != null){
			videoFile = videoFile.replace('.flv', '');
		}
		
		vWidth = parseInt(vWidth);
		vHeight = parseInt(vHeight);
		
		var videoPlayer = '<!-- Begin Flash Video for Progressive download -->' + 
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' +
		'width="' + vWidth + '" height="' + vHeight + '" id="videoPlayer"><param name="movie" value="' + assetDir + 'FLVPlayer_Progressive.swf?&skinName=' + assetDir + 'videoSkin&streamName=' + videoFile + '&autoPlay=false" />' +
		'<param name="salign" value="lt" /><param name="quality" value="high" /><param name="scale" value="noscale" />' +
		'<param name="FlashVars" value="&skinName=' + assetDir + 'videoSkin&streamName=' + videoFile + '&autoPlay=false&autoRewind=false" />' +
		'<embed src="' + assetDir + 'FLVPlayer_Progressive.swf" flashvars="&skinName=' + 
		assetDir + 'videoSkin&streamName=' + videoFile + '&autoPlay=false&autoRewind=false" quality="high" ' +
		'scale="noscale" width="' + vWidth + '" height="' + vHeight + '" name="videoPlayer" salign="LT" type="application/x-shockwave-flash" ' +
		'pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/></object><!-- End Flash Video for Progressive Download -->';
		
		//alert(videoPlayer);
		
		el.replaceWith("<div>" + videoPlayer + "</div>");
		
	}
	
	// Run the auto video player
	sseVideo($('.sseVideo'));	
	
	
	
	
	
	
	
	
	/**
	 * SSE SIMPLE AUDIO PLAYER
	 * 
	 * Replace a Link to an audio file
	 * with a simple audio player
	 * 
	 * 3. check for class - sseAutoPlay
	 * 
	 * If a subdirectory under the audio directory is needed,
	 * simply add it to the href in the link, and it will be appended.
	 * 
	 * 
	 * 
	 * UPDATE - BUG: May not work with more than one on page. May need to check and update playerID
	 * for more than one player.
	 * 
	 */
	function sseSimpleAudio(el){
		// removed /beta
		var assetDir = '/assets/plugins/';
		
		// let the audio file link come from the actual original link on the page
		var audioFile = el.attr('href'); // we'll need to cut off the .flv from the filename here
		//var audioFile = 'badfilehere'; // test behavior with a bad file
		//alert(audioFile);
		
		/**
		 * The js loader has to be last, because it's looking for object tags.
		 * 
		 * UPDATE: but we can't do an 'after' because the el doesn't exist anymore. :o\
		 * 
		 * UPDATE2: To get this working in IE7, we had to append the flashvars to the end 
		 * of the container swf because IE7 was showing up with blank flashvars.
		 */
		//' type="application/x-shockwave-flash" data="' + assetDir + 'audio_player/player.swf"' +
		var audioPlayer = '<!-- Begin Flash Audio --> ' + 
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"' +
		' id="audioplayer1" height="24" width="290">' +
		' <param name="movie" value="' + assetDir + 'audio_player/player.swf?&playerID=1&soundFile=' + audioFile + '"/>' +
		' <param name="quality" value="high"/>' +
		' <param name="menu" value="false"/>' +
		' <param name="wmode" value="transparent"/>' + 
		' <param name="FlashVars" value="&playerID=1&soundFile=' + audioFile + '"/>' +
		' <embed src="' + assetDir + 'audio_player/player.swf" flashvars="&playerID=1&soundFile=' + audioFile + '" quality="high" ' +
		' scale="noscale" width="290" height="24" name="player" salign="LT" type="application/x-shockwave-flash"' +
		' pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>' +
		'</object>' +
		' <!-- End Flash Audio -->';
		
		// all on one line to try to fix ie issue
		//var audioPlayer = '<!-- Begin Flash Audio --> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="audioplayer1" height="24" width="290"> <param name="movie" value="' + assetDir + 'audio_player/player.swf"/> <param name="FlashVars" value="playerID=1&soundFile=' + audioFile + '"/> <param name="quality" value="high"/> <param name="menu" value="false"/> <param name="wmode" value="transparent"/> <embed src="' + assetDir + 'audio_player/player.swf" flashvars="playerID=1&soundFile=' + audioFile + '" quality="high" scale="noscale" width="290" height="24" name="player" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/> </object> <!-- End Flash Audio -->';
		
		//alert(audioPlayer);
		
		el.replaceWith("<div>" + audioPlayer + "</div>");

		//var audioJS = '<script language="JavaScript" src="' + assetDir + 'audio_player/audio-player.js"></script>';
		
		//el.after(audioJS);		
		
		
	}
	
	// Run the auto audio player 
	/**
	 * DEPRECIATED 
	 * Wouldn't work with multiple audio files on page, 
	 * it would always apply the first audio file
	 */
	//sseSimpleAudio($('.sseSimpleAudio'));	
	
	
	
	
	
	/**
	 * SSE SIMPLE AUDIO PLAYER
	 * 
	 * Replace a Link to an audio file
	 * with a simple audio player simply
	 * by adding a class to the link
	 * 
	 * Updated simple audio player, works with multiple audio files on one page
	 * 
	 * 
	 * 
	 * Sample Usage:
	 * 
	 * <a class="sseSimpleAudio sseAutoPlay" style="width: 290px; height: 24px;" href="http://67.205.101.66/uploads/audio/100930-SteveO.mp3">
	 * Audio Player
	 * </a>
	 */
	$('.sseSimpleAudio').each(
			function(){
				// removed /beta
				var assetDir = '/assets/plugins/';
				
				var audioFile = $(this).attr('href'); 
				
				var audioPlayer = '<!-- Begin Flash Audio --> ' + 
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
				' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"' +
				' id="audioplayer1" height="24" width="290">' +
				' <param name="movie" value="' + assetDir + 'audio_player/player.swf?&playerID=1&soundFile=' + audioFile + '"/>' +
				' <param name="quality" value="high"/>' +
				' <param name="menu" value="false"/>' +
				' <param name="wmode" value="transparent"/>' + 
				' <param name="FlashVars" value="&playerID=1&soundFile=' + audioFile + '"/>' +
				' <embed src="' + assetDir + 'audio_player/player.swf" flashvars="&playerID=1&soundFile=' + audioFile + '" quality="high" ' +
				' scale="noscale" width="290" height="24" name="player" salign="LT" type="application/x-shockwave-flash"' +
				' pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"/>' +
				'</object>' +
				' <!-- End Flash Audio -->';
				
				$(this).replaceWith("<div>" + audioPlayer + "</div>");

	});
	
	
	
	
	
	
	/**
	 * Debugging & Status bar
	 */
	DEBUG = 0;

	if (DEBUG == 1){ 

		statusBar = '<span class="sseStatus" style="position: absolute; left: 0px; bottom: 0px; width: 250px; height: 300px; font-size: 8pt; padding: 4px; text-align: left; background-color: #fdfe77; padding: 4px; border: 1px solid #aa0000; visibility: hidden; overflow: scroll; color: #000;">' +
			'<span style="display: block; font-size: 9pt; font-weight: bold; color: #ffffff; margin: 0;  padding: 4px; background-color: red;">S T R A T A ./\\. STATUS: </span></span>';
		$('body').append(statusBar);
		$(".sseStatus").css({
			"visibility" : "visible", 
			"opacity" : ".7", 
			"cursor" : "move"
			}); 
		
		sseStatus = $('.sseStatus');
		sseStatus.draggable();
		
		sseStatus.update = function(sName, sVar){
			sseStatus.append ('<br><strong>' + sName + '</strong> = ' + sVar);
		}
	}	
	
	
	
	
	
	
}); // end document ready








/**
 * SSE Magic Form functions
 * 
 * These can not live inside any document ready
 * or window onload type function
 */
var oldFormTextColor; //dirty global

function focused(inObj, myText) {

		//var curInput = document.getElementById(inObj);
		var curInput = inObj;		
		
		oldFormTextColor = curInput.style.color;
		
		curInput.style.color = '#000';
		
		curInput.style.backgroundColor = '#fff';
		
		
		//var inputText = document.getElementById(inObj).value;
		var inputText =  curInput.value;
		
		if (inputText == myText)	{

			//document.getElementById(inObj).value = myText;
			//document.getElementById(inObj).value = '';
			curInput.value = '';
			
		}
			
		else {
			
			//curInput.style.color = '#96946B';
			
		}

}

function blurred(inObj, myText) {
			
		//var curInput = document.getElementById(inObj);
		var curInput = inObj;
				
		curInput.style.backgroundColor = '#ccc';
		
		//var inputText = document.getElementById(inObj).value;
		var inputText =  curInput.value;
		
		if (inputText == '')	{
			
			//document.getElementById(inObj).value = myText;
			curInput.value = myText;
			
			curInput.style.color = oldFormTextColor;

		}
			
		else {
			
			//document.getElementById(inObj).value = myText;
			//curInput.style.color = '#000000';
			
		
		}
	
}


