function navigate_page_no_history( windowObject, newLocation )
{
	windowObject.location.replace( "about:blank" );
	windowObject.location.replace( newLocation );
}
/*
function mainSearchFocus( searchstring ) {
	var s = document.getElementById("s");
	if (s.value == searchstring) {
		s.value = "";
	}
	document.getElementById("searchbuttons").style.display = "block";
}

function mainSearchBlur( searchstring ) {
	var s = document.getElementById("s");
	if (s.value == "") {
		s.value = searchstring;
		document.getElementById("searchbuttons").style.display = "none";
	}
}

function shackmast_searchSubmit( searchstring )
{
	var s = document.getElementById("s");
	if (s.value == searchstring || s.value == "" ) 
	{
		return false;
	}
	else
	{
		return true;
	}
}


function shackmast_searchSubmitEmpty( searchstring )
{
	var s = document.getElementById("s");
	if (s.value == searchstring ) 
	{
		s.value = "";
	}

	return true;
}


function shackmast_searchForType( searchType )
{
	var st = document.getElementById( "search_type" );
	st.value = searchType;
	var tf = document.getElementById( "searchboxes" );
	
	tf.submit();
	return false;
}
*/

function getDefaultSearchText(searchType)
{
	var st = document.getElementById('search' + searchType);
	if (st == null)
	{
		return 'Search the Shack...';
	}
	else
	{
		return st.getAttribute('title');
	}	
}

function searchTypeMouseOverHandler(tgt)
{
	var searchType = tgt.id.substr(6);
	
	if (isSearchTextADefault())
	{
		document.getElementById('s').value = getDefaultSearchText(searchType);
	}
}

function validateSearchValue()
{
	if ((isSearchTextDefault()) || (document.getElementById("s").value.length == 0))
	{
		alert('You didn\'t enter any search terms!');
		return false;
	}
	
	return true;	
}

function isSearchTextDefault()
{
	var s = document.getElementById("s").value; 
	
	if (s == 'Search the Shack...')
	{
		return true;
	}
	else if (s == getDefaultSearchText(document.getElementById('search_type').value))
	{
		return true; 
	}

	return false;
}

function isSearchTextADefault()
{
	var s = document.getElementById('s').value; 
	
	if (s == '')
	{
		return true;
	}
	else if (s == getDefaultSearchText(''))
	{
		return true;
	}

	var list = document.getElementById('searchbuttons').getElementsByTagName('a');
	for (var i = 0; i < list.length; i++)
	{
		if (s == getDefaultSearchText(list[i].id.substr(6)))
		{
			return true;
		}
	}
	
	return false;	
}

function mainSearchFocus() 
{
	document.getElementById("searchbuttons").style.display = "block";
}

function mainSearchClick()
{
	if (isSearchTextADefault())
	{
		document.getElementById('s').value = '';
	}
}

function shackmast_setSearchType(tgt)
{
	var searchType = tgt.id.substr(6);

	var s = document.getElementById('s'); 
	var st = document.getElementById('search_type'); 

	var oldSearchType = st.value;
	
	if (oldSearchType == searchType)
	{
		return false;
	}

	if (isSearchTextDefault())
	{
		s.value = '';
	}
	
	st.value = searchType; 
	
	if (s.value.length == 0)
	{
		s.value = getDefaultSearchText(searchType);
	}
	
	remove_class_from_element(document.getElementById('search' + oldSearchType), 'active');
	add_class_to_element(document.getElementById('search' + searchType), 'active');
	
	if (isSearchTextDefault() == false)
	{
		var tf = document.getElementById( "searchboxes" );
		tf.submit();
	}
	else
	{
		s.value = ''; 
		s.focus();
	}
	return false;
}

function shackmast_searchSubmit( searchstring )
{
	var s = document.getElementById("s");
	if (s.value == searchstring || s.value == "" ) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function shackmast_searchSubmitEmpty( searchstring )
{
	var s = document.getElementById("s");
	if (s.value == searchstring ) 
	{
		s.value = "";
	}
	return true;
}

function shackmast_searchForType( searchType )
{
	var st = document.getElementById( "search_type" );
	st.value = searchType;
	var tf = document.getElementById( "searchboxes" );
	
	tf.submit();
	return false;
}

function inline_viewmore_clicked()
{
	add_class_to_element( document.getElementById( "viewmore_link" ), "hidden" );
	remove_class_from_element( document.getElementById( "viewmore_content" ), "hidden" );
	
	return false;
}

function loginToggle() {
	var lc = document.getElementById("logincontrols");
	if (lc.style.display == '' || lc.style.display == 'none') {
		document.getElementById("logincontrols").style.display = "block";
		document.getElementById( "lusername" ).focus();
	} else {
		document.getElementById("logincontrols").style.display = "none";
	}
	return false;
}

function remove_from_array( theArray, theIndex )
{
	if ( theIndex != -1 )
	{
		var _in = 0; 
		var _out = 0;
		var _ret = new Array();
		
		for ( _in = 0; _in < theArray.length; ++_in )
		{
			if ( _in != theIndex )
			{
				_ret[_out] = theArray[_in];
				++_out;
			}
		}
		
		return _ret;
	}
	else
	{
		return theArray;
	}
}

function index_in_array(theArray, theValue)
{
	var arLength = theArray.length;
	for(var i=0; i < arLength; ++i )
	{
		if (theArray[i] == theValue)
		{
			return i;
		}
	}

	return -1;
}

function remove_value_from_array( theArray, theValue )
{
	var index = index_in_array( theArray, theValue );
	return remove_from_array( theArray, index );
}

function remove_from_className( theClassName, theValue )
{
	var classes = remove_value_from_array( theClassName.split( " " ), theValue );
	return classes.join( " " );
}

function add_to_className( theClassName, theValue )
{
	var classes = theClassName.split( " " );
	if ( index_in_array( classes, theValue ) == -1 )
	{
		classes[ classes.length ] = theValue;
	}
	
	return classes.join( " " );
}

function remove_class_from_element( element, theClass )
{
	element.className = remove_from_className( element.className, theClass );
}

function add_class_to_element( element, theClass )
{
	element.className = add_to_className( element.className, theClass );
}

function does_element_have_class( element, theClass )
{
	if ( index_in_array( element.className.split( " " ), theClass ) > (-1) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function find_element( parentRoot, element_type, element_class )
{
	var elements = parentRoot.getElementsByTagName( element_type );
	
  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( index_in_array( elements[i].className.split( " " ), element_class ) > -1 )
    {
//    	 alert( "Found element: " + elements[i].className );
       return elements[i];
    }
  }
   
  return false;
}

function append_element_after_element( to_append, where )
{
	var sib = where.nextSibling;
		
	if ( sib )
	{
		sib.parentNode.insertBefore( to_append, sib );
	}
	else
	{
		where.parentNode.appendChild( to_append );
	}
}

function find_elements_by_class( parentRoot, element_type, element_class )
{
	var elements = parentRoot.getElementsByTagName( element_type );
	var dst = new Array();
	
  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( index_in_array( elements[i].className.split( " " ), element_class ) > -1 )
    {
//    	 alert( "Found element: " + elements[i].className );
			dst.push( elements[i] );
    }
  }
   
  return dst;
}

function find_element_by_name( parentRoot, element_type, element_name )
{
	var elements = parentRoot.getElementsByTagName( element_type );

  for ( var i = 0; i < elements.length; ++i )
  {
  	if ( elements[i].name == element_name )
  	{
  		return elements[i];
  	}
	}	
	
	return false;
}

function push_front_element( parent_element, child_element )
{
   var elements = parent_element.childNodes;
   
   if ( elements.length > 0 )
   {
      return parent_element.insertBefore( child_element, elements[0] );
   }
   else
   {
      return parent_element.appendChild( child_element );
   }
}

function import_node( destination_document, node_to_import )
{
	if ( destination_document.importNode )
	{
		return destination_document.importNode( node_to_import, true );
	}
	else
	{
		// IE Path, since IE doesn't support importNode
		
		var tmpNode = destination_document.createElement("div");
		tmpNode.innerHTML = node_to_import.outerHTML;
		return tmpNode.firstChild.cloneNode(true);
	}
}

function replace_whole_element_from_iframe( element_name )
{
	var cloned = import_node( parent.document, document.getElementById( element_name ) );
	var found = parent.document.getElementById( element_name );
	
	found.parentNode.replaceChild( cloned, found );
}

function is_element_child_of( child_element, parent_element )
{
	var checking = child_element.parentNode;
	
	while ( checking )
	{
		if ( checking == parent_element )
		{
			return true;
		}
		
		checking = checking.parentNode;
	}
	
	return false;
}

function jump_to_anchor( anchor_name )
{
	window.location.hash = anchor_name;
}

function jump_to_anchor_from_iframe( anchor_name )
{
	parent.window.location.hash = anchor_name;
}

function spawn_audio_player ( audio )
{
	window.open ( "http://www.shacknews.com/extras/audio-player/player_popup.x?url=" + audio, "AudioPlayer", "resizable=no,status=no,width=310,height=25" );
}

function Bookmark(title,url)
{
  if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
  } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
  } else if (window.opera && window.print) { // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
  }
}

function popUp(theURL) { //v3.0

day = new Date();
winName = day.getTime();
isCenter = true;
myWidth = 914;
myHeight = 560;
features = '';

  if(window.screen)if(isCenter)if(isCenter=="true"){

    var myLeft = (screen.width-myWidth)/2;

    var myTop = (screen.height-myHeight)/2;

    features+=(features!='')?',':'';

    features+=',left='+myLeft+',top='+myTop;

  }

  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);

}

function popUpEmail(theURL) { //v3.0

day = new Date();
winName = day.getTime();
isCenter = true;
myWidth = 481;
myHeight = 283;
features = '';

  if(window.screen)if(isCenter)if(isCenter=="true"){

    var myLeft = (screen.width-myWidth)/2;

    var myTop = (screen.height-myHeight)/2;

    features+=(features!='')?',':'';

    features+=',left='+myLeft+',top='+myTop;

  }

  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);

}


/* 	Top Stories Rotator - ThomW */
(function() {

	// set up commonly used functions	
	var addEvent = function(obj, eventName, observer) { window.addEventListener ? obj.addEventListener(eventName, observer, false) : obj.attachEvent('on' + eventName, observer); }
	var $ = function(id) { return document.getElementById(id); }

	// 
	addEvent(window, 'load', so_init); 
	
	var imgs = new Array(), current = 0, timer = null;
	
	function so_init()
	{
		var f1 = $('f1');
		
		if (!f1) { return; }
		
		imgs = find_elements_by_class(f1, 'div', 'cel'); 
		for(i=1; i<imgs.length; i++) 
		{
			imgs[i].xOpacity = 0;
		}
		imgs[0].style.display = "block";
		imgs[0].xOpacity = .999999;
				
		timer = setTimeout(so_xfade,4000);

		// set up event handlers to handle pause and unpause when the mouse is moved over the image
		addEvent(f1, 'mouseover', so_pause); 
		addEvent(f1, 'mouseout', function () { if (timer) { return; } timer = setTimeout(so_xfade, 1000); }); 
		
		// set up next/prev buttons
		addEvent($('f1-next'), 'click', so_showNext);
		addEvent($('f1-prev'), 'click', so_showPrev);
	}

	function so_pause()
	{
		// stop the timer
		clearTimeout(timer); 
		timer = 0;
		
		// make the more opaque image the only image shown

		next = imgs[current + 1] ? current + 1 : 0; 
		
		// if the current image is more opaque, stay on the current image
		if (imgs[current].xOpacity > imgs[next].xOpacity)
		{
			imgs[next].xOpacity = 0;
			imgs[next].style.display = 'none';
			
			imgs[current].xOpacity = 0.999999; 

			setOpacity(imgs[current]);
			setOpacity(imgs[next]);
		}
		else
		{
			imgs[current].xOpacity = 0;
			setOpacity(imgs[current]);
			imgs[current].style.display = 'none';
			
			current = next;
			
			imgs[current].xOpacity = 0.999999; 
			setOpacity(imgs[current]);
		}
	}
	function highlightNextButton()
	{
		$('f1-next').style.backgroundPosition = '100% 100%';
		setTimeout(fixPagingBackgrounds, 500); 
	}
	function highlightPrevButton()
	{
		$('f1-prev').style.backgroundPosition = '0 100%';
		setTimeout(fixPagingBackgrounds, 500); 
	}	
	function fixPagingBackgrounds()
	{
		$('f1-prev').style.backgroundPosition = '0 0';
		$('f1-next').style.backgroundPosition = '100% 0';
	}
	function so_showNext()
	{
		highlightNextButton();
		
		next = imgs[current + 1] ? current + 1 : 0;
		so_show(next); 
	}
	function so_showPrev()
	{
		highlightPrevButton();
		
		next = imgs[current - 1] ? current - 1 : imgs.length - 1;
		so_show(next); 
	}
	function so_show(idx)
	{
		imgs[current].xOpacity = 0;
		setOpacity(imgs[current]);
		imgs[current].style.display = 'none';
		
		current = idx;
		
		imgs[current].style.display = 'block';
		imgs[current].xOpacity = 0.999999;
		setOpacity(imgs[current]);
	}
	function so_xfade(disable) 
	{
		cOpacity = imgs[current].xOpacity;
		nIndex = imgs[current+1]?current+1:0;
	
		nOpacity = imgs[nIndex].xOpacity;
		
		cOpacity-=.05; 
		nOpacity+=.05;

		// this is the start of a new fade in cycle		
		if (imgs[nIndex].style.display == 'none')
		{
			highlightNextButton();
			imgs[nIndex].style.display = "block";
		}
		
		imgs[current].xOpacity = cOpacity;
		imgs[nIndex].xOpacity = nOpacity;
		
		setOpacity(imgs[current]); 
		setOpacity(imgs[nIndex]);
		
		if (cOpacity <= 0) 
		{
			imgs[current].style.display = "none";
			current = nIndex;
			timer = setTimeout(so_xfade,4000);
		} 
		else 
		{
			timer = setTimeout(so_xfade,50);
		}
	}
	function setOpacity(obj) 
	{
		if(obj.xOpacity > 0.999999) 
		{
			obj.xOpacity = 0.999999;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity * 100) + ")";
	}
	
})();