/////////////////////////////////////////////
//cronAnimate - functions by crondesign 2009 
/********************************************
CONTENTS:
fadeTo(id, opacEnd, millisec)  					//fades from current opacity to a target opacity
fadeToggle(id, millisec, noscale) 				//fade in/out & display none
blendimage(divid, imageid, imagefile, millisec) //blend 2 images
scaleTo(objID,targSize,horiz)					//Scale from current size to new size
visToggle(obj,onoff)							//show/hide elements
Tscroll(obj)									//add to element onmouseover to scroll innerHTML
*/


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FADE FUNCTIONS::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function opacity(id, opacStart, opacEnd, millisec) {
	i=0 //counts frames animated
	fps=25; //animation frames per second
	frames=Math.round((millisec/1000)*fps); //number of frames in animation
	step = Math.round((opacEnd-opacStart)/frames); //amount to change each frame
	while(i<frames) {i++;//begin animation:
		setTimeout("changeOpac("+(opacStart+(i*step))+",'"+id+"')",(i*1000/fps));
	}
	setTimeout("changeOpac(" +  opacEnd + ",'" + id + "')",(i*1000/fps));
}

//change the opacity for different browsers:
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if(object.opacity==0){object.display='none';}else{object.display='block';}
}

//toggle on/off fade & display none
function fadeToggle(id, millisec,noscale) {
	if(millisec==null){millisec=300;}
	if(document.getElementById(id).style.opacity == "") {//if unset
		opacity(id, 0, 100, millisec);
	}else if(document.getElementById(id).style.opacity == 0 || document.getElementById(id).style.display=='none') {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

//blend 2 images:
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	//make image transparent
	changeOpac(0, imageid);
	//make new image
	document.getElementById(imageid).src = imagefile;
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

//fades from current opacity to a target opacity:
function fadeTo(id, opacEnd, millisec) {
	if(millisec==null){millisec=300;}
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//RESIZE FUNCTIONS::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//scale from current size to new size:
function scaleTo(objID,targSize,horiz){
	if(horiz==null){horiz=0;}else{horiz=1;}
	dropint=setInterval("rundrop('"+objID+"',"+targSize+","+horiz+")",15);
}

//scale from exact size to new size:
function scale(objID,startSize,targSize,horiz){
	if(horiz==null){
		document.getElementById(objID).style.height=startSize+'px';
	}else{
		document.getElementById(objID).style.width=startSize+'px';
	}
	scaleTo(objID,targSize,horiz)
}

//run scaling on interval:
function rundrop(objID,targSize,horiz){
	obj=document.getElementById(objID);
	currentSize=(horiz ? obj.clientWidth : obj.clientHeight);
	newSize=currentSize+(targSize-currentSize)/10;
	if(Math.round(newSize)==targSize){//end
		clearInterval(dropint);
	}
	if (horiz){obj.style.width = newSize+'px';}
	else{obj.style.height = newSize+'px';}
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//USABILITY FUNCTIONS::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//turn on/off elements:
function visToggle(obj,onoff){
	if(onoff==null){//Toggle display:
		document.getElementById(obj).style.display = (document.getElementById(obj).style.display == 'none') ? 'block' : 'none';
	}else if(onoff){//Make visible: 
		document.getElementById(obj).style.display = 'block';
	}else{//Make invisible:
		document.getElementById(obj).style.display = 'none';
	}
}

//Scroll long title on rollover:
Tscroll_pos=1;Tscroll_obj=0;Tscroll_length=0;Tscroll_txt=0;Tscroll_int="";Tscroll_Origtxt=0;

function Tscroll(obj,txt){
	if(txt==null){txt=obj.innerHTML;}
	fontSizeOffset=getFontSize(obj);
	//check if scroll is needed by guessing at text width:
	maxChars=obj.offsetWidth/fontSizeOffset
	if(txt.length<maxChars){return}
	//startscroll:
	Tscroll_pos=0
	Tscroll_obj=obj
	Tscroll_Origtxt=Tscroll_obj.innerHTML
	Tscroll_txt=((txt+" ... ").split("").join("<wbr>"));
	Tscroll_length=Tscroll_txt.length
	Tscroll_int=setInterval(runTitleScroll,100)
	//setmouseOut:
	obj.onmouseout=endTscroll;
	obj.onmousedown=function(){top.right.location.href=obj.href;}
}
function getFontSize(obj){
	var theNewParagraph = document.createElement('span');
	var theTextOfTheParagraph = document.createTextNode('o'); //average char width
	theNewParagraph.appendChild(theTextOfTheParagraph);
	theNewParagraph.setAttribute('id',"getFontSizeTempBox");
	obj.appendChild(theNewParagraph);
	s=document.getElementById('getFontSizeTempBox').offsetWidth
	obj.removeChild(theNewParagraph);
	return s;
}
function endTscroll(){
	Tscroll_length=0
	Tscroll_txt=0
	Tscroll_obj.innerHTML=Tscroll_Origtxt
	Tscroll_obj=0
	clearTimeout(Tscroll_int)
}
function runTitleScroll() {
	newtitle=Tscroll_txt.substring(Tscroll_pos, Tscroll_length) + Tscroll_txt.substring(0, Tscroll_pos)
	Tscroll_obj.innerHTML=newtitle
	Tscroll_pos+=6
	if (Tscroll_pos>=Tscroll_length+6) {Tscroll_pos=0;}
}