// == News back button ==
function BackButton() {
	window.history.back()
}


// == Show and hide function for show pages ==
function ShowOrHideContent(DivId){
	if($('body-text').style.display != "" && $('body-text').style.display != "block"){
		new Effect.Morph(DivId, {
			style: 'height:100%;',
			duration: 0,
			afterFinish: function(effect){
				Effect.BlindDown('body-text');
			}
		});
		$('show-more').innerHTML = "Close";
	}else{
		new Effect.BlindUp('body-text', {
			afterFinish: function(effect){
				new Effect.Morph(DivId, {
					style: 'height:25px',
					duration: 0
				})
			}
		});
		$('show-more').innerHTML = "More info";	
	}	
}

function ShowOrHideContentWithHeader(DivId){
	if($('body-text').style.display != "" && $('body-text').style.display != "block"){
		$('title-text').hide();
		new Effect.Morph(DivId, {
			style: 'height:100%;',
			duration: 0,
			afterFinish: function(effect){
				Effect.BlindDown('body-text');
			}
		});
		$('show-more').innerHTML = "Close";
	}else{
		new Effect.BlindUp('body-text', {
			afterFinish: function(effect){
				new Effect.Morph(DivId, {
					style: 'height:25px',
					duration: 0,
					afterFinish: function(effect){
						$('title-text').show();
					}
				})
			}
		});
		$('show-more').innerHTML = "More info";	
	}			
}

// == Functions for changing the background image and highlighting numbers ==
function ChangeImageBg(ImageSrc, LinkId){
	// Show preloader
	$('preloader').style.display = "block";
	
	// Create new image
	var newImage = document.createElement('img');
	newImage.id = 'new-img-bg';
	newImage.onload = function(){
		NewImageBgLoaded(newImage,LinkId);
	}
	newImage.src = ImageSrc;		
}

function NewImageBgLoaded(newImage,LinkId){
	// Replace current image
	$('new-image-holder').replaceChild(newImage,$('new-img-bg'));
	SetNumberLinks(LinkId);
	$('img-bg').src = $('new-img-bg').src;
	$('preloader').style.display = "none";
}

function SetNumberLinks(LinkId){
	for(i = 1; i <= $('images-count').value; i++){
		$('hl-show-more' + i).className = "link-deactive";
	}
	$('hl-show-more' + LinkId).className = "link-active";
	$('images-current').value = LinkId;
}

function ChangePrevious(){
	if($('images-current').value > 1){
		$('hl-show-more' + ($('images-current').value - 1)).onclick();
	}
}

function ChangeNext(){
	if($('images-current').value < $('images-count').value){
		$('hl-show-more' + (parseInt($('images-current').value) + 1)).onclick();
	}
}

// == Email functions ==
function WriteEmail(Name){
	var EmailName = Name;
	var EmailSeperator = "@";
	var EmailDomain = "dalziel-pow.co.uk";
	var Email = EmailName + EmailSeperator + EmailDomain;
	document.write('<a href="mailto:' + Email + '">' + Email + '</a>');
}

function WriteBrochureEmail(Text){
	var EmailName = 'info';
	var EmailSeperator = "@";
	var EmailDomain = "dalziel-pow.co.uk";
	var Email = EmailName + EmailSeperator + EmailDomain;
	var EmailSubject = "?subject=" + Text + ' brochure request';
	document.write('<a href="mailto:' + Email +  EmailSubject + '">' + Text + '</a>');
}