/** 
 * Copyright (c) 2009 Sylvain Gougouzian (sylvain@gougouzian.fr)
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 * GNU GPL (http://www.gnu.org/licenses/gpl.html) licensed.
 *
 * jQuery Weather Animated by Sylvain Gougouzian http://sylvain.gougouzian.fr
 * RSS from weather.yahoo.com // transforming into json on gougouzian.fr
 *
 * Version: 2.2
 *
 * Requires:
 *   	jQuery 1.3+ 	// http://www.jquery.com
 * 		Joose			// http://groups.google.com/group/joose-js
 * 		soundmanager 2	// http://www.schillmania.com/content/projects/soundmanager2/
 *
 * Compatible :
 * 		Internet Explorer 7+
 * 		Firefox 3+
 * 		Safari 3+
 * 		Opera 9+
 * 		Chrome 0.9+
 */
jQuery(function($){
    /**
     * Variable weather
     */
    var weather;
    var weather_options;
    var weather_id;
    
    var w_time;
    var w_rss;
    
    var w_type;
    var w_nb;
    var w_size;
    var w_speed;
    
    var tomorrow = {
        'fr-FR': 'demain',
        'en-US': 'tomorrow'
    };
    var today = {
        'fr-FR': 'aujourd\'hui',
        'en-US': 'today'
    };
    
    /**
     * Function weather
     * @param options
     * @return true
     */
    $.fn.weather = function(options){
        var opts = $.extend({}, $.fn.weather.defaults, options);
        this.each(function(){
            weather_options = $.meta ? $.extend({}, opts, weather.data()) : opts;
            weather = $(this);
            weather_id = weather.attr('id');
            weather.empty();
            $.getJSON('http://www.gougouzian.fr/weather/yahoo_json.php5?town=' + weather_options.town + '&unit=' + weather_options.unit + '&jsoncallback=?', function(json){
                w_time = json.w_time;
                w_time = w_time.substring(20, 22) + ":" + w_time.substring(23, 25);
                w_rss = json;
                
                if (weather_options.tomorrow) {
                    w_rss.w_condition_code = weather_options.cond;
                }
				
				if (weather_options.sound) {
					soundManager.flashVersion = (window.location.toString().match(/#flash8/i)?8:9);
					soundManager.url = weather_options.path;
					soundManager.debugMode = false;
					soundManager.consoleOnly = false;
				}
				
                init();
                
            });
        });
    };
    
    function init(){
        weather.css({
            'overflow': 'hidden'
        });
        
        $.ajax({
            url: weather_options.path + 'weather.xml',
            dataType: 'xml',
            async: false,
            success: function(xml){
                w_condition_text = $('weather#' + w_rss.w_condition_code + ' name[lang=' + weather_options.lang + ']', xml).text();
                w_type = $('weather#' + w_rss.w_condition_code + ' type', xml).text();
                w_nb = $('weather#' + w_rss.w_condition_code + ' nb', xml).text();
                w_size = $('weather#' + w_rss.w_condition_code + ' size', xml).text();
                w_speed = $('weather#' + w_rss.w_condition_code + ' speed', xml).text();
            },
            error: function(xml, textStatus){
                alert(textStatus);
            }
        });
        
        makeWeather();
        
        if (weather_options.info) {
            var text = "";
			if (weather_options.tomorrow) {
				text = w_rss.w_city + " | " + 
				w_condition_text;
			}
			else {
				text = w_rss.w_city + " | " + 
				w_condition_text + " | " + 
				w_rss.w_temperature + " " + 
				w_rss.w_temperature_unit + " | " + 
				w_rss.w_wind_speed + " " + 
				w_rss.w_wind_speed_unit;
			}
			
			$('<div id="' + weather_id + '_temp"></div>').css({
                'width': '100%',
                'text-align': 'right',
                'font-family': 'Verdana, Arial, sans-serif',
                'font-size': '10px',
                'top': '0px',
                'z-index': '2',
                'display': 'block',
                'position': 'absolute'
            }).text(text).appendTo(weather);
        }
        if (weather_options.previsions) {
            $('<div id="' + weather_id + '_previsions"></div>').css({
                'width': '100%',
                'text-align': 'right',
                'font-family': 'Verdana, Arial, sans-serif',
                'font-size': '10px',
                'top': (parseInt(weather.height()) - 12) + 'px',
                'z-index': '2',
                'display': 'block',
                'position': 'absolute'
            }).appendTo(weather);
            if (!weather_options.tomorrow) {
                $('div#' + weather_id + '_previsions').html('<a id="' + weather.attr('id') + '_previsions_link" href="#">' + tomorrow[weather_options.lang] + '</a>');
                $('a#' + weather_id + '_previsions_link').click(function(){
                    weather.weather({
                        path: weather_options.path,
                        town: weather_options.town,
                        unit: weather_options.unit,
                        lang: weather_options.lang,
                        info: weather_options.info,
                        animate: weather_options.animate,
                        townselect: weather_options.townselect,
                        previsions: weather_options.previsions,
                        tomorrow: true,
                        cond:  w_rss.w_tomorrow_condition_code
                     });
                });
            }
            else {
                $('div#' + weather_id + '_previsions').html('<a id="' + weather.attr('id') + '_previsions_link" href="#">' + today[weather_options.lang] + '</a>');
                $('a#' + weather_id + '_previsions_link').click(function(){
                    weather.weather({
                        path: weather_options.path,
                        town: weather_options.town,
                        unit: weather_options.unit,
                        lang: weather_options.lang,
                        info: weather_options.info,
                        animate: weather_options.animate,
                        townselect: weather_options.townselect,
                        previsions: weather_options.previsions,
                        init: true,
                        tomorrow: false,
                       	cond: w_rss.w_condition_code
                    });
                });
            }
            $('a#' + weather_id + '_previsions_link').css('text-decoration', 'none');
        }
        makeDayNight();
        
    }
    
    /**
     * Function makeDayNight
     */
    function makeDayNight(){
        var sunrise = transformTime(w_rss.w_sunrise);
        var sunrise_hour = parseInt(sunrise[0]);
        var sunrise_minutes = parseInt(sunrise[1]);
        var sunset = transformTime(w_rss.w_sunset);
        var sunset_hour = parseInt(sunset[0]);
        var sunset_minutes = parseInt(sunset[1]);
        var time_hour = parseInt(w_time.substring(0, 2));
        var time_minutes = parseInt(w_time.substring(3, 5));
        var daynight = "";
        if (time_hour < sunrise_hour) {
            daynight = "night";
        }
        else 
            if (time_hour == sunrise_hour) {
                if (time_minutes < sunrise_minutes) {
                    daynight = "night";
                }
                else 
                    if (time_minutes >= sunrise_minutes) {
                        daynight = "day";
                    }
            }
            else {
                if (time_hour < sunset_hour) {
                    daynight = "day";
                }
                else 
                    if (time_hour == sunset_hour) {
                        if (time_minutes < sunset_minutes) {
                            daynight = "day";
                        }
                        else {
                            daynight = "night";
                        }
                    }
                    else {
                        daynight = "night";
                    }
            }
        
        weather.css({
            'background-image': 'url("' + weather_options.path + 'img/grass_' + daynight + '.png")',
            'background-repeat': 'repeat-x',
            'background-position': 'bottom',
            'border-bottom': '1px solid #314F00',
            'margin-bottom': '1px',
            'text-align': 'left',
            'position': 'relative'
        });
        
        switch (w_type) {
            default:
                weather.css({
                    'background-color': '#FFFFFF',
                    'color': '#000000'
                });
                $('a', weather).css('color', '#000000');
                break;
            case "clear":
            case "cloud":
            case "cloud_rain":
                if (daynight == "day") {
                    weather.css({
                        'background-color': '#B3DEEF',
                        'color': '#000000'
                    });
                    $('a', weather).css('color', '#000000');
                }
                else {
                    weather.css({
                        'background-color': '#003D6F',
                        'color': '#FFFFFF'
                    });
                    $('a', weather).css('color', '#FFFFFF');
                }
                break;
            case "fog":
                if (daynight == "day") {
                    weather.css({
                        'background-color': '#DCF0F8',
                        'color': '#000000'
                    });
                    $('a', weather).css('color', '#000000');
                }
                else {
                    weather.css({
                        'background-color': '#003D6F',
                        'color': '#FFFFFF'
                    });
                    $('a', weather).css('color', '#FFFFFF');
                }
                break;
            case "hail":
            case "rain":
            case "snow":
            case "snow_hail":
            case "snow_rain":
            case "rain_hail":
            case "rain_thunder":
            case "thunder":
                if (daynight == "day") {
                    weather.css({
                        'background-color': '#DFDFDF',
                        'color': '#000000'
                    });
                    $('a', weather).css('color', '#000000');
                }
                else {
                    weather.css({
                        'background-color': '#3B425F',
                        'color': '#FFFFFF'
                    });
                    $('a', weather).css('color', '#FFFFFF');
                }
                break;
                
        }
        if (w_type == 'fog') {
            $('<div id="' + weather_id + '_astr"><img src="' + weather_options.path + 'img/' + daynight + '_fog.png" alt="" /></div>').appendTo(weather);
        }
        else 
            if (w_type == 'rain' || w_type == 'hail') {
                $('<div id="' + weather_id + '_astr"><img src="' + weather_options.path + 'img/' + daynight + '_cloud.png" alt="" /></div>').appendTo(weather);
            }
            else {
                $('<div id="' + weather_id + '_astr"><img src="' + weather_options.path + 'img/' + daynight + '.png" alt="" /></div>').appendTo(weather);
            }
        
        var doc_width = weather.width() - 40;
        var doc_height = weather.height() - 40;
        
        var a = (-4 * doc_height) / (doc_width * doc_width);
        var b = (4 * doc_height) / doc_width;
        var c = 0;
        
        var midday = 12 * 60;
        
        var timestamp = 60 * parseInt(time_hour) + parseInt(time_minutes);
        
        var x = parseInt((timestamp / midday) * (doc_width / 2));
        var y = doc_height - ((a * (x * x)) + (b * x) + c);
        
        $('div#' + weather_id + '_astr').css({
            'position': 'absolute',
            'left': parseInt(x) + 'px',
            'top': parseInt(y) + 'px'
        });
        
        return true;
    }
    
    function makeWeather(){
        var w_weather_cloud;
        var w_weather_fog;
        var w_weather_rain;
        var w_weather_snow;
        var w_weather_hail;
        var w_weather_thunder;
        
		if (weather_options.tomorrow) {
			w_rss.w_wind_speed = 0;
		}
		
		if (weather_options.sound) {
			if (parseInt(w_rss.w_wind_speed) > 20) {
				soundManager.play('wind', weather_options.path + 'mp3/wind.mp3');
			}
		}
		
        if (w_type.indexOf('cloud') >= 0) {
            var clouds = new Clouds({
                id: weather_id + '_cloud',
                path: weather_options.path + 'img',
                nb: w_nb,
                wind_speed: w_rss.w_wind_speed,
                doc_height: weather.height(),
                doc_width: weather.width()
            });
            weather.append(clouds.init());
            if (weather_options.animate) 
                setInterval(function(){
                    clouds.display();
                }, 40);
			if (weather_options.sound) {
				soundManager.play('clear', weather_options.path + 'mp3/clear.mp3');
			}
        }
        
        if (w_type.indexOf('fog') >= 0) {
            var fogs = new Clouds({
                id: weather_id + '_fog',
                path: weather_options.path + 'img',
                nb: w_nb,
                type: 'fog',
                wind_speed: w_rss.w_wind_speed,
                doc_height: weather.height(),
                doc_width: weather.width()
            });
            weather.append(fogs.init());
            if (weather_options.animate) 
                setInterval(function(){
                    fogs.display();
                }, 40);
        }
        if (w_type.indexOf('rain') >= 0) {
            var rains = new Drops({
                id: weather_id + '_rain',
                nb: w_nb,
                speed: w_speed,
                size: w_size,
                wind_speed: w_rss.w_wind_speed,
                doc_height: weather.height(),
                doc_width: weather.width()
            });
            weather.append(rains.init());
            if (weather_options.animate) 
                setInterval(function(){
                    rains.display();
                }, 40);
			if (weather_options.sound) {
				soundManager.play('rain', weather_options.path + 'mp3/rain.mp3');
			}
        }
        if (w_type.indexOf('hail') >= 0) {
            var rains = new Drops({
                id: weather_id + '_hail',
                nb: w_nb,
                speed: w_speed,
                size: w_size,
                type: 'hail',
                wind_speed: w_rss.w_wind_speed,
                doc_height: weather.height(),
                doc_width: weather.width()
            });
            weather.append(rains.init());
            if (weather_options.animate) 
                setInterval(function(){
                    rains.display();
                }, 40);
        }
        if (w_type.indexOf('snow') >= 0) {
            var flakes = new Flakes({
                id: weather_id + '_snow',
                nb: w_nb,
                speed: w_speed,
                size: w_size,
                wind_speed: w_rss.w_wind_speed,
                doc_height: weather.height(),
                doc_width: weather.width()
            });
            weather.append(flakes.init());
            if (weather_options.animate) 
                setInterval(function(){
                    flakes.display();
                }, 40);
        }
        if (w_type.indexOf('thunder') >= 0) {
            var th = new Thunder({
                id: weather_id + '_thunder',
                size: w_size,
				path: weather_options.path,
                sound : weather_options.sound,
                max_width: weather.width(),
                max_height: (weather.height() - 10)
            });
            weather.append(th.init());
            th.strike();
            if (weather_options.animate) 
                setInterval(function(){
                    th.strike();
                }, 2000);
        }
    }
    
    
    /**
     * Function transformTime
     * transform a 12 hours clock in a 24 hours clock
     */
    function transformTime(time){
        var hour = time.substring(0, time.indexOf(':'));
        var minuts = time.substring(time.indexOf(':') + 1);
        minuts = minuts.substring(0, 2);
        var AP = time.substring(time.indexOf('m') - 1);
        if (hour == "12") {
            if (AP == "pm") {
                hour = "0";
            }
            else {
                hour = "-12";
            }
        }
        if (AP == "pm") {
            hour = parseInt(hour) + 12;
        }
        return new Array(hour, minuts);
    }
    
    // default  
    $.fn.weather.defaults = {
        path: './',
        
        town: 'FRXX0055', // Lyon
        unit: 'c', // c or f
        lang: 'fr-FR',
        
        info: false,
        animate: false,
        previsions: false,
        sound: false,
        townselect: false,
        
        tomorrow: false,
        
        cond: -1
    };
});

Class("Clouds", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        nb: {
            is: "rw",
            init: 0
        },
        clouds: {
            is: "ro",
            init: new Array()
        },
        path: {
            is: "rw"
        },
        type: {
            is: "rw",
            init: "cloud"
        },
        wind_speed: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        }
    },
    methods: {
        init: function(){
            var html = "";
            for (var i = 0; i < this.nb; i++) {
                this.clouds[i] = new Cloud({
                    id: this.id + '_' + i,
                    path: this.path,
                    type: this.type,
                    wind_speed: this.wind_speed,
                    doc_height: this.doc_height,
                    doc_width: this.doc_width
                });
                html += this.clouds[i].init();
            }
            return html;
        },
        display: function(){
            for (var i = 0; i < this.nb; i++) {
                this.clouds[i].move();
            }
        }
    }
});

Class("Cloud", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        pos_x: {
            is: "rw",
            init: 0
        },
        pos_y: {
            is: "rw",
            init: 0
        },
        path: {
            is: "rw"
        },
        type: {
            is: "rw"
        },
        wind_speed: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        }
    },
    methods: {
        init: function(){
            this.pos_x = Math.round(Math.random() * Math.round(this.doc_width - 40));
            this.pos_y = Math.round(Math.random() * Math.round(this.doc_height - 40));
            return '<div id="' + this.id + '" style="position:absolute; top:' + parseInt(this.pos_y) + 'px; left:' + parseInt(this.pos_x) + 'px; z-index:3;"><img src="' + this.path + '/' + this.type + '.png" alt="" /></div>';
        },
        move: function(){
            if ((parseInt(this.pos_x) + 40 + parseInt(this.wind_speed)) > parseInt(this.doc_width)) {
                this.pos_x = Math.round(Math.random() * Math.round(this.doc_width - 40));
                this.pos_y = Math.round(Math.random() * Math.round(this.doc_height - 40));
            }
            else {
                this.pos_x = parseInt(this.pos_x) + parseInt(this.wind_speed / 4);
            }
            jQuery('#' + this.id).css({
                top: this.pos_y,
                left: this.pos_x
            });
        }
    }
});

Class("Drops", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        nb: {
            is: "rw",
            init: 0
        },
        drops: {
            is: "ro",
            init: new Array()
        },
        type: {
            is: "rw",
            init: "rain"
        },
        wind_speed: {
            is: "rw"
        },
        speed: {
            is: "rw"
        },
        size: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        }
    },
    methods: {
        init: function(){
            var html = "";
            for (var i = 0; i < (this.nb * 2); i++) {
                this.drops[i] = new Drop({
                    id: this.id + '_' + i,
                    type: this.type,
                    wind_speed: this.wind_speed,
                    speed: this.speed,
                    size: this.size,
                    doc_height: this.doc_height,
                    doc_width: this.doc_width
                });
                html += this.drops[i].init();
            }
            return html;
        },
        display: function(){
            for (var i = 0; i < (this.nb * 2); i++) {
                this.drops[i].move();
            }
        }
    }
});

Class("Drop", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        pos_x: {
            is: "rw",
            init: 0
        },
        pos_y: {
            is: "rw",
            init: 0
        },
        type: {
            is: "rw"
        },
        wind_speed: {
            is: "rw"
        },
        speed: {
            is: "rw"
        },
        size: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        },
        color: {
            is: "rw"
        },
        colorSet: {
            is: "ro",
            init: new Array("555555", "888888", "666666", "999999", "777777", "aaaaaa")
        }
    },
    methods: {
        init: function(){
            this.pos_x = Math.round(Math.random() * (this.doc_width - 50));
            this.pos_y = Math.round(Math.random() * Math.round(this.doc_height - 50));
            this.color = this.colorSet[Math.round(Math.random() * 2)];
            if (this.type == "rain") {
                return '<div id="' + this.id + '" style="position:absolute;' +
                'width:' +
                Math.ceil(this.size) +
                'px;' +
                'height:' +
                Math.ceil(this.size * 8) +
                'px;' +
                'top' +
                this.pos_y +
                'px;' +
                'left:' +
                this.pos_x +
                'px;' +
                'z-index:3;' +
                'background-color:#' +
                this.color +
                ';"></div>';
            }
            else {
                return '<div id="' + this.id + '" style="position:absolute;' +
                'width:4px;' +
                'height:4px;' +
                'font-family:Courier New, serif;' +
                'top:' +
                this.pos_y +
                'px;' +
                'left:' +
                this.pos_x +
                'px;' +
                'z-index:3;' +
                'font-size:' +
                parseInt(28 + (8 * (this.size - 1))) +
                'px;' +
                'color:#' +
                this.color +
                '">.</div>';
            }
        },
        move: function(){
            if (((parseInt(this.pos_y) + 10) > parseInt(this.doc_height)) || ((parseInt(this.pos_x) + 10) > parseInt(this.doc_width))) {
                this.pos_x = Math.round(Math.random() * (this.doc_width - 10));
                this.pos_y = Math.round(Math.random() * Math.round(this.doc_height - 50));
            }
            else {
                this.pos_x = parseInt((this.wind_speed * this.speed) / 5) + parseInt(this.pos_x);
                this.pos_y = parseInt(this.pos_y) + parseInt((this.wind_speed * this.speed) / 5) + 4;
            }
            this.color = this.colorSet[Math.round(Math.random() * this.colorSet.length)];
            jQuery('#' + this.id).css({
                top: this.pos_y,
                left: this.pos_x
            });
            if (this.type == "rain") {
                jQuery('#' + this.id).css({
                    'background-color': '#' + this.color
                });
            }
            else {
                jQuery('#' + this.id).css({
                    color: '#' + this.color
                });
            }
        }
    }
});

Class("Flakes", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        nb: {
            is: "rw",
            init: 0
        },
        flakes: {
            is: "ro",
            init: new Array()
        },
        wind_speed: {
            is: "rw"
        },
        speed: {
            is: "rw"
        },
        size: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        }
    },
    methods: {
        init: function(){
            var html = "";
            for (var i = 0; i < (this.nb * 2); i++) {
                this.flakes[i] = new Flake({
                    id: this.id + '_' + i,
                    type: this.type,
                    wind_speed: this.wind_speed,
                    speed: this.speed,
                    size: this.size,
                    doc_height: this.doc_height,
                    doc_width: this.doc_width
                });
                html += this.flakes[i].init();
            }
            return html;
        },
        display: function(){
            for (var i = 0; i < (this.nb * 2); i++) {
                this.flakes[i].move();
            }
        }
    }
});

Class("Flake", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        pos_x: {
            is: "rw",
            init: 0
        },
        pos_y: {
            is: "rw",
            init: 0
        },
        type: {
            is: "rw"
        },
        wind_speed: {
            is: "rw"
        },
        speed: {
            is: "rw"
        },
        size: {
            is: "rw"
        },
        doc_height: {
            is: "rw"
        },
        doc_width: {
            is: "rw"
        },
        color: {
            is: "rw"
        },
        amplitude: {
            is: "rw"
        },
        stx: {
            is: "rw"
        },
        sty: {
            is: "rw"
        },
        dx: {
            is: "rw"
        },
        colorSet: {
            is: "ro",
            init: new Array("ffffff", "f8f8f8", "f0f0f0")
        }
    },
    methods: {
        init: function(){
            this.pos_x = Math.round(Math.random() * (this.doc_width - 50));
            this.pos_y = Math.round(Math.random() * Math.round(this.doc_height) - 50);
            this.amplitude = Math.random() * 20 * Math.round(this.wind_speed) + this.speed;
            this.color = this.colorSet[Math.round(Math.random() * 2)];
            this.stx = 0.02 + Math.random() / 10;
            this.sty = 0.7 + Math.random();
            this.dx = 0;
            this.size = Math.round(Math.random() * (this.size - 1)) + 1;
            return '<div id="' + this.id + '" style="position:absolute;' +
            'width:4px;' +
            'height:4px;' +
            'font-family:Courier New, serif;' +
            'top:' +
            this.pos_y +
            'px;' +
            'left' +
            this.pos_x +
            'px;' +
            'z-index:3;' +
            'font-size:' +
            parseInt(28 + (8 * (this.size - 1))) +
            'px;' +
            'color:#' +
            this.color +
            '">.</div>';
            
        },
        move: function(){
            this.pos_y += this.sty;
            if (parseInt(this.pos_y) > parseInt(this.doc_height - 40)) {
                this.pos_x = Math.random() * (this.doc_width - this.amplitude - 30);
                this.pos_y = 0;
                this.stx = 0.02 + Math.random() / 10;
                this.sty = 0.7 + Math.random() * this.speed;
                this.color = this.colorSet[Math.round(Math.random() * this.colorSet.length)];
            }
            this.dx += this.stx;
            this.color = this.colorSet[Math.round(Math.random() * this.colorSet.length)];
            this.size = Math.round(Math.random() * (this.size - 1)) + 1;
            this.pos_x = this.pos_x + this.amplitude * Math.sin(this.dx);
            jQuery('#' + this.id).css({
                top: this.pos_y + 'px',
                left: this.pos_x + 'px',
                color: '#' + this.color
            });
        }
    }
});

Class("Thunder", {
    has: {
        id: {
            is: "rw",
            init: ""
        },
        color: {
            is: "rw",
            init: "#FFFFFF"
        },
        width: {
            is: "rw",
            init: 1
        },
        max_width: {
            is: "rw"
        },
        max_height: {
            is: "ro"
        },
		path : {
			is: "rw"
		},
		sound : {
			is: "rw"
		}
    },
    methods: {
        init: function(){
            return '<span id="' + this.id + '"></span>';
        },
        strike: function(){
            $('#' + this.id).empty();
            if (Math.random() < 0.66) {
                if (this.sound) {
					if (Math.random() < 0.33)
						soundManager.play('thunder' + parseInt(1000*Math.random()), this.path + 'mp3/thunder.mp3');
				}
				var x = Math.round((Math.floor(Math.random() * this.max_width) - 30));
                for (var y = 0; y < this.max_height; y++) {
                    if (Math.round(Math.random()) == 0) {
                        x++;
                    }
                    else {
                        x--;
                    }
                    $('<div id="' + this.id + '_' + y + '" style="position:absolute;top:' + y + 'px;left:' + x + 'px;height:' + this.width + 'px;width:' + this.width + 'px;background-color:' + this.color + ';"></div>').appendTo($('#' + this.id));
                }
                setTimeout(function(){
                    $('#' + this.id).empty();
                }, 100);
            }
        }
    }
});

