/**
 * @author sbradshaw
*/

if(!ALIGN) {var ALIGN={};}

ALIGN.getSearchAsArray = function() {
	var results = [];
	var input = unescape(location.search.substr(1));
	if (input) {
		var srchArray = input.split('&');
		var tempArray = [];
		for (var i = 0; i < srchArray.length; i++) {
			tempArray = srchArray[i].split("=");
			results[tempArray[0]] = tempArray[1];
		}
	}
	return results;
};


$(document).ready(function () {
	ALIGN.qs = ALIGN.getSearchAsArray();
	
	$('.backtotop').click(function(ev){
		window.scrollTo(0,0);
	});
	$('#tooltip').fadeTo(0, .0);
	$('[tooltip]').mouseover(function(ev){
		if($('#tooltip').css('opacity') > 0) {
			$('#tooltip').stop();
		}
		$('#tooltip').html(  $(this).attr('tooltip')  );
		$('#tooltip').css({'top':(ev.pageY) - $('#tooltip').height() - 35, 'left':(ev.pageX) - 110 });
		$('#tooltip').fadeTo(250, .85);
		$(this).mousemove(function(ev) {
			$('#tooltip').css({'top':(ev.pageY) - $('#tooltip').height() - 35, 'left':(ev.pageX) - 110 });
		});
	}); 
	$('[tooltip]').mouseout(function() {
		if($('#tooltip').css('opacity') < .85) {
			$('#tooltip').stop();
		}
		$('#tooltip').fadeTo(250, .0, function() {
			$('#tooltip').css({'top':-300, 'left':0 });
		});
	});
	
	/* DISPLAY SITE HEADER IMAGE */
	var currentLocation = location.pathname.split('/')[1];
	if( currentLocation.indexOf('Products') > -1 ||
	currentLocation.indexOf('RealStories') > -1 ||
	currentLocation.indexOf('Training') > -1 ||
	currentLocation.indexOf('GetHelp') > -1 ||
	currentLocation.indexOf('ClinicalEvidence') > -1 ||
	currentLocation.indexOf('Blog') > -1 ||
	currentLocation.indexOf('PracticeDev') > -1 ) {
		$('#SiteWideHeader > img').attr('src', '/SiteCollectionImages/HDR_' + currentLocation + '.png');
		$('.links-menu[href=/' + currentLocation + ']').css('color', '#265594');
	} else if (currentLocation.indexOf('Pages') > -1) {
		$('#SiteWideHeader > img').attr('src', '/SiteCollectionImages/HDR_Welcome.png');
		$('.links-menu[href=/]').css('color', '#265594');
	} else if(currentLocation.indexOf('Assets') > -1 && location.pathname.indexOf('/Assets/Pages/science.aspx') > -1) {
		$('#SiteWideHeader > img').attr('src', '/SiteCollectionImages/HDR_RealStories.png');
		$('.links-menu[href=/RealStories]').css('color', '#265594');
	}

	
});


