var _expose, $flashid;

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 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(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
// JavaScript Utils
function doShrinkLayer() {
	$('#'+$flashid).css('height',String(ExpandBanner.config.minheight+'px'));
};
function doExpandLayer() {
	$('#'+$flashid).css('height',String(ExpandBanner.config.height+'px'));
};

var ExpandBanner = {
	config:{
		bannersUrl:"f/swf/",
		width:950,
		height:400,
		minheight:30,
		expanded:0
	},
	init : function(){
		// Expose
		_expose = $("#backustopbanner1").expose({
			color : "#060D08",
			api: true,
			opacity: 0.95,
			closeOnClick: false, 
			onLoad: function() { 
				this.fit();  
			} 
		});
		
		$('div.banner.expandible').each(function(){
			var $this = $(this);
				$this.css('overflow', 'hidden');
				
			$flashid = String($this.attr('id'));
			var $flashbannerurl = String(ExpandBanner.config.bannersUrl+$flashid+'.swf');
			var $container = $this.find('.container');
				$container.attr('id', $flashid+'_expand');

			var flavars = {clickTag:$container.find('a').attr('href'), isExpanded:ExpandBanner.config.expanded, bannerId: $flashid}; 
			var flaparm = {menu:false, wmode:'opaque', quality:'high', allowScriptAccess : 'sameDomain', scale: 'noborder', salign: 'T'};
			swfobject.embedSWF($flashbannerurl, $flashid+'_expand', ExpandBanner.config.width, ExpandBanner.config.height, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", flavars, flaparm);
			if(ExpandBanner.config.expanded){
				doExpandLayer();
			}else{
				doShrinkLayer();
			}
		})
	},
	getBanner : function(id) {
		return $('#'+id);
	},
	setSize : function(id, dir) {
		var $flaObjt = ExpandBanner.getBanner(id+'_expand');
			$flaObjt.attr("height", dir?ExpandBanner.config.height:ExpandBanner.config.minheight);
	},
	overlayFocusOn : function(){
		_expose.load();
	},
	overlayFocusOff : function(){
		_expose.close()
	}	
};

// modal window
var ModalWindow = {
	parent:"body",
	windowId:null,
	content:null,
	width:null,
	height:null,
	close:function(){
		$('#menu').css("visibility","visible");
		$(".modal-window").remove();
		$(".modal-overlay").remove();
		$('html,body').removeAttr("style");
		$.cookie('filter_opened', 'true');
	},	
	open:function(){
		var modal = "";
		modal += "<div class=\"modal-overlay\"></div>";
		modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
		modal += '<div id="filter-container"><div id="filter-strip"></div><h3 class="sifrable">Presta mucha atenci&oacute;n !</h3>';
		modal += '<p class="first-parghp">Para ingresar a esta secci&oacute;n deber&aacute;s contar con la edad legal permitida para el consumo de alcohol en tu pa&iacute;s de residencia.</p>';
		modal += '<div class="over-strip"><p class="quest">&iquest;Tienes la edad legal para consumir cerveza en tu pa&iacute;s?</p> <div class="special"><p class="sifrable"><a href="#logo" class="optAfirm">s&iacute;</a> &nbsp; <a class="optNegat" href="#logo">no</a></p></div></div></div>';
		modal += "</div>";
		$('#menu').css("visibility","hidden");
		$('html,body').removeAttr("style");
		$('html,body').css({overflow:'hidden', height:($(document).height() + 'px')});
		$(this.parent).append(modal).find('.optAfirm').click(function(){ModalWindow.close(); return false;}).end().find('.optNegat').click(function(){/*history.back(1);*/ window.location.href='index.html'; return false;});
	}
};

// date
(function(){$.fn.date=function(){
	var days=["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"];
	var months=['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre'];
	var date=new Date();
	return this.text(days[date.getDay()]+', '+date.getDate()+' '+months[date.getMonth()]+' de '+date.getFullYear());
};})(jQuery);

/*var openMyModal = function(source){};
openMyModal('http://deseloper.org/examples/modal-simple/modal.html');*/

function setUpTabs(){
	//$('#news h3.todas, #news h3.marcas, #news h3.corp, #news h3.invsoc, #news h3.searchb').find("a").bind("click", tabOptionsClick);
	//$('#news h3.searchb a').bind("click", function(){ if($('#news .tab-search').is(":hidden")){$('#news .tab-search').slideDown();}else{$('#news .tab-search').slideUp();$(this).removeClass("selected");} });
}

function tabOptionsClick(e){ 
	$this = $(this);
	$this.parent().parent().parent().find("h3 a").removeClass("selected");
	$this.addClass("selected");
	if($('#news .tab-search').is(":hidden")==false && $this.parent().is('.searchb')==false)$('#news .tab-search').slideUp();
	return false;
}


var MultiForms = {
	settings : {main: "#multiForms", trigger:"#multiformsTrigger", containers: ".multiformsContainer", prefix:"#mForm"},
	setUp : function(){
		$(this.settings.trigger).change(function(){
			MultiForms.chooseForm($(this).val());
		});
		MultiForms.chooseForm($(this.settings.trigger).val());
	},
	chooseForm : function(id){
		if(id>-1){
			$(this.settings.prefix+id).css("display", "block").siblings().css("display", "none");
		}
	}
}

$(document).ready(function(){
	$('#header p').date();
	if($('body').is('.adultonly')){
		if($.cookie('filter_opened')!="true"){			
			ModalWindow.windowId = "adultOnlyWin";
			ModalWindow.width = 950;
			ModalWindow.height = 550;
			ModalWindow.content = "<iframe width='"+ModalWindow.width+"' height='"+ModalWindow.height+"' frameborder='0' scrolling='no' allowtransparency='true' src='filter.html'>&lt/iframe>";
			ModalWindow.open();
		}
	}
	Cufon.replace('h1.sifrable, h2.sifrable, h3.sifrable, h4.sifrable, p.sifrable');
	
	// tabs
	setUpTabs();
	
	// search field
	var searchTxtLine = "Buscar noticias";
	$(".tab-search input[name='q']").focus(function(){ if($(this).val()==searchTxtLine){$(this).val("");} }).blur(function(){if($(this).val()==""){$(this).val(searchTxtLine);} })
	$("#menu>li").hover(function(){$(this).addClass("hover")}, function(){$(this).removeClass("hover")});
});

var flaparm = {menu:false, wmode:'opaque', quality:'high', allowScriptAccess: 'always', scale: 'noborder', salign: 'T'};
swfobject.embedSWF('f/interactive/carrusel.swf', 'cervezascarusel', 710, 452, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {xmlitems:'f/interactive/cervezas/cervezas.xml'}, flaparm);
swfobject.embedSWF('f/interactive/carrusel.swf', 'bebidascarusel', 710, 452, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {xmlitems:'f/interactive/bebidas/bebidas.xml'}, flaparm);
swfobject.embedSWF('f/interactive/carrusel.swf', 'prioridades10swf', 710, 325, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {xmlitems:'f/interactive/10PDS/10prioridades.xml'}, flaparm);
swfobject.embedSWF('f/interactive/historia/historia.swf', 'historiaswf', 710, 450, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {idioma:1}, {menu:false, wmode:'opaque', scale: 'noscale',salign: 'TB'});
swfobject.embedSWF('f/interactive/tourvirtual/tourVirtual.swf', 'comohacemoscervezaswf', 710, 450, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {idioma:1}, {menu:false, wmode:'opaque', scale: 'noscale',salign: 'TB'});
swfobject.embedSWF('f/interactive/derechosHumanos.swf', 'ddhhFlash', 575, 366, "9.0.0", ExpandBanner.config.bannersUrl+"expressInstall.swf", {idioma:1}, {menu:false, wmode:'opaque', scale: 'noscale',salign: 'TL'});
