
/**
 * Border color animation script for the BonusThemes.com Corez Template
 *
 * @package bt_corez
 * @version 1.0
 * @copyright BonusThemes.com 2008
 * @link http://www.bonusthemes.com/goto/bt_corez
 */

function BorderCell(aa){this.iname=typeof aa.iname!='string'?'':aa.iname;if(this.iname==''){alert('Error: Missing instance name for BorderCell constructor');return;}
this.anim_interval=typeof aa.anim_interval!='number'?2:aa.anim_interval;this.climb_step=typeof aa.climb_step!='number'?2:aa.climb_step;if(this.climb_step<1)this.climb_step=1;else if(this.climb_step>100)this.climb_step=100;this.hover_step=typeof aa.hover_step!='number'?2:aa.hover_step;if(this.hover_step<1)this.hover_step=1;else if(this.hover_step>100)this.hover_step=100;if(typeof aa.norm_color=='string'){var m=aa.norm_color.match(/^\s*#?([0-9a-f]{6})\s*$/i);if(m){this.norm_color={r:parseInt(m[1].substr(0,2),16),g:parseInt(m[1].substr(2,2),16),b:parseInt(m[1].substr(4,2),16)};}
else{alert('Error: Invalid normal color for BorderCell constructor');return;}}
else{alert('Error: Missing normal color for BorderCell constructor');return;}
if(typeof aa.hover1_color=='string'){var m=aa.hover1_color.match(/^\s*#?([0-9a-f]{6})\s*$/i);if(m){this.hover1_color={r:parseInt(m[1].substr(0,2),16),g:parseInt(m[1].substr(2,2),16),b:parseInt(m[1].substr(4,2),16)};}
else{alert('Error: Invalid hover1 color for BorderCell constructor');return;}}
else{alert('Error: Missing hover1 color for BorderCell constructor');return;}
if(typeof aa.hover2_color=='string'){var m=aa.hover2_color.match(/^\s*#?([0-9a-f]{6})\s*$/i);if(m){this.hover2_color={r:parseInt(m[1].substr(0,2),16),g:parseInt(m[1].substr(2,2),16),b:parseInt(m[1].substr(4,2),16)};}
else{alert('Error: Invalid hover2 color for BorderCell constructor');return;}}
else{alert('Error: Missing hover2 color for BorderCell constructor');return;}
this.climb_face1=new BorderCellFace(this.norm_color.b,this.norm_color.r,this.hover1_color.b,this.hover1_color.r);this.climb_face2=new BorderCellFace(this.norm_color.g,this.norm_color.r,this.hover1_color.g,this.hover1_color.r);this.hover_face1=new BorderCellFace(this.hover1_color.b,this.hover1_color.r,this.hover2_color.b,this.hover2_color.r);this.hover_face2=new BorderCellFace(this.hover1_color.g,this.hover1_color.r,this.hover2_color.g,this.hover2_color.r);this.state=0;this.progress=0;this.step=0;this.timer=0;this.wdg=document.getElementById(this.iname);this.wdg.onmouseover=function(e){document['brdcells'][this.id].h_mouseover(e);}
this.wdg.onmouseout=function(e){document['brdcells'][this.id].h_mouseout(e);}}
BorderCell.prototype.hex2=function(i){var ba=i.toString(16);return(ba.length==1?'0':'')+ba;}
BorderCell.prototype.animate=function(){if(this.timer!=0)clearTimeout(this.timer);if(this.state==0)this.step=0;if(this.state==1&&this.step>0&&this.progress==100){this.state=2;this.progress=-this.hover_step;this.step=this.hover_step;}
if(this.state==1&&this.step<0&&this.progress==0){this.state=0;this.step=0;}
if(this.state==2&&this.step>0&&this.progress==100){this.step=-this.hover_step;}
if(this.state==2&&this.step<0&&this.progress==0){this.step=this.hover_step;}
if(this.state>0){this.progress+=this.step;if(this.progress>=100)this.progress=100;else if(this.progress<=0)this.progress=0;if(this.state==1){var r1=this.climb_face1.step(this.progress);var r2=this.climb_face2.step(this.progress);}
if(this.state==2){var r1=this.hover_face1.step(this.progress);var r2=this.hover_face2.step(this.progress);}
this.wdg.style.borderColor='#'+this.hex2(r2.y)+this.hex2(r2.x)+this.hex2(r1.x);}
this.timer=this.state==0?0:setTimeout('document["brdcells"]["'+this.iname+'"].animate()',this.anim_interval);}
BorderCell.prototype.isMouseEnterOrLeave=function(ca,e){if(e.type!='mouseout'&&e.type!='mouseover')return false;var da=e.relatedTarget||(e.type=='mouseout'?e.toElement:e.fromElement);while(da&&da!=ca)da=da.parentNode;return da!=ca;}
BorderCell.prototype.h_mouseover=function(e){if(this.isMouseEnterOrLeave(this.wdg,e||window.event)){if(this.state==0){this.state=1;this.progress=0;this.step=this.climb_step;}
this.animate();}}
BorderCell.prototype.h_mouseout=function(e){if(this.isMouseEnterOrLeave(this.wdg,e||window.event)){if(this.state>0){if(this.state>1)this.progress=100;this.state=1;this.step=-this.climb_step;}
this.animate();}}
function BorderCellFace(x1,y1,x2,y2){this.x1=x1;this.x2=x2;this.y1=y1;this.y2=y2;this.dist=x2-x1;if(this.dist!=0){this.b=(y1-y2)/(x1-x2);this.a=y1-this.b*x1;}}
BorderCellFace.prototype.step=function(ea){var x,y;if(this.dist==0){x=this.x1;y=this.y1+(this.y2-this.y1)*ea/100;}
else{x=this.x1+this.dist*ea/100;y=this.a+this.b*x;}
return{x:Math.round(x),y:Math.round(y)}}