var openRepeat=null;
var opV = 0;

function jg_showEmbeded(id,pano){
	E("embedPanoContainer_"+id).style.opacity = 0;
	E("embedPanoContainer_"+id).style.filter = 'alpha(opacity=0)';	
	
	opV = 0;
	
	jg_sizeDiv(id,20,pano);
}

function jg_hideEmbeded(id){	
	opV = 10;
	
	E("embedPanoMid_"+id).innerHTML = "";
	
	jg_opacity(id,-1,'');
}

function jg_sizeDiv(id,inc,pano){
	var h=E("embedPanoContainer_"+id).offsetHeight;
	
	if(inc>0&&h+inc>302){inc=302-h;};
	if(inc<0&&h+inc<0){inc=(0-h);};
	
	if((inc>0&&h<302)||(inc<0&&h>0))
	{
		E("embedPanoContainer_"+id).style.height = h+inc+"px";
	}
	
	// set-up the repeat
	if (openRepeat==null)
	{
		openRepeat = setInterval("jg_sizeDiv("+id+","+inc+",'"+pano+"')",10)
	}	

	if(inc>=0&&h>=302)
	{
		E("embedPanoContainer_"+id).style.height = "302px";
		clearInterval(openRepeat);
		openRepeat=null;
		jg_opacity(id,1,pano);
	}
	if(inc<=0&&h<=0)
	{
		E("embedPanoContainer_"+id).style.height = "0px";
		clearInterval(openRepeat);
		openRepeat=null;
		// ends here if closed
		//alert("closed");
	}
}

function jg_opacity(id,inc,pano){
	opV+=inc;
	E("embedPanoContainer_"+id).style.opacity = opV/10;
	E("embedPanoContainer_"+id).style.filter = 'alpha(opacity=' + opV*10 + ')';

	// set-up the repeat
	if (openRepeat==null)
	{
		openRepeat = setInterval("jg_opacity("+id+","+inc+",'"+pano+"')",50)
	}

	if(opV==0||opV==10)
	{
		clearInterval(openRepeat);
		openRepeat=null;
		if(opV==0)
		{
			jg_sizeDiv(id,-20,'');
		}
		else
		{
		// ends here if opening
		jg_insertSmPano(id,pano);
		return false;
		}
	}
}

function jg_insertSmPano(id,fileName){
	var c;
	
	fL= fileName.length; // due to bug in IE cant use substr(-3) in if statement below
	fS= fL-3; // as above

	if(fileName.substr(fS)=="swf")
	{
		c="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
		c+=" codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'";
		c+=" width='735' height='235'>\n";
		c+="<param name='movie' value='flash/small/" + fileName + "'>\n";
		c+="<embed src='flash/small/" + fileName + "' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='735' height='235' />\n";
		c+="</object>";
	}
	else
	{
		c='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="735" height="235" >';
		c+='<param name="src" value="qt/small/'+fileName+'">';
		c+='<param name="scale" value="tofit">';
		c+='<param name="controller" value="false">';	  
		c+='<embed width="735" height="235" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" src="qt/small/'+fileName+'" scale="1" controller="false" />';
		c+='</object>';
	}

	E("embedPanoMid_"+id).innerHTML = c;
}


function jg_open_full(tp,id) {
	mywindow = window.open("pano_full.php?tp="+tp+"&id="+id,"mywindow","location=0,status=0,scrollbars=1,toolbar=0,menubar=0,directories=0,resizable=1,width="+window.screen.availWidth+",height="+window.screen.availHeight);
	mywindow.moveTo(0,0);
}


//CONTACT FUNCTIONS


var validated = 0;


function jg_validate(){
	jg_name_check(E("emailFormName").value)
	jg_email_check(E("emailFormEmail").value)
	jg_captcha_check(E("emailFormCaptcha").value)
	if(validated<3)
	{
		alert("Please check the details you have entered\n\nOne or more appear incomplete");
	}
	else
	{		
		// working graphic on
		E("statusHeader").style.display = "none";
		E("statusText").innerHTML = "<br /><br /><br /><br /><br /><br /><span style=\"font-size:24px;text-decoration:blink\">Working...</span>";
		E("emailStatus").style.visibility="visible";
		var parameters = E("emailFormName").id + "=" + encodeURI(E("emailFormName").value) + "&" + E("emailFormEmail").id + "=" + encodeURI(E("emailFormEmail").value) + "&" + E("emailFormSubject").id + "=" + encodeURI(E("emailFormSubject").value) + "&" + E("emailFormMessage").id + "=" + encodeURI(E("emailFormMessage").value) + "&" + E("emailFormCaptcha").id + "=" + E("emailFormCaptcha").value;
		// send
		//alert(parameters);
		jg_ajax_post('scripts/emailsend.asp',parameters,"sendMail");
	}
}

function jg_ajax_passback(http_request,callID){
	if(callID=="sendMail")
	{
		var returnedStatus = http_request.responseText.split("*n")
		E("statusHeader").innerHTML = returnedStatus[0];
		E("statusText").innerHTML = returnedStatus[1].replace(/\$n/ig,"<br />");
		E("statusHeader").style.display = "block";
		E("emailStatus").style.visibility="visible";
	}
}

function jg_name_check(str){
	if(str.length==0)
	{
		E("emailWarningName").style.visibility="visible";
		validated = 0;
	}
	else
	{
		E("emailWarningName").style.visibility="hidden";
		validated += 1;
	}
}

function jg_email_check(str) {
var isValid = 1;

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)

if(str.substring(lstr,lstr-1)==dot)
{
	isValid = 0;
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
{
   isValid = 0;
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
{
	isValid = 0;
}

 if (str.indexOf(at,(lat+1))!=-1)
 {
	isValid = 0;
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
 {
	isValid = 0;
 }

 if (str.indexOf(dot,(lat+2))==-1)
 {
	isValid = 0;
 }

 if (str.indexOf(" ")!=-1)
 {
	isValid = 0;
 }

 if(isValid == 0)
 {
	E("emailWarningEmail").style.visibility="visible";
	validated = 0;
 }
 else
 {
 	E("emailWarningEmail").style.visibility="hidden";
	validated += 1;
 }			
}

function jg_captcha_check(str){
	if(str.length==0)
	{
		E("captchaNote").style.color="#F00";
		validated = 0;
	}
	else
	{
		E("captchaNote").style.color="#648c2d";
		validated += 1;
	}
}