// JavaScript Document
var infoEHeight;
var infoCHeight;
var infoTimer;
var delayTimer=0;
var resBoxCHeight = [];
var resBoxEHeight = [];
var resAnim=false;
var activeResBox;
var resizeType=false;
function betfairAdd(){
	var liab = parseFloat(document.getElementById('bfliab').value);
	var price = parseFloat(document.getElementById('bfprice').value);
	if(!isNaN(liab)){
		if(!isNaN(price)){
			if(price>1){
				if(liab>0){
					var stake = Math.round((liab / (price-1))*100);
					stake/=100;
					document.getElementById('betfairAns').innerHTML = '&pound;'+stake.toString();
					
				} else {
					document.getElementById('betfairAns').innerHTML = '&pound;0.00';
				}
			} else {
				document.getElementById('betfairAns').innerHTML = '&pound;0.00';	
			}
		}
	}
}
function loadImageBank(){
	window.open('image-bank.php','imageBank','width=600,height=600,location=no,menubar=no,scrollbars=1,status=no,toolbar=no');
}
function previewNewsletter(){
	window.open('newsletter-preview.php','previewPane','width=800,height=500,location=no,menubar=no,scrollbar=1,status=no,toolbar=no');
}
function previewAdvert(){
	window.open('ad-preview.php','previewPane','width=800,height=500,location=no,menubar=no,scrollbar=1,status=no,toolbar=no');
}
function retTextArea(){
	return tinyMCE.get('laynews').getContent();
}
function mouseOver(elemname){
	var elem = document.getElementsByName(elemname);
	if(elemname=='home_icon'){
		var img = new Image();
		img.src = "images/home-over.jpg";
		elem.src = img;
	}
}

function mouseOut(elemname){
	var elem = document.getElementsByName(elemname);
	if(elemname=='home_icon'){
		elem.src = "images/home.jpg";
	}
}
function setResBoxesHeight(total){
	for(i=0;i<total;i++){
		resBoxCHeight[i] = 0;
		resBoxEHeight[i] = Math.ceil(document.getElementById('resultDetails'+i).clientHeight);
		document.getElementById('resultDetails'+i).style.height=resBoxCHeight[i]+'px';
	}
}
function activateResBox(id){
	if(!resAnim){
		resAnim=true;
		activeResBox=id;
		if(resBoxCHeight[activeResBox]==0){
			resizeType=false;	
		} else {
			resizeType=true;	
		}
		infoTimer = window.setInterval(resizeActiveResBox,10);
	}
}
function resizeActiveResBox(){
	if(!resizeType){
		if(Math.ceil(document.getElementById('resultDetails'+activeResBox).clientHeight)>=resBoxEHeight[activeResBox]){
		   document.getElementById('resultDetails'+activeResBox).style.height=resBoxEHeight[activeResBox]+'px';
		   resAnim=false;
		   clearInterval(infoTimer);
		} else {
			resBoxCHeight[activeResBox] = resBoxCHeight[activeResBox]+Math.ceil(((resBoxEHeight[activeResBox]+10)-resBoxCHeight[activeResBox])/10);
			document.getElementById('resultDetails'+activeResBox).style.height=resBoxCHeight[activeResBox]+'px';
		}
	} else {
		if(Math.floor(document.getElementById('resultDetails'+activeResBox).clientHeight)<=0){
		   document.getElementById('resultDetails'+activeResBox).style.height='0px';
		   resAnim=false;
		   clearInterval(infoTimer);
		} else {
			resBoxCHeight[activeResBox] = resBoxCHeight[activeResBox]-Math.floor((resBoxCHeight[activeResBox]+10)/10);
			document.getElementById('resultDetails'+activeResBox).style.height=resBoxCHeight[activeResBox]+'px';
		}	
	}
}
function setInfoHeight(){
	infoCHeight = 0;
	infoEHeight = Math.ceil(document.getElementById('memberInfoContainer').clientHeight);
	document.getElementById('memberInfoContainer').style.height=infoCHeight+'px';
	infoTimer = window.setInterval(resizeInfoBar,10);
}
function resizeInfoBar(){
	if(delayTimer==50){
		if(infoCHeight==infoEHeight){
			clearInterval(infoTimer);
		} else {
			infoCHeight++;
			document.getElementById('memberInfoContainer').style.height=infoCHeight+'px';
		}
	} else {
		delayTimer++;	
	}
}
