 //**** On Page Load ****
function startup() {
 
	findheight();
 
}
 
 
 //*******Calculate and set the min-height attribute so that we can fill the screen.*******
 function findheight() {
 
 	var wheight = screen.availHeight;
 	
 	if (document.all){
 	
 		var nheight = wheight-385;
 	}
 	else {
 		var nheight = wheight-377;
 	}
 	
 	document.getElementById('maincontent').style.minHeight=nheight+"px";
 
}
 
 
 
 /* ====================================================
 Image Slide Show
==================================================== */

//*** Fader script ***
// http://brainerror.net/scripts/javascript/blendtrans/ for the fade transition

function opacityin(id, opacStart, opacEnd, millisec) { 
//speed for each frame 
var speed = Math.round(millisec / 100); 
var timer = 10; 

//determine the direction for the blending, if start and end are the same nothing happens 
if(opacStart > opacEnd) { 
 for(i = opacStart; i >= opacEnd; i--) { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} else if(opacStart < opacEnd) { 
 for(i = opacStart; i <= opacEnd; i++) 
 { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} 
} 

//change the opacity for different browsers 
function changeOpacin(opacity, id) { 
var object = document.getElementById(id).style; 
	object.filter = "alpha(opacity=" + opacity + ")"; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
} 




//*** Image swaper ***
function imagehide() {

	//this hides the initial fade-in image to make way for the full slide-show 	
	document.getElementById("hidefimg").style.display = "none";

}

function imagegallery() {

	//this part is what generates the image and calculates what image it is on and increment it by one on each loop of the image_swap() function
	if (nimg<opimages.length-1)
	{
	nimg++
	}
	else if (nimg>=opimages.length-1)
	{
	nimg = 0;
	}
	
	document.getElementById("rightgallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimg]+'" alt="Photography from Twisted Kitty Productions" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);  
	return true;
}


//****** Image Gallery - image change *******

function image_swap()
{

	//this part has been added to show the last image in the array to start with for 5 seconds as the slideshow has a 5 second delay	

	document.getElementById("rightgallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimgl]+'" alt="Photography from Twisted Kitty Productions" id="hidefimg" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);  
	var Tout = setTimeout("imagehide()", 5000);

	//this part activates and loops the fade in/out and image change script	
	var Tinterval = setInterval("imagegallery()", 5000);

	
} 




/** To validate forms before submit **/


function checkEnq() {

	var theform = "Required Fields";
	var origform = theform;
	
	cfname = document.enqform.realname.value;
	tcfemail = document.enqform.email.value; cfemail = tcfemail.match("@");
	cfenquiry = document.enqform.message.value;
	
	if(cfname == "" || cfname == " " || cfname == "  " || cfname == "   ")
	{
		document.getElementById("errorA").style.display = "inline";
		theform += "addme";
	}
	else
	{
		document.getElementById("errorA").style.display = "none";
	}

	if(cfemail == "" || cfemail == null || cfemail == " " || cfemail == "  " || cfemail == "   ")
	{
		document.getElementById("errorB").style.display = "inline";
		theform += "addme";
	}
	else
	{
		document.getElementById("errorB").style.display = "none";
	}

	if(cfenquiry == "" || cfenquiry == " " || cfenquiry == "  " || cfenquiry == "   ")
	{
		document.getElementById("errorC").style.display = "inline";
		theform += "addme";
	}
	else
	{
		document.getElementById("errorC").style.display = "none";
	}

	if (theform == origform)
	{
		document.enqform.submit();
		document.getElementById("errormsg").style.display = "none";
		return true;
 	}
 	else
 	{
 		document.getElementById("errormsg").style.display = "inline";
 		window.scrollTo(0,0);
 		return false;
 	}
}


/***** Pop Up Photo *****/

function largeimg(id,imgnum) {

	if(!document.getElementById("galleryimg"))
	{
		//** Build image container div and place it at the bottom of the body **
		var body = document.getElementsByTagName("body")[0];
		var dv = document.createElement("div");
		body.appendChild(dv);
		dv.setAttribute("id", "galleryimg");
	}

	//**** position large image at current location down the page no matter how far you have scrolled****
	
	tscreenheight = screen.availHeight;
	
	if (document.all)
	{
		tscreenwidth = screen.availWidth-21;
	}
	else
	{
		tscreenwidth = screen.availWidth-17;
	}
	
	
	//****page scroll offset****
	if (self.pageYOffset) 
	{
		var scrolling = self.pageYOffset;
	} 
	else
	{
		var scrolling = document.documentElement.scrollTop;
	}
		
	//****create height for transparent bg****
	if (tscreenheight+scrolling > document.documentElement.scrollHeight)
	{
		var bgimgheight = tscreenheight+scrolling;
	}
	else {
		var bgimgheight = document.documentElement.scrollHeight;
	}

	
	var lrgimgtoptemp = scrolling+50;
	var lrgimgtop = "width:"+opattsw[imgnum]+"px;height:"+opattsh[imgnum]+"px;";
	
	document.getElementById(id).style.paddingTop = lrgimgtoptemp+"px";
	document.getElementById(id).style.display = "block";
	document.getElementById(id).innerHTML = '<a onclick=\'closeimg()\' title="Click to close large photograph" alt="Click to close large photograph"><img src="/gfx/gallerybg.gif" width="'+tscreenwidth+'" height="'+bgimgheight+'" id="popupbg" /></a><div id="lrgimgcont" style="'+lrgimgtop+'"><img src="/gfx/clearme.gif" width="'+opattsw[imgnum]+'" height="'+opattsh[imgnum]+'" alt="Gig and Band Photography from Twisted Kitty Productions Photos" class="galleryLimg" style="background: url('+opimages[imgnum]+') no-repeat left top;" /><br /><div id="closeme"><a onclick=\'javascript:closeimg();\' title="Close the large photograph" class="closelrgimg"><img src="/gfx/clearme.gif" width="32" height="28" alt="Click to Close" /></a></div></div>';

}

function closeimg(id) {

	document.getElementById("closeme").style.backgroundImage="url(/gfx/closeimgon.png)";
	var t= setTimeout("document.getElementById('galleryimg').style.display = 'none';",300);
	var s= setTimeout("document.getElementById('galleryimg').innerHTML = '';",300);

}


function uploading() {

	if(!document.getElementById("galleryimg"))
	{
		//** Build image container div and place it at the bottom of the body **
		var body = document.getElementsByTagName("body")[0];
		var dv = document.createElement("div");
		body.appendChild(dv);
		dv.setAttribute("id", "galleryimg");
	}
	
	document.getElementById("galleryimg").style.paddingTop = "350px";
	document.getElementById("galleryimg").style.display = "block";
	document.getElementById("galleryimg").innerHTML = '<div id="lrgimgcontb" style="width:211px;height:61px;"><img src="/gfx/imgsloading.gif" width="211" height="61" alt="Photos now uploading" class="galleryLimg" /></div>';
}


function slideshow(dirk,mydiv){

showdiv = mydiv+"flash";
thediv = document.getElementById(showdiv);
menudiv = document.getElementById("mainmenu");

	if(dirk == "1")
	{
		thediv.style.display="block";
		menudiv.style.marginBottom = "50px";
		
	}
	else if(dirk == "0")
	{
		thediv.style.display="none";
		menudiv.style.marginBottom = "200px";
	}

}

function showflash(myfls){

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="200" height="150" id="slideshownew" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="/flash/slideshow.swf" />');
	document.write('<param name="FlashVars" value="myimglist=/flash/'+myfls+'.xml">');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="quality" value="best" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="#101010" />');
	document.write('<embed src="/flash/slideshow.swf" FlashVars="myimglist=/flash/'+myfls+'.xml" menu="false" quality="best" wmode="transparent" bgcolor="#101010" width="200" height="150" name="slideshownew" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
	
}

function zoomlocation(locat){

thediv = document.getElementById("tkplocation");
rightdiv = document.getElementById("curplocat");
mlocimgdiv = document.getElementById("ukmap");

	if(locat == "Aberdeenshire")
	{
		topnum = "-13px";
		leftnum = "138px";
		tmimg = "aberdeenshire"
	}
	else if(locat == "Yorkshire")
	{
		topnum = "92px";
		leftnum = "155px";
		tmimg = "yorkshire"
	}
	else if(locat == "Derbyshire")
	{
		topnum = "142px";
		leftnum = "185px";
		tmimg = "derbyshire"
	}
	else if(locat == "Nottinghamshire")
	{
		topnum = "137px";
		leftnum = "205px";
		tmimg = "nottinghamshire"
	}
	else if(locat == "Leicestershire")
	{
		topnum = "157px";
		leftnum = "195px";
		tmimg = "leicestershire"
	}
	
mlocimgdiv.style.opacity=0.7;
mlocimgdiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)"
	
thediv.style.top = topnum;
thediv.style.left = leftnum;
thediv.innerHTML = '<a href="/contact"><img src="/gfx/'+tmimg+'.png" alt="'+locat+'" onmouseout="hidelocat();" /></a>';
thediv.style.display = "block";

rightdiv.innerHTML = '<h2>'+locat+'</h2><img src="/gfx/'+tmimg+'.png" alt="'+locat+'" /><br clear="both" />Twisted Kitty '+locat+' can provide  Photography &amp; Promotional services in '+locat+' and the surrounding areas.<br /><br />Please contact us for more information on our Photography services and current availability.';
rightdiv.style.display = "block";
}

function hidelocat(){
thediv = document.getElementById("tkplocation");
thediv.style.display = "none";
thediv.innerHTML = '';

rightdiv = document.getElementById("curplocat");
rightdiv.style.display = "none";
rightdiv.innerHTML = '';

mlocimgdiv = document.getElementById("ukmap");
mlocimgdiv.style.opacity=1;
mlocimgdiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)"
}


function changebg(id,cdirc) {

ctdiv = document.getElementById(id);

	if(cdirc == "1")
	{
		ctdiv.style.backgroundColor = "#ffffff";
		ctdiv.style.borderRight="1px solid #ffffff"
		ctdiv.style.borderTop="1px solid #ffffff"
		ctdiv.style.borderBottom="1px solid #ffffff"
	}
	else if(cdirc == "0")
	{
		ctdiv.style.backgroundColor = "#EFEFEF";
		ctdiv.style.borderRight="1px solid #EFEFEF"
		ctdiv.style.borderTop="1px solid #EFEFEF"
		ctdiv.style.borderBottom="1px solid #EFEFEF"
	}
}


function chgopacity(tdiv,topac){

thisopac = topac/100;
ieopac = topac;

document.getElementById(tdiv).style.opacity = thisopac;
document.getElementById(tdiv).style.filter = "alpha(opacity="+ieopac+")";
document.getElementById(tdiv).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+ieopac+")";

}


function addstyles(){

	//** Build js rendered stylesheet that css validators fail on **
	var jstyle = document.getElementsByTagName("head")[0];
	var lk = document.createElement("link");
	jstyle.appendChild(lk);
	lk.setAttribute("rel", "stylesheet");
	lk.setAttribute("type", "text/css");
	lk.setAttribute("href", "/js-vl.css");

}
