var objGradientMenu = null;
var objHidables = null;

window.addEvent('domready', function() {
	
	initGradientMenu();
	initAutoHidables();
	initInjectionkitHover();
	if(window.location.href.indexOf('printfriendly=1') > 0)
	{
		$('PageFooter').style.width = '563px';
		window.print();
		
	}
});

function initGradientMenu()
{
	objGradientMenu = new GradientMenu({element:$("MainMenu"),color:"#041067",gradientPercent:30});
}

function initAutoHidables()
{
	objHidables = new AutoHidables();
}

function sendToFriend()
{
	mystring = window.location.href;
	mystring = mystring.replace(/&/ig,'&amp;'); 
	sendWin = window.open('/index.asp?did=34102&ArticleLink='+escape(mystring),'sendWin','width=400,height=500,resizable=yes,scrollbars=yes')
}


function toggleImage(strId)
{
	var elmHidable = $(strId);
	elmHidable.set('morph', {duration: 500, transition: 'quad:out'});
	
	switch(elmHidable.hasClass('visible')) {
	
	default:
	case false:
		elmHidable.setOpacity(0);
		var elmImg = elmHidable.getElements('img')[0];
		var objImage = new Image();
		
		objImage.src = elmImg.src;
		
		elmHidable.morph({'height':objImage.height,'opacity':1});
		elmHidable.addClass('visible');
		break;
		
	case true:
		elmHidable.morph({'height':0,'opacity':0});
		elmHidable.removeClass('visible');
		break;
		
	}
}


function toggleHidable(caller,strId)
{
	objHidables.toggle(caller,strId);
}


function irItemSelected(elmSelect)
{
	if(elmSelect.value != "")
		$(elmSelect).getParent().getParent().addClass("selected");
	else
		$(elmSelect).getParent().getParent().removeClass("selected");
}


function initInjectionkitHover()
{
	if($('InjectionKit')) {
		$('InjectionKit').addEvent('mouseenter', function(){
			if(!$('InjectionKitText')) {
				$('InjectionKit').adopt(new Element('div',{'id':'InjectionKitText'}).setText('To ensure appropriate and most effective use of emla cream, a pre-injection numbing kit has been put together which includes all the items a patient needs to use emla correctly – 2x occlusive dressings, a sterile wipe and a patient leaflet.'));
				$('InjectionKitText').setOpacity(0.9);
			} else {
				$('InjectionKit').adopt($('InjectionKitText'));
				$('InjectionKitText').setOpacity(0.9);
			}
			
		});
		$('InjectionKit').addEvent('mouseleave', function(){
			$('InjectionKitText').remove();
		});
	}
}

function printerFriendly()
{
	strUrl = window.location.href
	if(strUrl.indexOf('?') > 0)
	{
		strUrl += '&printfriendly=1'
	}
	else
	{
		strUrl += '?printfriendly=1'
	}
	printWin = window.open(strUrl,'printWin')

}