(function($)
{
    
    $.fn.wpHoroscope = function(settings)
    {
        
        var defaultSettings =   {
                                    width : '300px',
                                    height : 'auto',
                                    backColor : '#00aa00'
                                };
                                
        settings = $.extend(defaultSettings, settings);

        function createDiv(pId, pWidth, pHeight, pFloat, pBackColor, pAppendTo)
        {
            
            return $('<div/>')
                .attr('id', pId)
                .css('width', pWidth)
                .css('height', pHeight)
                .css('float', pFloat)
                .css('background-color', pBackColor)
                .appendTo(pAppendTo);
            
        }

        
        this.each(function()
        {
            
            var obj = $(this);
            
            $.getJSON("http://www.scrippsscripts.com/swapi/horoscope/getHoroscope.php?period=" + settings.period + "&callback=?",
                function(data){
                    
                    createDiv(settings.period + 'horoscopeBox', '300px', 'auto', settings.float, '#ffffff', obj);

                    $('<div/>')
                        .html(data.horoscope_date.horoscope_dow + '. ' + data.horoscope_date.horoscope_month + '. ' + data.horoscope_date.horoscope_day + ', ' + data.horoscope_date.horoscope_year + '<br /><br />')
                        .css('padding', '5px;')
                        .css('font-size', '10pt')
                        .css('font-weight', 'bold')
                        .css('font-family', 'Verdana, Arial, Helvetica, Sans-Serif')
                        .css('color', '#000000')
                        .css('float', 'left')
                        .appendTo('#' + settings.period + 'horoscopeBox');

                    createDiv(settings.period + 'horoscopeText', '280px', 'auto', 'left', '#ffffff', '#' + settings.period + 'horoscopeBox');
                    
                    $('#' + settings.period + 'horoscopeText')
                        .css('padding', '5px');

                    for (i=0; i<data.horoscopes.horoscope.length; i++)
                    {
                        
                        var currentSign = data.horoscopes.horoscope[i].title;
                        var imageHTML = '<img src="http://media2.newsnet5.com/image/horoscope/ZodiacSigns/' + currentSign + '.png" alt="' + currentSign + '" style="padding-right:5px;float:left;" />';
                        
                        $('<h3/>')
                            .html(imageHTML + currentSign + ' (' + data.horoscopes.horoscope[i]._attributes.start_month + '. ' + data.horoscopes.horoscope[i]._attributes.start_day + ' - ' + data.horoscopes.horoscope[i]._attributes.end_month + '. ' + data.horoscopes.horoscope[i]._attributes.end_day + ')')
                            .css('padding', '10px')
                            .css('padding-top', '5px')
                            .css('padding-bottom', '5px')
                            .css('margin-top', '10px')
                            .css('font-size', '10pt')
                            .css('font-weight', 'normal')
                            .css('font-family', 'Verdana, Arial, Helvetica, Sans-Serif')
                            .css('color', '#000000')
                            .css('float', 'left')
                            .css('width', '100%')
                            .css('background-color', '#ffffff')
                            .css('border-width', '1px')
                            .css('border-style', 'solid')
                            .css('border-color', '#bbaf99')
                            .appendTo('#' + settings.period + 'horoscopeText');
    
                        $('<div/>')
                            .html(data.horoscopes.horoscope[i].content)
                            .css('height', '190px')
                            .css('border-width', '1px')
                            .css('border-style', 'solid')
                            .css('border-color', '#bbaf99')
                            .css('width', '100%')
                            .css('padding', '10px')
                            .css('font-size', '9pt')
                            .css('font-family', 'Verdana, Arial, Helvetica, Sans-Serif')
                            .css('color', '#000000')
                            .css('float', 'left')
                            .appendTo('#' + settings.period + 'horoscopeText');
                    }

                    //$('#' + settings.period + 'horoscopeText').accordion({ fillspace : true });
                        
            });
        
        });
        
        return this;
        
    };

})(jQuery);
