// ON DOCUMENT READY

$(function(){
	
	$('.portafolio_sec .sabores a').click(function(){		
		$('.portafolio_sec .presentar:visible img').attr('src', 'assets/images/botellasmedianas/'+ $(this).attr('sabor')+'.png');
	});
	
	$('.portafolio_sec .botones a').click(function(){
		$('.p_400ml, .p_591ml, .p_litro, .p_tetrapak ,.p_polvo').hide();
		$('.'+$(this).attr('tipo')).show();
	});
	
	$(".comunidad_sec .meses").datepicker({
		beforeShowDay: diasValidos
	});
	
	
	var numero=0;
	//START ROTACION
	/*var numero = $.cookie('banner_slide');
	
	if(numero==undefined) numero = 0;
	else numero++;
	if(numero>1) numero=0;
	
	$.cookie('banner_slide', numero);*/
	//END ROTACION
	
	$(".banner_slider").cycle({
		startingSlide: numero,
		timeout:1000,
		pager:'.banner_pager',
		fx:'scrollHorz',
		pause:1,
		next:   '#next2', 
		prev:   '#prev2',
		after: function() {
			if( $(this).hasClass("EvolucionG") ) swfobject.registerObject("FlashEvolucionG");
		}
	});

	$(".pelota_holder").cycle({
		timeout:0,
		fx:'scrollHorz',
		pause:1,
		next:   '#pelota_next', 
		prev:   '#pelota_prev'		
	});
	
});

function diasValidos(date){
	return [false,'','Un dia'];
}

function showMap(myLat,myLang) {
	$(window)
		.load(function(){

			if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("corripio_map"));
			
			var mylatlng = new GLatLng(myLat,myLang);
			map.setCenter(mylatlng, 14);
			
			/*GEvent.addListener(map,"click", function(overlay,latlng) {     
			  if (latlng) {   
				var myHtml
				  = "Lat: " + latlng.lat() + "<br />"
				  + "Lng: " + latlng.lng() + "<br />"
				  + "Zoom: " +map.getZoom()+ "<br />"
				  ;
				map.openInfoWindow(latlng, myHtml);
			  }
			});*/
			
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addOverlay(new GMarker(mylatlng));
			}			
		})
		.unload(function(){
			GUnload();
		});	

}


function ventanaGris(selector){
	var ventana = $('<div class="ventana_gris" style="position:absolute; left:0; top:0; width:100%; height:100%; z-index:12;">\
		<div class="fondo_ventana_gris" style="position:absolute; left:0; top:0; width:100%; height:100%; background:black; opacity:0.7; filter:alpha(opacity=70); z-index:11;"></div>\
		<a href="#" class="cerrar" style="float:right; color:white; position:relative; z-index:13; border:2px solid white;padding: 10px;border-radius: 20px;font: 30px/20px Arial;text-decoration: none;\
				width: 20px;height: 20px; margin:20px;" onclick="$(\'.ventana_gris\').empty().remove(); return false;">X</a>\
		<div class="contenido" style="text-align:center; position:relative; z-index:12;"></div>\
		</div>');
	ventana.find('.contenido').append( $(selector).clone() ).find('div').show();
	
	$('body').append(ventana);
}


function ventanaSlider(){
	var h = $(document).height() + 'px';
	var w = $(document).width() + 'px';
	
	//var h = $(window).scrollTop() + 'px';
	
	$('.ventana_slider').css({width:w, height:h}).show();
}

function ventanaVideo(){
	var h = $(document).height() + 'px';
	var w = $(document).width() + 'px';
	
	//var h = $(window).scrollTop() + 'px';
	
	$('.ventana_video').css({width:w, height:h}).show();
}




/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
