// JavaScript Document for Calpol MooTools Elements


/****************************************************
* Global Vars										*
*													*
*****************************************************/

var arrow_y = "0px";
var animating = false;





/****************************************************
* Initialise Calpol Navigation						*
*													*
*****************************************************/

function initNavigation(){
	var primary_navs = $$('#navigation ul.primary-nav');
	var primary_navs_as, filename;
	
	var req = new Request({
		method: 'get',
		onRequest: function(){},
		onSuccess: function(responseText, responseXML){ createSlideOuts(responseXML); },
		onComplete: function(){},
		onFailure: function(xhr){}
	});
	
	if(document.getElementById("torso")){
		$("torso").setAttribute("orig-height", $("torso").offsetHeight);
	}
	
	if(primary_navs.length > 0){
		$each(primary_navs, function(pn, i){
			if(i===0){
				primary_navs_as = pn.getElementsByTagName("a");
				if(primary_navs_as.length > 0){
					$each(primary_navs_as, function(pna, j){
						if(pna.className.indexOf("no-sub") < 0){
							pna.id = "pna-" + j;
							pna.hideFocus = true;
							$("pna-" + j).addEvent('click', function(e){								
								if(this.parentNode.className.indexOf("nav-on") < 0){
									updateNavClasses(e);
									filename = root_dir + 'xml/primary-navigation/' + pna.innerHTML.substring(0,pna.innerHTML.length - 2).replace(/ /g, "_").toLowerCase() + '.xml';								
									req.send({url: filename});
								}
																
								e = new Event(e);
								e.stop(); 
								
							});
							pna.id = "";
						}
				   });
				}
			}
		});		
	}
	
	
	
	var hpImgArr = ['images/generic/arrow.png', 'images/generic/down_gradient2.gif', 'images/generic/text_selectarticle.gif', 'images/generic/gradientline_left.gif', 'images/generic/abstract_cover.gif', 'images/generic/gradientline_left.gif', 'images/homepage/shutter1.png', 'images/homepage/shutter2.png', 'images/homepage/shutter1.gif', 'images/homepage/shutter2.gif', 'images/generic/gradientline_left.gif', 'images/generic/nav_gradientbg.gif', 'images/generic/titles_arrow.gif', 'images/subpages/nav_lefttop.png', 'images/subpages/nav_righttop.png', 'images/subpages/nav_leftbottom.png', 'images/subpages/nav_rightbottom.png', 'images/generic/down_gradient3.gif', 'images/generic/text_abstract.gif', 'images/generic/backbutton.gif', 'images/generic/gradient_across3.gif', 'images/generic/backbutton2.png', 'images/homepage/shutter1a.png', 'images/homepage/shutter2a.png', 'images/homepage/shutter1a.gif', 'images/homepage/shutter2a.gif', 'images/generic/btn_purple.gif', 'images/subpages/firstbabymoments/arrow_up2.gif', 'images/subpages/firstbabymoments/arrow_down2.gif'];
	
	for(var i=0; i<hpImgArr.length; i++){
		hpImgArr[i] = root_dir + hpImgArr[i];
	}
	
	var hpImages = new Asset.images(hpImgArr, {
		onProgress: function(counter, index){
		},
		onComplete: function(){
		}
	});
}




/****************************************************
* Populate Primary Navigation Pop Outs From XML		*
*													*
*****************************************************/

function populateArticles(xml){
	var titles = [];
	for(var i=0; i<xml.getElementsByTagName("title").length; i++){
		titles[i] = [];
		titles[i][0] = xml.getElementsByTagName("title")[i].childNodes[0].nodeValue;
		titles[i][1] = xml.getElementsByTagName("link")[i].childNodes[0].nodeValue;
	}
	
	return titles;
}


function populateAbstract(xml,num,titles){	
	var innerHTML = "<h5><a href='" + root_dir + titles[num][1] + "'>" + xml.getElementsByTagName("title")[num].childNodes[0].nodeValue + "</a></h5>";
	for(var i=0; i<xml.getElementsByTagName("abstract")[num].getElementsByTagName("text")[0].childNodes.length; i++){
		innerHTML += "<" + xml.getElementsByTagName("abstract")[num].getElementsByTagName("text")[0].childNodes[i].nodeName + ">" + getHTMLfromXML(xml.getElementsByTagName("abstract")[num].getElementsByTagName("text")[0].childNodes[i]) + "</" + xml.getElementsByTagName("abstract")[num].getElementsByTagName("text")[0].childNodes[i].nodeName + ">";
	}
	
	innerHTML += '<a href="' + xml.getElementsByTagName("link")[num].childNodes[0].nodeValue + '" class="read-article">read article</a>';
	
	return innerHTML;
}






/****************************************************
* Update Classes on Primary Nav and PopOuts			*
*													*
*****************************************************/

function updateNavClasses(e){
	if (!e){ e = window.event; }
	var tgt = e.target || e.srcElement;	
	var clicked_ul, clicked_lis;
	
	if(tgt.parentNode.nodeName.toLowerCase() == "li" && tgt.parentNode.parentNode.className == "primary-nav" && !animating){
		
		tgt.parentNode.id = "li_position";
		arrow_y = $("li_position").getPosition($('torso')).y + "px";
		tgt.parentNode.id = "";
		
		clicked_ul = tgt.parentNode.parentNode;
		clicked_ul.id = "clicked_ul";
		clicked_lis = $("clicked_ul").getChildren();
		for(var i=0; i<clicked_lis.length; i++){
			clicked_lis[i].style.marginTop = "0px";
			clicked_lis[i].style.paddingTop = "0px";
			if(clicked_lis[i].className.indexOf("nav-on") > -1){
				clicked_lis[i].className = clicked_lis[i].className.replace(/nav-on/i, "");
			} else {
				clicked_lis[i].className = "";
			}
		}
		clicked_ul.id = "";
		
		if(tgt.parentNode.className.length > 0){
			tgt.parentNode.className += " nav-on"; 
		} else {
			tgt.parentNode.className = "nav-on";
		}
		
		if(clicked_lis.length > 0){
			if(tgt.parentNode != clicked_lis[0]){
				tgt.parentNode.id = "temp-title";
				if(browser.isIE6 || browser.isIE5){
					$("temp-title").setStyles({
						'margin-top': '-2px',
						'padding-top': '1px'
					});
				} else {
					$("temp-title").setStyles({
						'margin-top': '-1px',
						'padding-top': '1px'
					});
				}

				tgt.parentNode.id = "";
			}
		}
	
	} else if(tgt.parentNode.parentNode.nodeName.toLowerCase() == "li" && !animating){
		tgt.parentNode.parentNode.id = "li_position";
		arrow_y = $("li_position").getPosition($('torso')).y + "px";
		tgt.parentNode.parentNode.id = "";
		clicked_ul = tgt.parentNode.parentNode.parentNode;
		clicked_lis = $$("#navigation-titles li");
		for(var i=0; i<clicked_lis.length; i++){
			if(clicked_lis[i].className.indexOf("nav-on") > -1){
				clicked_lis[i].className = clicked_lis[i].className.replace(/nav-on/i, "");
			} else {
				clicked_lis[i].className = "";
			}
		}
		
		if(tgt.parentNode.parentNode.className.length > 0){
			tgt.parentNode.parentNode.className += " nav-on"; 
		} else {
			tgt.parentNode.parentNode.className = "nav-on";
		}
	}
}







/****************************************************
* Create Slideout Menus								*
*													*
*****************************************************/

function createSlideOuts(xml){
	var titles = populateArticles(xml);	
	if(titles.length > 0 && !animating && !document.getElementById("navigation-titles")){
	
		animating = true;
		var nav_cover = new Element('div', {'id': 'navigation-cover', 'styles': {'height': $("torso").offsetHeight + 'px'}});
		var arrow = new Element('div', {'id': 'navigation-arrow', 'class': 'slider-1', 'styles': {'top': arrow_y}});
		var titles_div = new Element('div', {'id': 'navigation-titles', 'class': 'navigation-titles slider-1'});
		var titles_div_heading = new Element('div', {'class': 'title'});
		var titles_div_heading_border = new Element('div', {'class': 'border'});
		var titles_div_heading_white = new Element('div', {'class': 'white'});
		var titles_div_ul_holder = new Element('div', {'id': 'sub-nav-ul-holder', 'class': 'ul-holder'});
		var titles_list = new Element('ul', {'id': 'titles_list', 'class': 'fade-1'});
		var abstract_div = new Element('div', {'id': 'abstracts', 'class': 'slider-2'});
		var abstract_div_heading = new Element('div', {'class': 'title'});
		var close_nav = new Element('div', {
			'class': 'close',
			'events': {
				'click': function(){					
					animateSlideOuts('in');
				},
				'mouseover': function(e){					
					hoverCloseBut(e,'over');
				},
				'mouseout': function(e){					
					hoverCloseBut(e,'out');
				}
			}
		});
		var abstract_div_content = new Element('div', {'class': 'content'});
		var abstract_div_inner = new Element('div', {'id': 'abstract_div_inner', 'class': 'inner fade-1'});
		
		var lists = "";
		for(var i=0; i<titles.length; i++){
			if(i===0){
				lists += '<li class="nav-on"><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
			} else if(i==titles.length-1){
				lists += '<li style="background-image:none;"><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
			} else {
				lists += '<li><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
			}
		}
		
		titles_list.innerHTML = lists;
		abstract_div_inner.innerHTML = populateAbstract(xml,0,titles);
		
		titles_div_ul_holder.appendChild(titles_list);
		titles_div_heading.appendChild(titles_div_heading_border);
		titles_div_heading.appendChild(titles_div_heading_white);
		titles_div.appendChild(titles_div_heading);
		titles_div.appendChild(titles_div_ul_holder);		
		abstract_div_heading.appendChild(close_nav);
		abstract_div.appendChild(abstract_div_heading);
		abstract_div_content.appendChild(abstract_div_inner);
		abstract_div.appendChild(abstract_div_content);
		
		titles_div.inject($('content'));
		arrow.inject(titles_div, 'after');		
		abstract_div.inject(arrow, 'after');
		nav_cover.inject(abstract_div, 'after');
		
		var primary_navs_titles_as = $$('#navigation-titles a');
		$each(primary_navs_titles_as, function(pna, j){
			pna.id = "pna-" + j;
			pna.hideFocus = true;
			$("pna-" + j).addEvent('click', function(e){
				if(this.parentNode.parentNode.className.indexOf("nav-on") < 0){
					updateNavClasses(e);
					updateAbstract(e,xml,j,titles);
				}
				
				e = new Event(e);
				e.stop(); 
				
			});
			pna.id = "";
	   	});
		
		animateSlideOuts('out');
		
		
	
	} else if(titles.length > 0 && !animating && document.getElementById("navigation-titles")){
		animating = true;
		var fx1, fx2, fx3;
		var o = {};
		
		
		fx1 = new Fx.Elements($$('.fade-1'), {
			duration:400,
			wait:true,
			onComplete: function(){
				var lists = "";
				for(var i=0; i<titles.length; i++){
					if(i===0){
						lists += '<li class="nav-on"><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
					} else if(i==titles.length-1){
						lists += '<li style="background-image:none;"><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
					} else {
						lists += '<li><span><a href="' + root_dir + titles[i][1] + '">' + titles[i][0] + ' &raquo;</a></span><div class="arrow"></div></li>';
					}
				}
				
				
				$('titles_list').innerHTML = lists;
				$('abstract_div_inner').innerHTML = populateAbstract(xml,0,titles);
				
				var fade_shutter = checkTitleHeight(1);
				
				var primary_navs_titles_as = $$('#navigation-titles a');
				$each(primary_navs_titles_as, function(pna, j){
					pna.id = "pna-" + j;
					pna.hideFocus = true;
					$("pna-" + j).addEvent('click', function(e){
						if(this.parentNode.parentNode.className.indexOf("nav-on") < 0){									 
							updateNavClasses(e);
							updateAbstract(e,xml,j,titles);
						}
						
						e = new Event(e);
						e.stop(); 
						
					});
					pna.id = "";
				});
				
				
				fx2 = new Fx.Elements($$('.fade-1'), {
					duration:400,
					wait:true,
					onComplete: function(){
						animating = false;
					}
				});
				
				o = {};
				$each($$('.fade-1'), function(el, i){
					o[i] = {opacity: [0,1]};
				});
				
				fx2.start(o);
					

				
			}
		});				
		
		fx3 = new Fx.Elements($('navigation-arrow'), {
			duration:420,
			wait:true,
			onComplete: function(){
				$('navigation-arrow').style.top = arrow_y;
				fx4.start({
					'0': {
						'left': [-171,0]
					}
				});
			}
		});
		
		fx4 = new Fx.Elements($('navigation-arrow'), {
			duration:420,
			wait:true,
			onComplete: function(){
			}
		});
		
		
		o = {};
		$each($$('.fade-1'), function(el, i){
			o[i] = {opacity: [1,0]};
		});
		
		fx1.start(o);
		
		fx3.start({
			'0': {
				'left': [0,-171]
			}
		});
	}	
}






/****************************************************
* Check Titles Heights and Create Blinds if needed	*
*													*
*****************************************************/

function checkTitleHeight(num){
	var height = 0;
	var extras = 0;
	var new_uls = [], new_lis = "", shutter = [];
	var distance = 124;
	var cut_off = 148;
	
	if(browser.isIE){ distance = 122; cut_off = 146; }
	
	if(num == 1){
		if(browser.isIE){ distance = 123; }
		else { distance = 125; }
	}
	
	$each($$('#navigation-titles .shutter-control'), function(sh, j){
		if(document.getElementById('shutter_'+j)){ $('shutter_'+j).destroy(); }
	});
	$each($$('#navigation-titles .extra-ul'), function(ul, j){
		if(document.getElementById('titles_list_'+parseInt(j+1,10))){ $('titles_list_'+parseInt(j+1,10)).destroy(); }
	});
	
	if(document.getElementById('titles_list')){
		$each($$('#titles_list li'), function(li, j){
			if(extras > 0){
				new_uls[extras-1].appendChild(li);
			}
			
			height += li.offsetHeight;
			if($('torso').offsetHeight - cut_off - height < 0){
				if(extras == 0){
					$('titles_list').setStyles({
						'height': $('torso').offsetHeight - cut_off + 'px',
						'max-height': $('torso').offsetHeight - cut_off + 'px',
						'min-height': $('torso').offsetHeight - cut_off + 'px',
						'position': 'absolute',
						'z-index': '1'
					});
					$('titles_list').className += " shutter_0";
				}
	
				
				if(extras == 0){
					shutter[extras] = new Element('div', {'id': 'shutter_'+parseInt(extras,10), 'class': 'shutter-control fade-1 shutter_'+parseInt(extras,10), 'styles': { 'clear': 'both', 'opacity': '0', 'z-index': '2', 'top': $('torso').offsetHeight - distance + 'px'}, 'events': {'click': function(e){ doShutter(e); }, 'mouseover': function(e){ hoverShutterBut(e,'over'); }, 'mouseout': function(e){ hoverShutterBut(e,'out'); }} });
				} else {
					shutter[extras] = new Element('div', {'id': 'shutter_'+parseInt(extras,10), 'class': 'shutter-control fade-1 shutter_'+parseInt(extras,10), 'styles': { 'clear': 'both', 'opacity': '0', 'z-index': '2', 'top': $('torso').offsetHeight - distance + 'px'}, 'events': {'click': function(e){ doShutter(e); }, 'mouseover': function(e){ hoverShutterBut(e,'over'); }, 'mouseout': function(e){ hoverShutterBut(e,'out'); }} });
				}
				
				new_uls[extras] = new Element('ul', {'id': 'titles_list_'+parseInt(extras + 1,10), 'class': 'fade-1 extra-ul', 'styles': { 'position': 'absolute', 'z-index': '0'}});
				
				extras++;
				height = li.offsetHeight;
			}
		});
	}
	
	if(new_uls.length == 0){
		$('titles_list').setStyles({
			'height': '394px',
			'max-height': '394px',
			'min-height': '394px',
			'position': 'relative',
			'top': '0'
		});
		$('titles_list').className = "fade-1";
		return true;
		
	} else {
		for(var i=0; i<new_uls.length; i++){
			new_uls[i].inject($('sub-nav-ul-holder'));
			shutter[i].inject($('sub-nav-ul-holder'));
		}
		return false;
	}		
}







/****************************************************
* Animate Slideout Menus							*
*													*
*****************************************************/

function animateSlideOuts(dir){
	var fx_titles, fx_abstract;
	
	fx_abstract = new Fx.Elements($$('.slider-2'), {
		duration:400,
		wait:true,
		onComplete: function(){
			if(dir == "in"){
				$('abstracts').style.display = "none";
				fx_titles.start({
					'0': {
						'left': [0,-171]
					},
					'1': {
						'left': [0,-171]
					}
				});
				
			} else if(dir == "out"){
				animating = false;
			}
		}
	});
	
	fx_titles = new Fx.Elements($$('.slider-1'), {
		duration:400,
		wait:true,
		onComplete: function(){
			if(dir == "out"){
				$('abstracts').setStyles({
					'display': 'inline',
					'z-index': 1
				});
				
				fx_abstract.start({
					'0': {
						'left': [-94,170]
					}
				});
				
			} else if(dir == "in"){
				$('navigation-arrow').style.display = "none";
				$('navigation-titles').style.display = "none";
				$('navigation-arrow').destroy();
				$('navigation-titles').destroy();
				$('abstracts').destroy();
				$('navigation-cover').destroy();
				
				var clicked_lis = $$("#navigation li");
				for(var i=0; i<clicked_lis.length; i++){
					clicked_lis[i].style.marginTop = "0px";
					clicked_lis[i].style.paddingTop = "0px";
					if(clicked_lis[i].className.indexOf("nav-on") > -1){
						clicked_lis[i].className = clicked_lis[i].className.replace(/nav-on/i, "");
					} else {
						clicked_lis[i].className = "";
					}
				}
				
				animating = false;
			}
		}
	});	
	
	if(dir == "out"){
		$('navigation-arrow').style.display = "inline";
		$('navigation-titles').setStyles({
			'display': 'inline',
			'z-index': 2,
			'opacity': 0
		});
		
		checkTitleHeight();
		$each($$('#navigation-titles .shutter-control'), function(sh, j){
			if(document.getElementById('shutter_'+j)){ $('shutter_'+j).setStyles({'opacity': '1'}); }
		});
		
		
		/*$('navigation-titles').style.height = "100%";
		$('navigation-titles').style.minHeight = "100%";		
		$('abstracts').style.height = "100%";
		$('abstracts').style.minHeight = "100%";*/
		
		$('navigation-titles').style.height = $('content').getSize().y;
		$('navigation-titles').style.minHeight = $('content').getSize().y;		
		$('abstracts').style.height = $('content').getSize().y;
		$('abstracts').style.minHeight = $('content').getSize().y;
		
		$('navigation-titles').setStyles({
			'opacity': 1
		});
		
		fx_titles.start({
			'0': {
				'left': [-171,0]
			},
			'1': {
				'left': [-171, 0]
			}
		});
		
	} else if(dir == "in"){
		fx_abstract.start({
			'0': {
				'left': [170,-94]
			}
		});
	}
}





/****************************************************
* Do Shutter Effect on Sub Nav						*
*													*
*****************************************************/

function doShutter(e){
	animating = true;
	if (!e){ e = window.event; }
	var tgt = e.target || e.srcElement;
	var css, bg, bg_orig, ul_num, distance = 124;
	
	if(browser.isIE){ distance = 122; }
	
	if(tgt.currentStyle){
		bg = tgt.currentStyle.backgroundImage;
		if(browser.isIE6 || browser.isIE5){
			bg = tgt.currentStyle.filter.substring(tgt.currentStyle.filter.indexOf("http:"), parseInt(tgt.currentStyle.filter.indexOf(".png") + 4,10));
			bg_orig = tgt.currentStyle.backgroundImage;
		}
	} else {
		css = getComputedStyle(tgt,'')
		bg = css.getPropertyValue("background-image");
	}
	
	ul_num = parseInt(tgt.id.replace(/shutter_/g, ""),10);
	var fx = new Fx.Elements($$('.shutter_'+ul_num), {
		duration:400,
		wait:true,
		onComplete: function(){
			animating = false;
		}
	})
	
	bg = bg.replace(/1a.gif/i, "1.gif");
	bg = bg.replace(/2a.gif/i, "2.gif");

	if(bg.indexOf("shutter1") > -1){
		if(browser.isIE6 || browser.isIE5){
			tgt.style.backgroundImage = "url(" + bg.replace(/shutter1/i, "shutter2") + ")";
			tgt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg.replace(/shutter1/i, "shutter2") + "', sizingMethod='crop')";
			tgt.style.backgroundImage = bg_orig;
			
		} else {
			tgt.style.backgroundImage = bg.replace(/shutter1/i, "shutter2");
		}
		
		fx.start({
			'0': {
				'top': [0, (-1 * parseInt($$('.shutter_'+ul_num)[0].offsetHeight + 2,10)) + 'px']
			},
			'1': {
				'top': '1px'
			}
		});
		
		if(document.getElementById('titles_list_'+parseInt(ul_num + 1,10))){
			if($('titles_list_'+parseInt(ul_num + 1,10))){
				fadeUl('in', $('titles_list_'+parseInt(ul_num + 1,10)));
			}
		}
														   
		
	} else if(bg.indexOf("shutter2") > -1){
		if(browser.isIE6 || browser.isIE5){
			tgt.style.backgroundImage = "url(" + bg.replace(/shutter2/i, "shutter1") + ")";
			tgt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg.replace(/shutter2/i, "shutter1") + "', sizingMethod='crop')";
			tgt.style.backgroundImage = bg_orig;
			
		} else {
			tgt.style.backgroundImage = bg.replace(/shutter2/i, "shutter1");
		}
		
		fx.start({
			'0': {
				'top': '1px'
			},
			'1': {
				'top': $('torso').offsetHeight - distance + 'px'
			}
		});
			
		if(document.getElementById('titles_list_'+parseInt(ul_num + 1,10))){
			if($('titles_list_'+parseInt(ul_num + 1,10))){
				fadeUl('out', $('titles_list_'+parseInt(ul_num + 1,10)));
			}
		}
	}
}





/****************************************************
* Fade Arrows under Shutter							*
*													*
*****************************************************/

function fadeUl(dir,el){
	var fx = new Fx.Elements(el, {
		duration:400,
		wait:true,
		onComplete: function(){
			if(dir!='in'){ el.setStyles({'display': 'none'}); }
			animating = false;
		}
	})	

	if(dir=='in'){ 
		el.setStyles({'opacity': '0', 'display': 'inline'});
		fx.start({'0': {'opacity': 1}});
		
	} else {		
		fx.start({'0': {'opacity': 0}});
	}
}







/****************************************************
* Update Abstracts									*
*													*
*****************************************************/

function updateAbstract(e,xml,ind,titles){
	if($$('#abstracts .inner').length > 0 && !animating){
		animating = true;
		var cfx = new Fx.Elements($$('#abstracts .inner'), {
			duration:400,
			wait:true,
			onComplete: function(){
				updateAbstract2(e,xml,ind,titles)
			}
		}).start({
			'0': {
				'opacity': [1,0]
			}
		});
	}
}

function updateAbstract2(e,xml,ind,titles){
	$$('#abstracts .inner')[0].innerHTML = populateAbstract(xml,ind,titles);
	var cfx = new Fx.Elements($$('#abstracts .inner'), {
		duration:400,
		wait:true,
		onComplete: function(){
			animating = false;
		}
	}).start({
		'0': {
			'opacity': [0,1]
		}
	});
}




/****************************************************
* Handle Hovers on Close Button and Shuuter Button	*
*													*
*****************************************************/

function hoverCloseBut(e,state){
	if (!e){ e = window.event; }
	var tgt = e.target || e.srcElement;
	var css, bg, bg_orig;
	
	if(tgt.currentStyle){
		bg = tgt.currentStyle.backgroundImage;
		if((browser.isIE6 || browser.isIE5) && state=="out"){
			bg = tgt.currentStyle.filter.substring(tgt.currentStyle.filter.indexOf("http:"), parseInt(tgt.currentStyle.filter.indexOf(".png") + 4,10));
			bg_orig = tgt.currentStyle.backgroundImage;
		}
	} else {
		css = getComputedStyle(tgt,'')
		bg = css.getPropertyValue("background-image");
	}

	if(state=="over"){
		if(browser.isIE6 || browser.isIE5){
			tgt.style.backgroundImage = bg.replace(/n.gif/i, "n2.png");
			bg = bg.replace(/url\("/i, "");
			bg = bg.replace(/"\)/i, "");
			tgt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + bg.replace(/n.gif/i, "n2.png") + "', sizingMethod='crop')";
			tgt.style.backgroundImage = "url(" + root_dir + "css/blank.gif)";
			
		} else {
			tgt.style.backgroundImage = bg.replace(/n.gif/i, "n2.png");
		}														   
		
	} else {
		if(browser.isIE6 || browser.isIE5){
			tgt.style.filter = "none";
			tgt.style.backgroundImage = "url(" + bg.replace(/n2.png/i, "n.gif") + ")";		
		} else {
			tgt.style.backgroundImage = bg.replace(/n2.png/i, "n.gif");
		}
	}
}


function hoverShutterBut(e,state){
	if (!e){ e = window.event; }
	var tgt = e.target || e.srcElement;
	var css, bg, bg_orig, new_bg;
	
	if(tgt.currentStyle){
		bg = tgt.currentStyle.backgroundImage;
		if(browser.isIE6 || browser.isIE5){
			bg = tgt.currentStyle.filter.substring(tgt.currentStyle.filter.indexOf("http:"), parseInt(tgt.currentStyle.filter.indexOf(".png") + 4,10));
			bg_orig = tgt.currentStyle.backgroundImage;
		}
	} else {
		css = getComputedStyle(tgt,'')
		bg = css.getPropertyValue("background-image");
	}

	if(state=="over"){
		new_bg = bg.replace(/1.gif/i, "1a.gif");
		new_bg = new_bg.replace(/2.gif/i, "2a.gif");				   
		
	} else {
		new_bg = bg.replace(/1a.gif/i, "1.gif");
		new_bg = new_bg.replace(/2a.gif/i, "2.gif");		
	}
	
	if(browser.isIE6 || browser.isIE5){
		tgt.style.backgroundImage = "url(" + new_bg + ")";
		tgt.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + new_bg + "', sizingMethod='crop')";
		tgt.style.backgroundImage = bg_orig;
		
	} else {
		tgt.style.backgroundImage = new_bg;
	}
}





/****************************************************
* Return HTML from XML								*
*													*
*****************************************************/

function getHTMLfromXML(node){
	if (typeof node.textContent != 'undefined'){
		return node.textContent;
	} else if (typeof node.innerText != 'undefined'){
		return node.innerText;
	} else if (typeof node.text != 'undefined'){
		return node.text;
	} else {
		switch (node.nodeType){
			case 3:
			case 4:
				return node.nodeValue;
			case 1:
			case 11:
				var innerText = '';
				for (var i = 0; i < node.childNodes.length; i++){
					innerText += getInnerText(node.childNodes[i]);
				}
				return innerText;
			default:
				return '';
		}
	}
}




/****************************************************
* Initialise MooTools Elements						*
*													*
*****************************************************/

function initMooTools(){
	initNavigation();
}


window.addEvent('domready', initMooTools);
window.addEvent('resize', initMooTools);
