

$(document).ready(function(){
	$('#climamty').weatherfeed(['MXNL0068']); //clima
	// Cambiar fondo segun la hora
	var d = new Date();
    var curr_hour = d.getHours();	

	if (curr_hour >= 5 && curr_hour < 7)
    {
		//12am - 7am  Night Time Bg
		$('html').addClass('madrugada');
		$('div.flash').attr('id', 'bg_madrugada');
		var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "madrugada",
          name: "madrugada",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "mandrugada",
          name: "mandrugada",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/madrugada.swf", "bg_dia", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);

	}

	if (curr_hour == 7)
    {
		//7-8am transition time
		$('html').addClass('dia');
		$('div.flash').attr('id', 'bg_dia');
		var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "dia",
          name: "dia",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "dia",
          name: "dia",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/dia.swf", "bg_dia", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
    }

	if (curr_hour > 8 && curr_hour < 17)
    {
		//7am - 6pm Day Time Bg
		$('html').addClass('dia');
		$('div.flash').attr('id', 'bg_dia');
		//Funciones BB Tarde
        var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "dia",
          name: "dia",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "dia",
          name: "dia",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/dia.swf", "bg_dia", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
    }

	if (curr_hour == 17)
    {
        $('html').addClass('tarde');
		$('.flash').attr('id', 'bg_tarde');
		//Funciones BB Tarde
        var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/tarde.swf", "bg_tarde", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
	}

	if (curr_hour > 17 && curr_hour <= 19)
    {
        //7pm - 11pm Night Time Bg
		$('html').addClass('tarde');
		$('.flash').attr('id', 'bg_tarde');
		//Funciones BB Tarde
        var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/tarde.swf", "bg_tarde", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
    }
	
	if (curr_hour == 19)
    {
		$('html').addClass('tarde');
		$('.flash').attr('id', 'bg_tarde');
		//Funciones BB Tarde
        var flashvars = {
          myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "image", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "tarde",
          name: "tarde",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/tarde.swf", "bg_tarde", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
    }
	
		if (curr_hour > 19 && curr_hour <= 24)
    {
        //7pm - 11pm Night Time Bg
		$('html').addClass('noche');
		$('.flash').attr('id', 'bg_noche');
    }
	
	if (curr_hour > 0 && curr_hour <= 5)
    {
        //7pm - 11pm Night Time Bg
		$('html').addClass('madrugada');
		$('div.flash').attr('id', 'bg_madrugada');
		var flashvars = {
          //myFile: "a_bg_img.jpg", //set the file URL that flash will load
  		  myFileType: "flash", //set filetype (values: image, flash)
  		  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "madrugada",
          name: "madrugada",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "mandrugada",
          name: "mandrugada",
          wmode: "transparent",
          menu: "false"
        };

		swfobject.embedSWF("swf/madrugada.swf", "bg_madrugada", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
    }    
	// Cambiar fondo segun la hora (end)
	$('.menu_footer').delegate("li", "mouseover mouseout", function(e) {
		if (e.type == 'mouseover') {
		$('.menu_footer li').not(this).dequeue().animate({opacity: "0.3"}, 300);
    	} else {
		$('.menu_footer li').not(this).dequeue().animate({opacity: "1"}, 300);
   		}
	});
	$('.menu_social').delegate("li", "mouseover mouseout", function(e) {
		if (e.type == 'mouseover') {
		$('.menu_social li').not(this).dequeue().animate({opacity: "0.3"}, 300);
    	} else {
		$('.menu_social li').not(this).dequeue().animate({opacity: "1"}, 300);
   		}
	});
	
});

//Funciones Fondo 1
        var flashvars = {
          loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
        };
        var params = {
          id: "intro",
          name: "intro",
          wmode: "transparent",
          menu: "false"
        };
        var attributes = {
          id: "intro",
          name: "intro",
          wmode: "transparent",
          menu: "false"
        };
        
        swfobject.embedSWF("swf/intro.swf", "bg", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
		
//Funciones Mona     
        swfobject.embedSWF("swf/mona.swf", "bg_mona", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
		
				
	//Funciones BB Noche
	var flashvars = {
	  myFile: "images/01madrugada.jpg", //set the file URL that flash will load
	  myFileType: "image", //set filetype (values: image, flash)
	  loadEffect: "Fade" //set load effect - options: "Fade", "Wipe", "Iris", "PixelDissolve", "Photo"
	};
	var params = {
	  id: "bg_noche",
	  name: "bg_noche",
	  wmode: "transparent",
	  menu: "false"
	};
	var attributes = {
	  id: "bg_noche",
	  name: "tarde",
	  wmode: "transparent",
	  menu: "false"
	};

	swfobject.embedSWF("swf/noche.swf", "bg_noche", "984", "732", "10.0.45.2","expressInstall.swf", flashvars, params, attributes);
		//end noche

//clima
(function($){

	var row = 'odd';

	$.fn.weatherfeed = function(locations, options) {	
	
		// Set pluign defaults
		var defaults = {
			unit: 'c',
			image: true,
			highlow: true,
			wind: false,
			link: false,
			showerror: false
		};  
		var options = $.extend(defaults, options); 
		
		// Functions
		return this.each(function(i, e) {
			var $e = $(e);
			
			// Add feed class to user div
			if (!$e.hasClass('weatherFeed')) $e.addClass('weatherFeed');

			// Check and append locations
			if (!$.isArray(locations)) return false;
			var count = locations.length;
			if (count > 10) count = 10;
			var locationid = '';
			for (var i=0; i<count; i++) {
				if (locationid != '') locationid += ',';
				locationid += "'"+ locations[i] + "'";
			}

			// Cache results for an hour to prevent overuse
			now = new Date()
					
			// Create Yahoo Weather feed API address
			var query = "select * from weather.forecast where location in ("+ locationid +") and u='"+ options.unit +"'";
			var api = 'http://query.yahooapis.com/v1/public/yql?q='+ encodeURIComponent(query) +'&rnd='+ now.getFullYear() + now.getMonth() + now.getDay() + now.getHours() +'&format=json&callback=?';

			// Send request
			//$.getJSON(api, function(data) {
			$.ajax({
				type: 'GET',
				url: api,
				dataType: 'json',
				success: function(data) {

					if (data.query) {
			
						if (data.query.results.channel.length > 0 ) {
							
							// Multiple locations
							var result = data.query.results.channel.length;
							for (var i=0; i<result; i++) {
							
								// Create weather feed item
								_callback(e, data.query.results.channel[i], options);
							}
						} else {

							// Single location only
							_callback(e, data.query.results.channel, options);
						}
					} else {
						if (options.showerror) $e.html('<p>Weather information unavailable</p>');
					}
				},
				error: function(data) {
					if (options.showerror)  $e.html('<p>Weather request failed</p>');
				}
			});

		});
	};

	// Function to each feed item
	var _callback = function(e, feed, options) {
		var $e = $(e);

		// Format feed items
		var wd = feed.wind.direction;
		if (wd>=348.75&&wd<=360){wd="N"};if(wd>=0&&wd<11.25){wd="N"};if(wd>=11.25&&wd<33.75){wd="NNE"};if(wd>=33.75&&wd<56.25){wd="NE"};if(wd>=56.25&&wd<78.75){wd="ENE"};if(wd>=78.75&&wd<101.25){wd="E"};if(wd>=101.25&&wd<123.75){wd="ESE"};if(wd>=123.75&&wd<146.25){wd="SE"};if(wd>=146.25&&wd<168.75){wd="SSE"};if(wd>=168.75&&wd<191.25){wd="S"};if(wd>=191.25 && wd<213.75){wd="SSW"};if(wd>=213.75&&wd<236.25){wd="SW"};if(wd>=236.25&&wd<258.75){wd="WSW"};if(wd>=258.75 && wd<281.25){wd="W"};if(wd>=281.25&&wd<303.75){wd="WNW"};if(wd>=303.75&&wd<326.25){wd="NW"};if(wd>=326.25&&wd<348.75){wd="NNW"};
		var wf = feed.item.forecast[0];
		
		// Determine day or night image
		wpd = feed.item.pubDate;
		n = wpd.indexOf(":");
		tpb = _getTimeAsDate(wpd.substr(n-2,8));
		tsr = _getTimeAsDate(feed.astronomy.sunrise);
		tss = _getTimeAsDate(feed.astronomy.sunset);

		if (tpb>tsr && tpb<tss) { daynight = 'd'; } else { daynight = 'n'; }

		// Add item container
		var html = '<div class="weatherItem '+ row +'"';		/*http://l.yimg.com/a/i/us/nws/weather/gr/ (URL Original)*/
		if (options.image) html += ' style="background-image: url(images/clima/'+ feed.item.condition.code + daynight +'.png); background-repeat: no-repeat;"';
		html += '>';
		
		// Add item data
		html += '<div class="weatherCity">'+ feed.location.city +'</div>';
		html += '<div class="weatherTemp">'+ feed.item.condition.temp +'&deg;</div>';
		//html += '<div class="weatherDesc">'+ feed.item.condition.text +'</div>';
		if (options.highlow) html += '<span class="weatherRange">'+ wf.low +'&deg; Min &nbsp;'+ wf.high +'&deg; Max</span>';
		if (options.wind) html += '<div class="weatherWind">Wind: '+ wd +' '+ feed.wind.speed + feed.units.speed +'</div>';
		if (options.link) html += '<div class="weatherLink"><a href="'+ feed.item.link +'">Read full forecast</a></div>';
		
		html += '</div>';

		// Alternate row classes
		if (row == 'odd') { row = 'even'; } else { row = 'odd';	}
		
		$e.append(html);
	};

	// Get time string as date
	var _getTimeAsDate = function(t) {
		
		d = new Date();
		r = new Date(d.toDateString() +' '+ t);

		return r;
	};
})(jQuery);		

		
