//	open external links in a new window - replaces target="_blank"
	function externalLinks () { 
		if ( ! document.getElementsByTagName ) return; 
		var anchors = document.getElementsByTagName("a"); 
		for ( var i=0; i < anchors.length; i++ ) { 
			var anchor = anchors[i]; 
			if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) anchor.target = "_blank"; 
		} 
	} 

//	preload images
	function preload_images () {
		arImageSrc = new Array ();
		arImageList = new Array ();
		for (counter in arImageSrc) {
			arImageList[counter] = new Image();
			arImageList[counter].src = arImageSrc[counter];
		}
	}


//	add given page to favourites (bookmark)
	function setBookmark ( url, str ) {
		if ( str == '' ) str = url;
		if ( document.all ) window.external.AddFavorite( url, str );
		else alert( 'Sorry, this function only works in Internet Explorer.\n\nPlease press CTRL and D to add a bookmark to \n"' + str + '".' );
	}

//	toggle a given elements visibility
	function toggle (el) {
		if ( document.getElementById(el).style.display == 'none' ) {
			document.getElementById(el).style.display = '';
		} else {
			document.getElementById(el).style.display = 'none';
		}
	}

//	show a given element
	function show (el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = '';
	}

//	activate the correct navigation
	function activate_nav() {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 1;
		var filename = patharray[folderposition];
		var filearray = filename.split('.');
		var nav = filearray[0];
		if ( nav == 'index' || nav == '' ) {
			nav = 'home';
		}
		if ( nav == 'search' || nav == 'email' ) {
			nav = 'blank';
		}
		
		if ( nav == 'whos_who' ) {
			nav = 'about';
		}
		
		if ( document.getElementById('nav_' + nav) != undefined ) document.getElementById('nav_' + nav).className = 'selected';
	}

//	show a given navigation
	function show_nav(nav) {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 2;
		document.getElementById('nav').src = 'media/images/nav_' + nav + '.gif';
	}

//	restore the navigation depending on the current page
	function restore_nav() {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 1;
		var filename = patharray[folderposition];
		var filearray = filename.split('.');
		var filename = filearray[0];
		var nav2show = '';
		switch ( filename ) {
			case 'about' :
				nav2show = 'nav_about';
				break;
			case 'blog' :
				nav2show = 'nav_blog';
				break;
			case 'shop' :
				nav2show = 'nav_shop';
				break;
			case 'links' :
				nav2show = 'nav_links';
				break;
			case 'contact' :
				nav2show = 'nav_contact';
				break;
			case 'denandtheartof.co.uk' :
			case 'index' :
			case '' :
				nav2show = 'nav_home';
				break;
			default :
				nav2show = 'nav_blank';
				break;
		}
		if ( nav2show == '' ) {
			nav2show = 'nav_home';
		}
		document.getElementById('nav').src = 'media/images/' + nav2show + '.gif';
	}

//	when search field received focus
	function focus_search() {
		if ( document.getElementById('q').value == 'Search this site...' ) {
			document.getElementById('q').value = '';
		}
	}
	
	function blur_search() {
		if ( document.getElementById('q').value == '' ) {
			document.getElementById('q').value = 'Search this site...';
		}
	}

//	perform the following functions when the page loads
	window.onload = function(e) {
		externalLinks();
		activate_nav();
		show_initial_sub_menu();
		if ( typeof updateList == 'function' ) {
			updateList(document.getElementById('move'), document.getElementById('newList'));		
		}
	}
	
	
//	navigation
		function show_menu(el) {
			if ( document.getElementById('sub_navigation_holder') != undefined ) {
				document.getElementById('sub_navigation_holder').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_about') != undefined ) {
				document.getElementById('sub_navigation_about').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_technical_support') != undefined ) {
				document.getElementById('sub_navigation_technical_support').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_products') != undefined ) {
				document.getElementById('sub_navigation_products').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_home') != undefined ) {
				document.getElementById('sub_navigation_home').style.display = 'none';
			}
			if ( document.getElementById(el) != undefined ) {
				document.getElementById(el).style.display = '';
			}
		}
		function hide_menu() {
			if ( document.getElementById('sub_navigation_holder') != undefined ) {
				document.getElementById('sub_navigation_holder').style.display = '';
			}
			if ( document.getElementById('sub_navigation_about') != undefined ) {
				document.getElementById('sub_navigation_about').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_technical_support') != undefined ) {
				document.getElementById('sub_navigation_technical_support').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_products') != undefined ) {
				document.getElementById('sub_navigation_products').style.display = 'none';
			}
			if ( document.getElementById('sub_navigation_home') != undefined ) {
				document.getElementById('sub_navigation_home').style.display = 'none';
			}
			show_initial_sub_menu();
		
		}
		function show_initial_sub_menu() {
			var fullpath = location.pathname;
			var patharray = fullpath.split('/');
			var folderposition = patharray.length - 1;
			var filename = patharray[folderposition];
			var filearray = filename.split('.');
			var nav = filearray[0];

			switch ( nav ) {
				
				case 'about' :
				case 'whos_who' :
				case 'partners' :
				case 'company_history' :
					if ( document.getElementById('sub_navigation_about') != undefined ) {
						if ( document.getElementById('sub_navigation_holder') != undefined ) {
							document.getElementById('sub_navigation_holder').style.display = 'none';
						}
						document.getElementById('sub_navigation_about').style.display = '';
					}
					break;

				case 'home_page_content' :
				case 'home_page_slides' :
					if ( document.getElementById('sub_navigation_home') != undefined ) {
						if ( document.getElementById('sub_navigation_holder') != undefined ) {
							document.getElementById('sub_navigation_holder').style.display = 'none';
						}
						document.getElementById('sub_navigation_home').style.display = '';
					}
					break;					
				
				case 'products' :
				case 'categories' :
				case 'press_releases' :
				case 'catalogue_order' :
				case 'high_res' :
					if ( document.getElementById('sub_navigation_products') != undefined ) {
						if ( document.getElementById('sub_navigation_holder') != undefined ) {
							document.getElementById('sub_navigation_holder').style.display = 'none';
						}
						document.getElementById('sub_navigation_products').style.display = '';
					}
					break;					

				case 'technical_support' :
				case 'video_tutorials' :
				case 'datasheets' :
				case 'manuals' :
				case 'software' :
				case 'faq' :
				case 'highres_image' :
					if ( document.getElementById('sub_navigation_holder') != undefined ) {
						document.getElementById('sub_navigation_holder').style.display = 'none';
					}
					if ( document.getElementById('sub_navigation_technical_support') != undefined ) {
						document.getElementById('sub_navigation_technical_support').style.display = '';
					}
					break;					
				
				
				default :
					if ( document.getElementById('sub_navigation_holder') != undefined ) {
						document.getElementById('sub_navigation_holder').style.display = '';
					}
					if ( document.getElementById('sub_navigation_about') != undefined ) {
						document.getElementById('sub_navigation_about').style.display = 'none';
					}
					if ( document.getElementById('sub_navigation_technical_support') != undefined ) {
						document.getElementById('sub_navigation_technical_support').style.display = 'none';
					}
					if ( document.getElementById('sub_navigation_products') != undefined ) {
						document.getElementById('sub_navigation_products').style.display = 'none';
					}
					break;
				
				
			}
			
		}
	
