// CREDITS:
// TextMagnet by Urs Dudli and Peter Gehrig 
// Copyright (c) 2000 Peter Gehrig and Urs Dudli. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// 2/24/2000

// CONFIGURATION:
// 1. 	Copy and paste the two script-blocks into your HTML-file:
// 		Put the first script-block inside the head-section of your HTML-file.
//		Put the second script-block right at the end of the 
//		body-section of your HTML-file.
// 2.	Copy and paste the style-sheet into head-section of your HTML-file.
//		Configure font, font-size, font-color, background-color etc.
// 3. 	Insert 'onLoad="changetext()"' into the body tag.
// 4. 	Configure the variables below:
		
// The width of your textbox (pixels). 
var textwidth=300

// The height of your textbox (pixels). 
var textheight=150

// Your messages. You may add as many messages as you like.
var message=new Array()
message[0]="Welcome To 3G Chimney<br><br>The Ultimate Chimney Company"

// Final horizontal position of the image: distance to the left margin of the window
// If you set this to '-1' the textbox will centered in the middle of the browser-window
var x_finalpos=171

// Final vertical position of the image: distance to the top margin of the window
// If you set this to '-1' the textbox will centered in the middle of the browser-window
var y_finalpos=229

// Number of sliced cells (the higher this value the slower the script)
var x_slices=6

// Number of sliced rows (the higher this value the slower the script)
var y_slices=1

// Speed of the reassembling effect. More means slower.
var pause=10

// The width and heigth of the zone where the debris of the message are spread (pixels)
var screenwidth=500
var screenheight=300

// Do not change the variables below
var x_step=new Array()
var y_step=new Array()
var x_randompos=0
var y_randompos=0
var i_loop=0
var max_loop=30
var i_text=0
var width_slice=Math.floor(textwidth/x_slices)
var height_slice=Math.floor(textheight/y_slices)
var cliptop=0
var clipbottom=height_slice
var clipleft=0
var clipright=width_slice
var spancounter=0

function initiate() {
	if (x_finalpos==-1) {
		x_finalpos=Math.floor(document.body.clientWidth/2)-Math.floor(textwidth/2)
	}
	if (y_finalpos==-1) {
		y_finalpos=Math.floor(document.body.clientHeight/2)-Math.floor(textheight/2)
	}
	cliptop=0
	clipbottom=height_slice
	clipleft=0
	clipright=width_slice
	i_loop=0
	spancounter=0
    if (document.all) {
 	    for (i=0;i<=y_slices-1;i++) {
			for (ii=0;ii<=x_slices-1;ii++) {
				var thisspan=eval("document.all.span"+spancounter+".style")
				x_randompos=Math.ceil(screenwidth*Math.random())
				y_randompos=Math.ceil(screenheight*Math.random())
				thisspan.posLeft=x_randompos
				thisspan.posTop=y_randompos
                thisspan.clip ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
				clipleft+=width_slice
		        clipright+=width_slice
		        spancounter++
			}
        	clipleft=0
	        clipright=width_slice
	        cliptop+=height_slice
	        clipbottom+=height_slice
		}
   }
   explode_IE()
}

function changetext() {
	spancounter=0
	for (i=0;i<=y_slices-1;i++) {
		for (ii=0;ii<=x_slices-1;ii++) {
			var thisspan=eval("document.all.span"+spancounter+".style")		
			thisspan.posLeft=-5000
			spancounter++
		}
	}
	spancounter=0
	if (i_text>message.length-1) {i_text=0}
	for (i=0;i<=y_slices-1;i++) {
		for (ii=0;ii<=x_slices-1;ii++) {
			var thisinnerspan=eval("span"+spancounter)
    		thisinnerspan.innerHTML=message[i_text]
			spancounter++
		}
	}
	i_text++
	initiate()
}


function explode_IE() {
	spancounter=0
	if (i_loop<=max_loop-1) {
		for (i=0;i<=y_slices-1;i++) {
			for (ii=0;ii<=x_slices-1;ii++) {
				var thisspan=eval("document.all.span"+spancounter+".style")
				x_step[spancounter]=(x_finalpos-thisspan.posLeft)/(max_loop-i_loop)
				y_step[spancounter]=(y_finalpos-thisspan.posTop)/(max_loop-i_loop)		
				thisspan.posLeft+=x_step[spancounter]
				thisspan.posTop+=y_step[spancounter]
				spancounter++
			}
		}
		i_loop++
		var timer=setTimeout("explode_IE()",pause)
	}
	else {
		spancounter=0
		clearTimeout(timer)
		var timer=setTimeout("hidetext()",500)
	}
}

function hidetext()
{
	spancounter=0
	for (i=0;i<=y_slices-1;i++) {
		for (ii=0;ii<=x_slices-1;ii++) {
			var thisspan=eval("document.all.span"+spancounter+".style")
			thisspan.display = 'none';
			spancounter++
		}
	}
    var header = document.getElementById('tdHeader');
	header.style.visibility = 'visible';
}

