Ext.onReady(function () {
	var task = {
            run: function () {
                Ext.fly('resume').frame();
            },
            interval: (10 * 1000)
        };

    (Ext.isMac) && (Ext.getBody().addClass('mac-font'));
    Ext.select('.tab-buttons-panel').on(
		'click',
	    function (e, t) {
			var n = t.id.slice(-1);
	        Ext.fly(t).radioClass('tab-show');
	        Ext.get('content' + n).radioClass('tab-content-show');
			(Ext.isIE7) && (Ext.fly('content' + n).setStyle({ 'margin-top': '-27px' }));
	    },
	    null,
        { delegate: 'li' }
    );
	Ext.select('.tab-content-panel').setHeight(Ext.fly('main-content').getHeight() - 100);
	if (Ext.isIE)
	{
		Ext.select('h1').setStyle({ 'filter': "progid:DXImageTransform.Microsoft.dropShadow(OffX=4, OffY=4, Color='black', Positive='true')" });
        Ext.select('#main-sidebar p').setStyle({ 'filter': "progid:DXImageTransform.Microsoft.dropShadow(OffX=1, OffY=1, Color='black', Positive='true')" });
        if (Ext.isIE7)
		{
			Ext.getBody().setStyle({ 'margin-top': '72px' });
			Ext.fly('content1').setStyle({ 'margin-top': '-27px' });
			Ext.fly('me').setStyle({ 'margin-top': '0' });
		}
	} else {
		var totalSparks = 40,
            sparks = [];

		while (totalSparks--) {
			sparks[totalSparks] = new Spark();
		}	
	}
    (new Ext.util.TaskRunner()).start(task);
	Ext.fly('vid').on('click', function () { TINY.box.show('vid.html', 1, 640, 640, 1) });
});

var Spark = function () {
        this.b = 'images/';
        this.s = [ 'spark.png', 'spark2.png', 'spark3.png', 'spark4.png' ];
        this.i = this.s[this.random(this.s.length)];
        this.f = this.b + this.i;
        this.n = document.createElement('img');
        this.newPoint().init().newSpeed().newPoint().goFly();
    };

Spark.prototype.init = function () {
	Ext.fly(this.n).set({ 'src': this.f }).position('absolute', this.random(20), this.x, this.y);
	Ext.getBody().appendChild(this.n);

	return this;
};

Spark.prototype.goFly = function () {
	var self = this;

	Ext.fly(this.n).animate({ left: { to: this.x }, top: { to: this.y } },
		this.speed,
		function () {
			self.newSpeed().newPoint().goFly();
		},
		'easeBoth',
		'motion');
};

Spark.prototype.newSpeed = function () {
	this.speed = (this.random(20) + 5);

	return this;
};

Spark.prototype.newPoint = function () {
	this.x = this.random(window.innerWidth - 200);
	this.y = this.random(150);

	return this;
};

Spark.prototype.random = function (max) {
	return Math.ceil(Math.random() * max) - 1;
};
