/*
Extensiones
----------------------------------------------*/
Effect.PhaseIn = function(element) {
  element = $(element);
  new Effect.BlindDown(element, arguments[1] || {});
  new Effect.Appear(element, arguments[2] || arguments[1] || {});
}

Effect.PhaseOut = function(element) {
  element = $(element);
  new Effect.Fade(element, arguments[1] || {});
  new Effect.BlindUp(element, arguments[2] || arguments[1] || {});
}

Effect.Phase = function(element) {
  element = $(element);
  if (element.style.display == 'none')
    new Effect.PhaseIn(element, arguments[1] || {}, arguments[2] || arguments[1] || {});
  else new Effect.PhaseOut(element, arguments[1] || {}, arguments[2] || arguments[1] || {});
}
Effect.Transitions.exponential = function(pos) {
  return 1-Math.pow(1-pos,2);
}
Effect.Transitions.slowstop = function(pos) {
  return 1-Math.pow(0.5,20*pos);
}
// Adapted from DOM Ready extension by Dan Webb
// http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
// which was based on work by Matthias Miller, Dean Edwards and John Resig
//
// Usage:
//
// Event.onReady(callbackFunction);
Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (Event._timer)  clearInterval(Event._timer);
    
    Event._readyCallbacks.each(function(f) { f() });
    Event._readyCallbacks = null;
    
  },
  onReady : function(f) {
    if (!this._readyCallbacks) {
      var domReady = this._domReady;
      
      if (domReady.done) return f();
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);
        
        /*@cc_on @*/
        /*@if (@_win32)
            var dummy = location.protocol == "https:" ?  "https://javascript:void(0)" : "javascript:void(0)";
            document.write("<script id=__ie_onload defer src='" + dummy + "'><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") { domReady(); }
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});

/*
Javascript disponible en todas las paginas
Ismael Celis / Aardvark @ 01/2007
----------------------------------------------*/
var LoadEffects = {
	global_int:null,
	config:{
		highlight_duration:3,
		interval_duration:2
	},
	fades:function(){
		clearInterval(LoadEffects.global_int);
		$$(".fade").each(function(e){
			new Effect.Highlight(e,{duration:LoadEffects.config.highlight_duration});
		});
	},
	adjustContentHeight: function(){
		var sidebar = $("the_sidebar");
		var content = $("the_content");
		if(sidebar && content){
			var content_height = content.getHeight();
			var sidebar_height = sidebar.getHeight();
			if(sidebar_height > content_height)
				content.setStyle({height:(sidebar_height+40)+"px"});
		}
	},
	init:function(){
		LoadEffects.global_int = window.setInterval(LoadEffects.fades,LoadEffects.config.interval_duration*1000);
		//LoadEffects.fades();
		LoadEffects.adjustContentHeight();
	}
}

var Buttons = {
	clickSubmit:function(button){
		var opts = Object.extend(
			{
				hide:null
			},
			arguments[1] || {}
		);
		if(opts.hide && $(opts.hide)){
			$(opts.hide).style.height = $(opts.hide).getHeight() + 'px';
			$(opts.hide).innerHTML = "<p class='processing'>Procesando...</p>";
		}
		var loader = "<span class='submit-loader' style='height:"+$(button).getHeight()+"px;'><img src='/medios/art/ajax-loader.gif' /></span>";
		$(button).hide();
		new Insertion.After(button, loader);
	},
	processSubmit:function(id){
		var loader = "<div class='submit-process' style='height:"+$(id).getHeight()+"px;'><img src='/medios/art/ajax-loader.gif' /></div>";
		new Insertion.After(id, loader);
		$(id).hide();
	}
}
Effect.SmoothCollapse = function(node){
	new Effect.PhaseOut(node,{
		transition: Effect.Transitions.slowstop, scaleContent: true, duration:2,
		beforeStart:function(ev){
			ev.element.style.borderWidth = 0;
		}
	});
}

var Flash = {
	embed: function(swf){
		var options = Object.extend(
			{
				width:610,
				height:320,
				quality:'high',
				path:'/medios/banners/',
				config_file:'/campanas/config.php'
			},
			arguments[1] || {}
		);
		var conf = options.config_file?'?config_file='+options.config_file:'';
		var src = options.path + swf + '.swf' + conf;
		var str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0'";
		str += " id='FlashMovie' width='"+options.width+"' height='"+options.height+"'>";
		str += " <param name=movie value='"+src+"'>";
		str += " <param name='quality' value="+options.quality+">";
		str += " <param name='play' value='True'>";
		str += " <embed play='True' name='FlashMovie' src='"+src+"' quality="+options.quality+" width='"+options.width+"' height='"+options.height+"' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed >";
		str += "</object>";
		document.write(str);
	}
}
Event.onReady(LoadEffects.init);
/*Event.observe(window,"load",function(){
	LoadEffects.init();
});*/