function ChangeImageSrc(id, src)
{
    document.getElementById(id).src = src;
}

function HomeIconOver(name)
{
    id = name + 'HomeIconShadow';
    PulseIcon(id);
}


function HomeIconOut(name)
{
    PulseIconStop();
}


function HomeIconDown(name)
{
    id = name + 'HomeIcon';
    ChangeImageSrc(id, '/images/masthead/home_' + name + '_icon_depressed.png');
}


function HomeIconUp(name)
{
    id = name + 'HomeIcon';
    ChangeImageSrc(id, '/images/masthead/home_' + name + '_icon.png');
    PulseIconStop();
}








var _PulseInfo = {ticks:0, startFrom:0, endAt:0.0, duration:0, element:null, timer:null};

function PulseIcon(id)
{
    elem = document.getElementById(id);
    
	_PulseInfo.element   = elem;
	_PulseInfo.startFrom = 0.0;
	_PulseInfo.endAt     = 0.8;
	_PulseInfo.ticks     = 0;
	_PulseInfo.duration  = 35;
	_PulseInfo.timer     = setInterval("_PulseElementAnimation();", 15);
}


function PulseIconStop()
{
    if (_PulseInfo.element) {
        _PulseInfo.element.style.opacity = 0.0;
        clearInterval(_PulseInfo.timer);
	   _PulseInfo.timer = null;
	}
}


function _PulseElementAnimation()
{
    progress = EaseInOut( _PulseInfo.ticks / _PulseInfo.duration );
    _PulseInfo.element.style.opacity = _PulseInfo.startFrom + progress * (_PulseInfo.endAt - _PulseInfo.startFrom);
    _PulseInfo.ticks++;
}


function EaseInOut(x)
{
	return Math.sin( x * Math.PI - (Math.PI / 2.0) ) / 2.0 + 0.5;
}

















function switchToPanel(panelSetName, panelName, animate)
{
	$("div[name='" + panelSetName + "'] [name|='btn']").addClass('off').removeClass('on');
	$("div[name='" + panelSetName + "'] [name='btn-" + panelName + "']").toggleClass('off on');
	switchToTab(panelSetName, panelName, animate);
}



function switchToTab(tabSetName, tabName, animate)
{
	if (animate == true) {
		
		// Get the container
		var container = $("div[name='" + tabSetName + "']");
		
		
		// Get the current tab...
		var allTabs = $("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']");
		var currentTab = null;
		allTabs.each(function(index){
			if (this.style.display == "block") {
				currentTab = $(this);
			}
		});
		
		
		// Get the new tabs
		var newTab = $("div[name='" + tabSetName + "'] div[name='" + tabSetName +"-" + tabName + "']");
		
		
		if (newTab[0] == currentTab[0]) {
			return;
		}
		
		
		var difference = newTab.height() - currentTab.height();
		
		
		// Set height of containing div to the larger height explicitly
		//container.animate({'height' : (height + 'px')}, 300); // This causes some kind of visual glitch :()
		if (difference > 0) {
			container.css({'height' : (container.height() + difference + 'px')});
		} else {
			container.css({'height' : (container.height() + 'px')});
		}
		
		// Then make all subdivs absolute
		$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").css({'position':'absolute'});
	
	
		// Then do the fades
		$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").fadeOut(300);
	
		// Show the right tab
		newTab.fadeIn(300, function(){
		
			// Then make em relative again
			$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").css({'position':'relative'});
			
			$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").css({'display':'none'});
			$("div[name='" + tabSetName + "'] div[name='" + tabSetName +"-" + tabName + "']").css({'display':'block'});
			
			
			// Then make the containing div have fitting height
			$("div[name='" + tabSetName + "']").css({'height':''});
		});
	
	} else {
		$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").css({'display':'none'});
		$("div[name='" + tabSetName + "'] div[name='" + tabSetName +"-" + tabName + "']").css({'display':'block'});
	}
	
}




// 
// function switchToTab(tabSetName, tabName, scroll)
// {
// 	// Hide all tabs
// 	$("div[name='" + tabSetName + "'] div[name|='" + tabSetName +"']").fadeOut(); //css({'display':'none'});
// 	
// 	// Show the right tab
// 	var tab = $("div[name='" + tabSetName + "'] div[name='" + tabSetName +"-" + tabName + "']");
// 	if (tab != null) {
// 		tab.fadeIn(); //css({'display':'block'});
// 		
// 		if (tab.offset() && scroll == true) {
// 			$('html,body').animate({ scrollTop: tab.offset().top }, { duration: 'slow', easing: 'swing'});
// 		}
// 	}
// }
// 

