function JtagWeather() {

    this.init = function(settings) {
        baseURL = settings.root;
        units   = settings.units;
	  
        // Defaults
        jQuery('#JtagWChange a').click(function(){
            jQuery('.JtagWeather').children().not('#JtagWChangeBox').fadeOut(500);
            jQuery('#JtagWChangeBox').fadeIn(500);
        })
        
        // On load
        // AJAX request
        
        if (jQuery.cookie('JtagWeather')) {
            loc = jQuery.cookie('JtagWeather');
        } else {
            loc = settings.loc;
        }
        
        jQuery.ajax({
            type: 'POST',
            url: baseURL+'modules/mod_jtagweather/xml/mod_jtagweatherxml.php',
            data: 'location='+loc,
            success: function(xml) {
                var loc        = jQuery(xml).find('current').find('location').text();
                var celsius    = jQuery(xml).find('current').find('c').text();
                var fahrenheit = jQuery(xml).find('current').find('f').text();
                var con        = jQuery(xml).find('current').find('con').text();
                var icon       = jQuery(xml).find('current').find('icon').text();

                icon = icon.replace('/ig/images/weather/','');
                icon = icon.replace('.gif','.png');
                
                // Forecast
                jQuery(xml).find('forecast').each(function(){
                    
                    var theday   = jQuery(this).find('day').text();
                    var foreicon = jQuery(this).find('icon').text();
                    var low      = jQuery(this).find('low').text();
                    var high     = jQuery(this).find('high').text();
                    
                    foreicon = foreicon.replace('/ig/images/weather/','');
                    foreicon = foreicon.replace('.gif','.png');
                    //jQuery('.JtagWForeImage').attr('src', baseURL+'modules/mod_jtagweather/css/img/'+foreicon);
                    
                    if ( units == 'celsius' ) {
                        // Convert F to C
                        low  = Math.round( ( (low - 32)  * 5) / 9  );
                        high = Math.round( ( (high - 32) * 5) / 9  );
                    }
            
                    jQuery('<div class="JtagWForecast"><div class="JtagWForeText"><p class="JtagWDay">'+theday+'</p><p class="JtagForeDeg"><span class="low">'+low+'|</span><span class="high">'+high+'</span></p></div><img alt="" class="JtagWForeImage" src="'+baseURL+'modules/mod_jtagweather/css/img/'+foreicon+'"/></div>').appendTo('#JtagW4Days');
    
                })
        
                // Display Module
                jQuery('#JtagWLoading').remove();
                jQuery('.JtagWeather').children().not('#JtagW4Days').not('#JtagWChangeBox').fadeIn(500);
                
                // Print Temp Degrees
                if ( units == 'celsius' ) {
                    jQuery('#JtagWDeg').text(celsius + '°C')
                }
                if ( units == 'fahrenheit' ) {
                    jQuery('#JtagWDeg').text(fahrenheit + '°F')
                }
                
                // Print Location
                jQuery('#JtagWLocation').text(loc);
               
                //Print Weather Icons
                jQuery('#JtagWIcon').attr('src', baseURL+'modules/mod_jtagweather/css/img/'+icon);
            },
            dataType: 'xml'
        });
        // END of AJAX request
       
       
        // On User Action     
        
        // User Weather Icon Mouseover
        jQuery('#JtagWIcon').mouseover(function(){

            //alert(jQuery('#JtagW4Days').html())

            jQuery('.JtagWeather').children().fadeOut(200);
            jQuery('#JtagW4Days').fadeIn(200);
   
        });
        
        jQuery('.JtagWeather').mouseleave(function(){
            if (jQuery('#JtagW4Days').is(':visible')) {
                jQuery('#JtagW4Days').fadeOut(200);
                jQuery('.JtagWeather').children().not('#JtagW4Days').not('#JtagWChangeBox').fadeIn(200);
            }
        })
        
        
        // User Location
        jQuery('#JtagWChangeBox input').blur(function(){
           
            var loc = jQuery('#JtagWChangeBox input').val();
            
            if (loc.trim()) {
                
                jQuery.cookie("JtagWeather", loc, {
                    expires : 10
                });
                                           
                jQuery('#JtagWChangeBox').fadeOut(500);
                // AJAX request
                jQuery.ajax({
                    type: 'POST',
                    url: baseURL+'modules/mod_jtagweather/xml/mod_jtagweatherxml.php',
                    data: 'location='+loc,
                    success: function(xml) {
                    
                        var loc        = jQuery(xml).find('current').find('location').text();
                        var celsius    = jQuery(xml).find('current').find('c').text();
                        var fahrenheit = jQuery(xml).find('current').find('f').text();
                        var con        = jQuery(xml).find('current').find('con').text();
                        var icon       = jQuery(xml).find('current').find('icon').text();
				
                        icon = icon.replace('/ig/images/weather/','');
                        icon = icon.replace('.gif','.png');
                        
                        // Forecast
                        jQuery('#JtagW4Days').children().remove();
                        jQuery(xml).find('forecast').each(function(){

                            var theday   = jQuery(this).find('day').text();
                            var foreicon = jQuery(this).find('icon').text();
                            var low      = jQuery(this).find('low').text();
                            var high     = jQuery(this).find('high').text();

                            foreicon = foreicon.replace('/ig/images/weather/','');
                            foreicon = foreicon.replace('.gif','.png');
                            //jQuery('.JtagWForeImage').attr('src', baseURL+'modules/mod_jtagweather/css/img/'+foreicon);
                            
                            if ( units == 'celsius' ) {
                                // Convert F to C
                                low  = Math.round( ( (low - 32)  * 5) / 9  );
                                high = Math.round( ( (high - 32) * 5) / 9  );
                            }
                            
                            jQuery('<div class="JtagWForecast"><div class="JtagWForeText"><p class="JtagWDay">'+theday+'</p><p class="JtagForeDeg"><span class="low">'+low+'|</span><span class="high">'+high+'</span></p></div><img alt="" class="JtagWForeImage" src="'+baseURL+'modules/mod_jtagweather/css/img/'+foreicon+'"/></div>').appendTo('#JtagW4Days');
             
                        })
                    
                        jQuery('#JtagWChangeBox').fadeOut(500);
                        jQuery('.JtagWeather').children().not('#JtagW4Days').not('#JtagWChangeBox').fadeIn(500);
                    
                        // Print Temp Degrees

                        if ( units == 'celsius' ) {
                            jQuery('#JtagWDeg').text(celsius + '°C')
                        }
                        if ( units == 'fahrenheit' ) {
                            jQuery('#JtagWDeg').text(fahrenheit + '°F')
                        }

                        // Print Location
                        jQuery('#JtagWLocation').text(loc);

                        //Print Weather Icons
                        jQuery('#JtagWIcon').attr('src', baseURL+'modules/mod_jtagweather/css/img/'+icon);
					
                    },
                    dataType: 'xml'
                });
            // END of AJAX request
            }
        });
    }
    	
}
