/*
 * jDigiClock plugin 2.1
 *
 * http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-digiclock/
 *
 * Copyright (c) 2009 Radoslav Dimov
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


(function ($) {
    $.fn.extend({

        jdigiclock: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'EUR|UK|UK001|SOUTHAMPTON',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };

            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';

                var html = '<div id="plugin_container">';
                html += '<div id="digital_container">';
                html += '<div id="clock"></div>';
                html += '<div id="weather"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData($this);

                var panel_pos = ($('#plugin_container > div').length - 1) * 500;
            });
        }
    });


    $.fn.getData = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;

            $.fn.getWeather(el);

            $.fn.getTime(el);
        });

        setTimeout(function () { $.fn.getData(el) }, $.fn.delay());
    }


    $.fn.delay = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }


    $.fn.getWeather = function (el) {
        el.find('#weather').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather .loading, #forecast_container .loading').hide();
        var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

        el.find('#weather').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
        var weather = '<div id="local"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
        weather += '<div id="temp">' + curr_temp + '</div>';
        el.find('#weather').html(weather);

        $('#reload').click(function () {
            el.find('#weather').html('');
            $.fn.getWeather(el);
        });
    }


    $.fn.getTime = function (el) {
        var old = new Date();
        var now = new Date(el.CurrentDateTime);

        old.setTime(now.getTime() - 60000);

        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours"><div class="line"></div>';
        timeOld += '<div id="hours_bg"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd" class="second_digit" />';
        timeOld += '</div>';

        el.find('#clock').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }


})(jQuery);


//CLOCK 2
(function ($) {
    $.fn.extend({

        jdigiclock1: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'ASI|CN|CH024|SHANGHAI',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };
            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';


                var html = '<div id="plugin_container1">';
                html += '<div id="digital_container1">';
                html += '<div id="clock1"></div>';
                html += '<div id="weather1"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData1($this);


                var panel_pos1 = ($('#plugin_container1 > div').length - 1) * 500;

            });
        }
    });

    $.fn.getData1 = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;

            $.fn.getWeather1(el);
            $.fn.getTime1(el);
        });
        setTimeout(function () { $.fn.getData1(el) }, $.fn.delay());
    }


    $.fn.delay1 = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }

    $.fn.getTime1 = function (el) {
        var old = new Date();
        var now = new Date(el.CurrentDateTime);
        old.setTime(now.getTime() - 60000);


        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours1"><div class="line"></div>';
        timeOld += '<div id="hours_bg1"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd1" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd1" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes1"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm1"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg1"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd1" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd1" class="second_digit" />';
        timeOld += '</div>';
       
        el.find('#clock1').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd1').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd1').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd1').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd1').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd1').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd1').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd1').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd1').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg1 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd1').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd1').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd1').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd1').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd1').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd1').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd1').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd1').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg1 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }

   
   $.fn.getWeather1 = function (el) {
        el.find('#weather1').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container1').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather1 .loading, #forecast_container1 .loading').hide();
            var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

            el.find('#weather1').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
            var weather = '<div id="local1"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
            weather += '<div id="temp1">' + curr_temp + '</div>';
            el.find('#weather1').html(weather);

            $('#reload').click(function () {
                el.find('#weather1').html('');
                $.fn.getWeather1(el);
            });
    }

})(jQuery);



//CLOCK 3
(function ($) {
    $.fn.extend({

        jdigiclock2: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'ASI|TH|TH017|BANGKOK',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };
            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';

                var html = '<div id="plugin_container2">';
                html += '<div id="digital_container2">';
                html += '<div id="clock2"></div>';
                html += '<div id="weather2"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData2($this);


                var panel_pos1 = ($('#plugin_container2 > div').length - 1) * 500;

            });
        }
    });
       
    $.fn.getData2 = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;


            $.fn.getTime2(el);
            $.fn.getWeather2(el);
            
        });
        setTimeout(function () { $.fn.getData2(el) }, $.fn.delay());
    }



    $.fn.delay2 = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }

    $.fn.getTime2 = function (el) {
        var now = new Date(el.CurrentDateTime);
        var old = new Date();
        old.setTime(now.getTime() - 60000);


        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours2"><div class="line"></div>';
        timeOld += '<div id="hours_bg2"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd2" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd2" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes2"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm2"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg2"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd2" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd2" class="second_digit" />';
        timeOld += '</div>';
       
        el.find('#clock2').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd2').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd2').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd2').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd2').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd2').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd2').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd2').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd2').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg2 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd2').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd2').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd2').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd2').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd2').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd2').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd2').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd2').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg2 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }

 
     $.fn.getWeather2 = function (el) {
        el.find('#weather2').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container2').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather2 .loading, #forecast_container2 .loading').hide();
            var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

            el.find('#weather2').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
            var weather = '<div id="local2"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
            weather += '<div id="temp2">' + curr_temp + '</div>';
            el.find('#weather2').html(weather);

            $('#reload').click(function () {
                el.find('#weather2').html('');
                $.fn.getWeather2(el);
            });
    }

})(jQuery);



//CLOCK 4
(function ($) {
    $.fn.extend({

        jdigiclock3: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'ASI|BD|BG001|CHITTAGONG',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };
            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';

                var html = '<div id="plugin_container3">';
                html += '<div id="digital_container3">';
                html += '<div id="clock3"></div>';
                html += '<div id="weather3"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData3($this);

                var panel_pos1 = ($('#plugin_container3 > div').length - 1) * 500;

            });
        }
    });

    $.fn.getData3 = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;

            $.fn.getTime3(el);
            $.fn.getWeather3(el);
        });
        setTimeout(function () { $.fn.getData3(el) }, $.fn.delay());
    }


    $.fn.delay3 = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }

    $.fn.getTime3 = function (el) {
        var now = new Date(el.CurrentDateTime);
        var old = new Date();
        old.setTime(now.getTime() - 60000);


        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours3"><div class="line"></div>';
        timeOld += '<div id="hours_bg3"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd3" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd3" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes3"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm3"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg3"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd3" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd3" class="second_digit" />';
        timeOld += '</div>';
       
        el.find('#clock3').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd3').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd3').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd3').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd3').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd3').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd3').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd3').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd3').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg3 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd3').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd3').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd3').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd3').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd3').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd3').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd3').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd3').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg3 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }

    $.fn.getWeather3 = function (el) {
        el.find('#weather3').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container3').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather3 .loading, #forecast_container3 .loading').hide();
            var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

            el.find('#weather3').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
            var weather = '<div id="local3"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
            weather += '<div id="temp3">' + curr_temp + '</div>';
            el.find('#weather3').html(weather);

            $('#reload').click(function () {
                el.find('#weather3').html('');
                $.fn.getWeather3(el);
            });
    }

})(jQuery);


//CLOCK 5
(function ($) {
    $.fn.extend({

        jdigiclock4: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'NAM|US|NY|NEW YORK',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };
            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';

                var html = '<div id="plugin_container4">';
                html += '<div id="digital_container4">';
                html += '<div id="clock4"></div>';
                html += '<div id="weather4"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData4($this);


                var panel_pos1 = ($('#plugin_container4 > div').length - 1) * 500;

            });
        }
    });


    $.fn.getData4 = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;

            $.fn.getTime4(el);
            $.fn.getWeather4(el);
        });
        setTimeout(function () { $.fn.getData4(el) }, $.fn.delay());
    }



    $.fn.delay4 = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }

    $.fn.getTime4 = function (el) {
        var now = new Date(el.CurrentDateTime);
        var old = new Date();
        old.setTime(now.getTime() - 60000);


        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours4"><div class="line"></div>';
        timeOld += '<div id="hours_bg4"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd4" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd4" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes4"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm4"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg4"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd4" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd4" class="second_digit" />';
        timeOld += '</div>';
       
        el.find('#clock4').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd4').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd4').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd4').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd4').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd4').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd4').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd4').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd4').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg4 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd4').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd4').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd4').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd4').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd4').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd4').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd4').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd4').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg4 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }

    
    $.fn.getWeather4 = function (el) {
        el.find('#weather4').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container4').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather4 .loading, #forecast_container4 .loading').hide();
            var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

            el.find('#weather4').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
            var weather = '<div id="local4"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
            weather += '<div id="temp4">' + curr_temp + '</div>';
            el.find('#weather4').html(weather);

            $('#reload').click(function () {
                el.find('#weather4').html('');
                $.fn.getWeather4(el);
            });
    }

})(jQuery);





















//CLOCK 6
(function ($) {
    $.fn.extend({

        jdigiclock5: function (options) {

            var defaults = {
                clockImagesPath: 'images/clock/clock/',
                weatherImagesPath: 'images/clock/weather/',
                lang: 'en',
                am_pm: false,
                weatherLocationCode: 'SAM|BR|BR017|RIO DE JANEIRO',
                weatherMetric: 'C',
                weatherUpdate: 0,
                proxyType: 'asp'

            };
            var regional = [];
            regional['en'] = {
                monthNames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
            }


            var options = $.extend(defaults, options);

            return this.each(function () {

                var $this = $(this);
                var o = options;
                $this.clockImagesPath = o.clockImagesPath;
                $this.weatherImagesPath = o.weatherImagesPath;
                $this.lang = regional[o.lang] == undefined ? regional['en'] : regional[o.lang];
                $this.am_pm = o.am_pm;
                $this.weatherLocationCode = o.weatherLocationCode;
                $this.weatherMetric = o.weatherMetric == 'C' ? 1 : 0;
                $this.weatherUpdate = o.weatherUpdate;
                $this.proxyType = o.proxyType;
                $this.currDate = '';
                $this.timeUpdate = '';

                $this.CurrentTemp = '';
                $this.CurrentCity = '';
                $this.CurrentDate = '';
                $this.CurrentWeather = '';
                $this.CurrentDateTime = '';
                $this.WeatherIcon = '';

                var html = '<div id="plugin_container5">';
                html += '<div id="digital_container5">';
                html += '<div id="clock5"></div>';
                html += '<div id="weather5"></div>';
                html += '</div>';
                html += '</div>';

                $this.html(html);

                $this.getData5($this);


                var panel_pos1 = ($('#plugin_container5 > div').length - 1) * 500;

            });
        }
    });


    $.fn.getData5 = function (el) {
        //Go to the webservice and get the data
        $.getJSON('lib/asp/Weather.aspx?location=' + el.weatherLocationCode + '&metric=' + el.weatherMetric, function (data) {
            el.CurrentDateTime = data.DateTime;
            el.CurrentWeather = data.WeatherCurrent;
            el.CurrentTemp = data.WeatherTemp;
            el.CurrentCity = data.City;
            el.CurrentDate = data.Date;
            el.WeatherIcon = data.WeatherIcon;

            $.fn.getTime5(el);
            $.fn.getWeather5(el);
        });
        setTimeout(function () { $.fn.getData5(el) }, $.fn.delay());
    }



    $.fn.delay5 = function () {
        var now = new Date();
        var delay = (60 - now.getSeconds()) * 1000;

        return delay;
    }

    $.fn.getTime5 = function (el) {
        var now = new Date(el.CurrentDateTime);
        var old = new Date();
        old.setTime(now.getTime() - 60000);


        var now_hours, now_minutes, old_hours, old_minutes, timeOld = '';
        now_hours = now.getHours();
        now_minutes = now.getMinutes();
        old_hours = old.getHours();
        old_minutes = old.getMinutes();

        if (el.am_pm) {
            var am_pm = now_hours > 11 ? 'pm' : 'am';
            now_hours = ((now_hours > 12) ? now_hours - 12 : now_hours);
            old_hours = ((old_hours > 12) ? old_hours - 12 : old_hours);
        }

        now_hours = ((now_hours < 10) ? "0" : "") + now_hours;
        now_minutes = ((now_minutes < 10) ? "0" : "") + now_minutes;
        old_hours = ((old_hours < 10) ? "0" : "") + old_hours;
        old_minutes = ((old_minutes < 10) ? "0" : "") + old_minutes;
        // date
        el.currDate = el.lang.dayNames[now.getDay()] + ',&nbsp;' + now.getDate() + '&nbsp;' + el.lang.monthNames[now.getMonth()];
        // time update
        el.timeUpdate = el.currDate + ',&nbsp;' + now_hours + ':' + now_minutes;

        var firstHourDigit = old_hours.substr(0, 1);
        var secondHourDigit = old_hours.substr(1, 1);
        var firstMinuteDigit = old_minutes.substr(0, 1);
        var secondMinuteDigit = old_minutes.substr(1, 1);

        timeOld += '<div id="hours5"><div class="line"></div>';
        timeOld += '<div id="hours_bg5"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstHourDigit + '.png" id="fhd5" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondHourDigit + '.png" id="shd5" class="second_digit" />';
        timeOld += '</div>';
        timeOld += '<div id="minutes5"><div class="line"></div>';
        if (el.am_pm) {
            timeOld += '<div id="am_pm5"><img src="' + el.clockImagesPath + am_pm + '.png" /></div>';
        }
        timeOld += '<div id="minutes_bg5"><img src="' + el.clockImagesPath + 'clock1.png" /></div>';
        timeOld += '<img src="' + el.clockImagesPath + firstMinuteDigit + '.png" id="fmd5" class="first_digit" />';
        timeOld += '<img src="' + el.clockImagesPath + secondMinuteDigit + '.png" id="smd5" class="second_digit" />';
        timeOld += '</div>';
       
        el.find('#clock5').html(timeOld);

        // set minutes
        if (secondMinuteDigit != '9') {
            firstMinuteDigit = firstMinuteDigit + '1';
        }

        if (old_minutes == '59') {
            firstMinuteDigit = '511';
        }

        setTimeout(function () {
            $('#fmd5').attr('src', el.clockImagesPath + firstMinuteDigit + '-1.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#fmd5').attr('src', el.clockImagesPath + firstMinuteDigit + '-2.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#fmd5').attr('src', el.clockImagesPath + firstMinuteDigit + '-3.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () {
            $('#smd5').attr('src', el.clockImagesPath + secondMinuteDigit + '-1.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock2.png');
        }, 200);
        setTimeout(function () { $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
        setTimeout(function () {
            $('#smd5').attr('src', el.clockImagesPath + secondMinuteDigit + '-2.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock4.png');
        }, 400);
        setTimeout(function () { $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
        setTimeout(function () {
            $('#smd5').attr('src', el.clockImagesPath + secondMinuteDigit + '-3.png');
            $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock6.png');
        }, 600);

        setTimeout(function () { $('#fmd5').attr('src', el.clockImagesPath + now_minutes.substr(0, 1) + '.png') }, 800);
        setTimeout(function () { $('#smd5').attr('src', el.clockImagesPath + now_minutes.substr(1, 1) + '.png') }, 800);
        setTimeout(function () { $('#minutes_bg5 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);

        // set hours
        if (now_minutes == '00') {

            if (el.am_pm) {
                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    now_hours = '12';
                } else if (now_hours == '01') {
                    firstHourDigit = '001';
                    secondHourDigit = '111';
                } else {
                    firstHourDigit = firstHourDigit + '1';
                }
            } else {
                if (now_hours != '10') {
                    firstHourDigit = firstHourDigit + '1';
                }

                if (now_hours == '20') {
                    firstHourDigit = '1';
                }

                if (now_hours == '00') {
                    firstHourDigit = firstHourDigit + '1';
                    secondHourDigit = secondHourDigit + '11';
                }
            }

            setTimeout(function () {
                $('#fhd5').attr('src', el.clockImagesPath + firstHourDigit + '-1.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clockb.png');
            }, 200);
            setTimeout(function () { $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clockb.png') }, 250);
            setTimeout(function () {
                $('#fhd5').attr('src', el.clockImagesPath + firstHourDigit + '-2.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#fhd5').attr('src', el.clockImagesPath + firstHourDigit + '-3.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () {
                $('#shd5').attr('src', el.clockImagesPath + secondHourDigit + '-1.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock2.png');
            }, 200);
            setTimeout(function () { $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock3.png') }, 250);
            setTimeout(function () {
                $('#shd5').attr('src', el.clockImagesPath + secondHourDigit + '-2.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock4.png');
            }, 400);
            setTimeout(function () { $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock5.png') }, 450);
            setTimeout(function () {
                $('#shd5').attr('src', el.clockImagesPath + secondHourDigit + '-3.png');
                $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock6.png');
            }, 600);

            setTimeout(function () { $('#fhd5').attr('src', el.clockImagesPath + now_hours.substr(0, 1) + '.png') }, 800);
            setTimeout(function () { $('#shd5').attr('src', el.clockImagesPath + now_hours.substr(1, 1) + '.png') }, 800);
            setTimeout(function () { $('#hours_bg5 img').attr('src', el.clockImagesPath + 'clock1.png') }, 850);
        }
    }

    
    $.fn.getWeather5 = function (el) {
        el.find('#weather5').html('<p class="loading">Update Weather ...</p>');
        el.find('#forecast_container5').html('<p class="loading">Update Weather ...</p>');
        var metric = el.weatherMetric == 1 ? 'C' : 'F';
        var proxy = '';

        el.find('#weather5 .loading, #forecast_container5 .loading').hide();
            var curr_temp = '<p class="temp">' + el.CurrentTemp + '&deg;<span class="metric">' + metric + '</span></p>';

            el.find('#weather5').css('background', 'url(' + el.weatherImagesPath + el.WeatherIcon + '.png) 50% 10% no-repeat');
            var weather = '<div id="local5"><p class="city">' + el.CurrentCity + '</p><p class="current">' + el.CurrentWeather + '</p></div>';
            weather += '<div id="temp5">' + curr_temp + '</div>';
            el.find('#weather5').html(weather);

            $('#reload').click(function () {
                el.find('#weather5').html('');
                $.fn.getWeather5(el);
            });
    }

})(jQuery);


