/*
 * Class Implementation, by Magic Corneas
 */

Function.prototype.bind = function() {
  var fn = this, args = jQuery.makeArray(arguments), scope = args.shift();
  return function() {
    return fn.apply(scope, args);
  }
}

var Class = function(d) { var c = function() { this.initialize.apply(this, arguments) }; for(var i in d) c.prototype[i] = d[i]; return c };

/*
 * jQuery Custom Select Plugin
 *
 * Copyright (C) 2009 Don NadieN (Betazeta)
 * Licensed under the GPL license:
 * http://www.gnu.org/licenses/gpl.html
 *
 *
 * Version: 0.2
 */
 
jQuery.fn.customSelect = function(options) {
	
	var options 	  = this.get(0).options;
	var container 	= jQuery(document.createElement('div')).addClass('custom_select');
	
	var title	= jQuery(document.createElement('a')).attr('href', '#').text(options[0].text);
	var list	= jQuery(document.createElement('ul')).css('display', 'none');
	
	container.click(function(e) {
		e.stopPropagation();
	});

	title.click(function() {
		jQuery(this).next('ul').slideToggle('fast');
		jQuery(this).toggleClass('focus').focus();
		return false;
	});

	jQuery(document).click(function() {
		title.removeClass('focus').next('ul').slideUp('fast');
	});

	for(var i=1; i < options.length; i++) {
		var item = jQuery('<li><a href="' + options[i].value + '">' + options[i].text + ' </a></li>');
		item.addClass(options[i].text.replace(' ', '_').toLowerCase());
		list.append(item);
	}
	
	this.after(container.append(title).append(list)).remove();
	
}

/*
 * jQuery Custom Select Plugin 2 xD
 *
 * Copyright (C) 2009 Betazeta
 * Licensed under the GPL license:
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 0.2 by Claudio Lizana
 * Version: 0.21 by Felipe Figueroa
 *
 */
 
jQuery.fn.dropDown = function() {
  return this.each(function() {

	  jQuery(this).children('li').each(function(i) {
		  var item = jQuery(this);
		  if(item.hasClass('active')) {
			  item.parent().css('top', -1 * i * 24);
			
			  item.click(function() {
			    if(item.parent().hasClass('open')) {
			      jQuery(document).trigger('click');
			      return;
			    }
			    
				  jQuery(this).parent().children('li').not('li.active').css({'visibility': 'visible', 'z-index':'200'});
				  jQuery(this).parent().addClass('open');
			  });
			
		  } else {
			  item.css({'visibility': 'hidden', 'z-index':'-1000'});
		  }
	  });

	  jQuery(this).parent().click(function(e) {
		  e.stopPropagation();
	  });

	  var ref = jQuery(this);	

	  jQuery(document).click(function() {
		  ref.children('li').not('li.active').css({'visibility': 'hidden', 'z-index':'-1000'});
		  ref.removeClass('open');
	  });


  	jQuery(this).trigger('mouseleave');
  	
  });
}

/*
 * CSS cBrowser Ss
 *
 * Copyright (C) 2008 Rafael Lima
 * Licence: http://creativecommons.org/licenses/by/2.5/
 *
 * Inspired on 37Signals Cross Browser Selectors
 *
 * Version: 0.3.1
 */

function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

/*
 * Equal Heights
 *
 * Copyright (C) 2008 Rob Glazebrook
 *
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Version: 1.0
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css('overflow','visible');
		});
	}
})(jQuery);

/*
 * idTabs
 *
 * Copyright (C) 2008 Sean Catchpole
 *
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Version: 2.2
 */
 
(function(){var dep={"jQuery":"http://code.jquery.com/jquery-latest.min.js"};var init=function(){(function($){$.fn.idTabs=function(){var s={};for(var i=0;i<arguments.length;++i){var a=arguments[i];switch(a.constructor){case Object:$.extend(s,a);break;case Boolean:s.change=a;break;case Number:s.start=a;break;case Function:s.click=a;break;case String:if(a.charAt(0)=='.')s.active=a;else if(a.charAt(0)=='!')s.event=a;else s.start=a;break;}}
if(typeof s['return']=="function")
s.change=s['return'];return this.each(function(){$.idTabs(this,s);});}
$.idTabs=function(tabs,options){var meta=($.metadata)?$(tabs).metadata():{};var s=$.extend({},$.idTabs.settings,meta,options);if(s.active.charAt(0)=='.')s.active=s.active.substr(1);if(s.event.charAt(0)=='!')s.event=s.event.substr(1);if(s.start==null)s.start=-1;var showId=function(){if($(this).is('.'+s.active))
return s.change;var id="#"+this.href.split('#')[1];var aList=[];var idList=[];$("a",tabs).each(function(){if(this.href.match(/#/)){aList.push(this);idList.push("#"+this.href.split('#')[1]);}});if(s.click&&!s.click.apply(this,[id,idList,tabs,s]))return s.change;for(i in aList)$(aList[i]).removeClass(s.active);for(i in idList)$(idList[i]).hide();$(this).addClass(s.active);$(id).show();return s.change;}
var list=$("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId);list.each(function(){$("#"+this.href.split('#')[1]).hide();});var test=false;if((test=list.filter('.'+s.active)).length);else if(typeof s.start=="number"&&(test=list.eq(s.start)).length);else if(typeof s.start=="string"&&(test=list.filter("[href*='#"+s.start+"']")).length);if(test){test.removeClass(s.active);test.trigger(s.event);}
return s;}
$.idTabs.settings={start:0,change:false,click:null,active:".active",event:"!click"};$.idTabs.version="2.2";$(function(){$(".idTabs").idTabs();});})(jQuery);}
var check=function(o,s){s=s.split('.');while(o&&s.length)o=o[s.shift()];return o;}
var head=document.getElementsByTagName("head")[0];var add=function(url){var s=document.createElement("script");s.type="text/javascript";s.src=url;head.appendChild(s);}
var s=document.getElementsByTagName('script');var src=s[s.length-1].src;var ok=true;for(d in dep){if(check(this,d))continue;ok=false;add(dep[d]);}if(ok)return init();add(src);})();

/*
 * eplAdvertisement
 *
 * ePlanning AdServer Deployment
 *
 */

var sitio_id = "4966";
var eplrnd = (new String(Math.random())).substring(2,8) + (((new Date()).getTime()) & 262143);
var sw = (self.innerWidth ? self.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body ? document.body.clientWidth : "");
var sh = (self.innerHeight ? self.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body ? document.body.clientHeight : "");
var wh = (sw && sh) ? (sw.toString(16) + "x" + sh.toString(16)) : "";

function eplAD(espacio_id) {
	var ad = '<scri' + 'pt language="JavaScript" type="text/javascript" src="http://ads.us.e-planning.net/eb/3/' + sitio_id + '/' + espacio_id + '?o=j&rnd=' + eplrnd + (wh ? ('&n=' + wh) : '') + '"></scri' + 'pt>';
	document.write(ad);
}


/* Google Search Helper */

var google = {

  search: function(keywords, pages) {

    for(var i=0; i < pages; i++) {
      var url = "http://www.google.com/uds/GwebSearch?v=1.0&rsz=large&callback=google.onResults&q=" + encodeURIComponent(keywords) + "&start=" + (i * 8);
      jQuery.getScript(url);
    }
    
  },
  
  onResults: function(data) {
    
    if(data.responseData.results.length == 0) {
      jQuery('#search_empty').css('display', 'block');
    } 
    
	  for(var i=0; i < data.responseData.results.length; i++) {
		  var item = data.responseData.results[i];
		
		  var isForum = (item.url.indexOf('http://www.chw.net/foro') >= 0);
		
		  var title = isForum ? item.title.replace('- Foros de CHW', '') : item.title.replace('| CHW', '');
		  var label = isForum ? 'Foro CHW' : 'Blog CHW';
		  var klass = isForum ? 'foro' : 'blog';
		
		  title = title.substring(0, 1).toUpperCase() + title.substring(1);  /* Capitalize 1st character */
		
		  jQuery('#search_results').append('<a href="' + item.url + '">' + title + '</a> <em class="' + klass + '">' + label + '</em><br />');
		  jQuery('#search_results').append('<p>' + item.content + '</p>');
	  }
	
	}
	
};


var Ticker = new Class({
  height:  null,
  current: 0,
  timer:   null,

  initialize: function(selector) {
    this.element = jQuery(selector);
    this.height  = this.element.height();
  },
  
  next: function(pause) {
    var child = this.element.children();
    var top   = parseInt(child.css('top')) || 0;
    
    if(top - this.height <= child.height() * -1)
      top = this.height;

    child.animate({'top': top - this.height});
    
    if(pause) clearInterval(this.timer);
  },
  
  prev: function(pause) {
    var child = this.element.children();
    var top   = parseInt(child.css('top')) || 0;
        
    if(top >= 0)
      top = child.height() * -1;
    
    child.animate({'top': top + this.height});
    
    if(pause) clearInterval(this.timer);
  },
  
  start: function() {
    this.timer = setInterval(this.next.bind(this), 3000);
  }

});

/*
 *
 * pngFix for IE6
 * 
 */

var DD_belatedPNG = {

	ns: 'DD_belatedPNG',
	imgSize: {},
	
	createVmlNameSpace: function() { /* enable VML */
		if (document.namespaces && !document.namespaces[this.ns]) {
		  document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml');
		}
		if (window.attachEvent) {
			window.attachEvent('onbeforeunload', function() {
				DD_belatedPNG = null;
			});
		}
	},
	
	createVmlStyleSheet: function() { /* style VML, enable behaviors */
		/*
			Just in case lots of other developers have added
			lots of other stylesheets using document.createStyleSheet
			and hit the 31-limit mark, let's not use that method!
			further reading: http://msdn.microsoft.com/en-us/library/ms531194(VS.85).aspx
		*/
		var style = document.createElement('style');
		document.documentElement.firstChild.insertBefore(style, document.documentElement.firstChild.firstChild);
		var styleSheet = style.styleSheet;
		styleSheet.addRule(this.ns + '\\:*', '{behavior:url(#default#VML)}');
		styleSheet.addRule(this.ns + '\\:shape', 'position:absolute;');
		styleSheet.addRule('img.' + this.ns + '_sizeFinder', 'behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;'); /* large negative top value for avoiding vertical scrollbars for large images, suggested by James O'Brien, http://www.thanatopsic.org/hendrik/ */
		this.styleSheet = styleSheet;
	},
	
	readPropertyChange: function() {
		var el = event.srcElement;
		if (event.propertyName.search('background') != -1 || event.propertyName.search('border') != -1) {
			DD_belatedPNG.applyVML(el);
		}
		if (event.propertyName == 'style.display') {
			var display = (el.currentStyle.display == 'none') ? 'none' : 'block';
			for (var v in el.vml) {
				el.vml[v].shape.style.display = display;
			}
		}
		if (event.propertyName.search('filter') != -1) {
			DD_belatedPNG.vmlOpacity(el);
		}
	},
	
	vmlOpacity: function(el) {
		if (el.currentStyle.filter.search('lpha') != -1) {
			var trans = el.currentStyle.filter;
			trans = parseInt(trans.substring(trans.lastIndexOf('=')+1, trans.lastIndexOf(')')), 10)/100;
			el.vml.color.shape.style.filter = el.currentStyle.filter; /* complete guesswork */
			el.vml.image.fill.opacity = trans; /* complete guesswork */
		}
	},
	
	handlePseudoHover: function(el) {
		setTimeout(function() { /* wouldn't work as intended without setTimeout */
			DD_belatedPNG.applyVML(el);
		}, 1);
	},
	
	/**
	* This is the method to use in a document.
	* @param {String} selector - REQUIRED - a CSS selector, such as '#doc .container'
	**/
	fix: function(selector) {
		var selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */
		for (var i=0; i<selectors.length; i++) {
			this.styleSheet.addRule(selectors[i], 'behavior:expression(DD_belatedPNG.fixPng(this))'); /* seems to execute the function without adding it to the stylesheet - interesting... */
		}
	},
	
	applyVML: function(el) {
		el.runtimeStyle.cssText = '';
		this.vmlFill(el);
		this.vmlOffsets(el);
		this.vmlOpacity(el);
		if (el.isImg) {
			this.copyImageBorders(el);
		}
	},
	
	attachHandlers: function(el) {
		var self = this;
		var handlers = {resize: 'vmlOffsets', move: 'vmlOffsets'};
		if (el.nodeName == 'A') {
			var moreForAs = {mouseleave: 'handlePseudoHover', mouseenter: 'handlePseudoHover', focus: 'handlePseudoHover', blur: 'handlePseudoHover'};
			for (var a in moreForAs) {
				handlers[a] = moreForAs[a];
			}
		}
		for (var h in handlers) {
			el.attachEvent('on' + h, function() {
				self[handlers[h]](el);
			});
		}
		el.attachEvent('onpropertychange', this.readPropertyChange);
	},
	
	giveLayout: function(el) {
		el.style.zoom = 1;
		if (el.currentStyle.position == 'static') {
			el.style.position = 'relative';
		}
	},
	
	copyImageBorders: function(el) {
		var styles = {'borderStyle':true, 'borderWidth':true, 'borderColor':true};
		for (var s in styles) {
			el.vml.color.shape.style[s] = el.currentStyle[s];
		}
	},
	
	vmlFill: function(el) {
		if (!el.currentStyle) {
			return;
		} else {
			var elStyle = el.currentStyle;
		}
		for (var v in el.vml) {
			el.vml[v].shape.style.zIndex = elStyle.zIndex;
		}
		el.runtimeStyle.backgroundColor = '';
		el.runtimeStyle.backgroundImage = '';
		var noColor = (elStyle.backgroundColor == 'transparent');
		var noImg = true;
		if (elStyle.backgroundImage != 'none' || el.isImg) {
			if (!el.isImg) {
				el.vmlBg = elStyle.backgroundImage;
				el.vmlBg = el.vmlBg.substr(5, el.vmlBg.lastIndexOf('")')-5);
			}
			else {
				el.vmlBg = el.src;
			}
			var lib = this;
			if (!lib.imgSize[el.vmlBg]) { /* determine size of loaded image */
				var img = document.createElement('img');
				lib.imgSize[el.vmlBg] = img;
				img.className = lib.ns + '_sizeFinder';
				img.runtimeStyle.cssText = 'behavior:none; position:absolute; left:-10000px; top:-10000px; border:none;'; /* make sure to set behavior to none to prevent accidental matching of the helper elements! */
				img.attachEvent('onload', function() {
					this.width = this.offsetWidth; /* weird cache-busting requirement! */
					this.height = this.offsetHeight;
					lib.vmlOffsets(el);
				});
				img.src = el.vmlBg;
				img.removeAttribute('width');
				img.removeAttribute('height');
				document.body.insertBefore(img, document.body.firstChild);
			}
			el.vml.image.fill.src = el.vmlBg;
			noImg = false;
		}
		el.vml.image.fill.on = !noImg;
		el.vml.image.fill.color = 'none';
		el.vml.color.shape.style.backgroundColor = elStyle.backgroundColor;
		el.runtimeStyle.backgroundImage = 'none';
		el.runtimeStyle.backgroundColor = 'transparent';
	},
	
	/* IE can't figure out what do when the offsetLeft and the clientLeft add up to 1, and the VML ends up getting fuzzy... so we have to push/enlarge things by 1 pixel and then clip off the excess */
	vmlOffsets: function(el) {
		var thisStyle = el.currentStyle;
		var size = {'W':el.clientWidth+1, 'H':el.clientHeight+1, 'w':this.imgSize[el.vmlBg].width, 'h':this.imgSize[el.vmlBg].height, 'L':el.offsetLeft, 'T':el.offsetTop, 'bLW':el.clientLeft, 'bTW':el.clientTop};
		var fudge = (size.L + size.bLW == 1) ? 1 : 0;
		
		/* vml shape, left, top, width, height, origin */
		var makeVisible = function(vml, l, t, w, h, o) {
			vml.coordsize = w+','+h;
			vml.coordorigin = o+','+o;
			vml.path = 'm0,0l'+w+',0l'+w+','+h+'l0,'+h+' xe';
			vml.style.width = w + 'px';
			vml.style.height = h + 'px';
			vml.style.left = l + 'px';
			vml.style.top = t + 'px';
		};
		makeVisible(el.vml.color.shape, (size.L + (el.isImg ? 0 : size.bLW)), (size.T + (el.isImg ? 0 : size.bTW)), (size.W-1), (size.H-1), 0);
		makeVisible(el.vml.image.shape, (size.L + size.bLW), (size.T + size.bTW), (size.W), (size.H), 1);
		
		var bg = {'X':0, 'Y':0};
		var figurePercentage = function(axis, position) {
			var fraction = true;
			switch(position) {
				case 'left':
				case 'top':
					bg[axis] = 0;
					break;
				case 'center':
					bg[axis] = .5;
					break;
				case 'right':
				case 'bottom':
					bg[axis] = 1;
					break;
				default:
					if (position.search('%') != -1) {
						bg[axis] = parseInt(position)*.01;
					}
					else {
						fraction = false;
					}
			}
			var horz = (axis == 'X');
			bg[axis] = Math.ceil(fraction ? ( (size[horz?'W': 'H'] * bg[axis]) - (size[horz?'w': 'h'] * bg[axis]) ) : parseInt(position));
			if (bg[axis] == 0) {
				bg[axis]++;
			}
		};
		for (var b in bg) {
			figurePercentage(b, thisStyle['backgroundPosition'+b]);
		}
		
		el.vml.image.fill.position = (bg.X/size.W) + ',' + (bg.Y/size.H);
		
		var bgR = thisStyle.backgroundRepeat;
		var dC = {'T':1, 'R':size.W+fudge, 'B':size.H, 'L':1+fudge}; /* these are defaults for repeat of any kind */
		var altC = { 'X': {'b1': 'L', 'b2': 'R', 'd': 'W'}, 'Y': {'b1': 'T', 'b2': 'B', 'd': 'H'} };
		if (bgR != 'repeat') {
			var c = {'T':(bg.Y), 'R':(bg.X+size.w), 'B':(bg.Y+size.h), 'L':(bg.X)}; /* these are defaults for no-repeat - clips down to the image location */
			if (bgR.search('repeat-') != -1) { /* now let's revert to dC for repeat-x or repeat-y */
				var v = bgR.split('repeat-')[1].toUpperCase();
				c[altC[v].b1] = 1;
				c[altC[v].b2] = size[altC[v].d];
			}
			if (c.B > size.H) {
				c.B = size.H;
			}
			el.vml.image.shape.style.clip = 'rect('+c.T+'px '+(c.R+fudge)+'px '+c.B+'px '+(c.L+fudge)+'px)';
		}
		else {
			el.vml.image.shape.style.clip = 'rect('+dC.T+'px '+dC.R+'px '+dC.B+'px '+dC.L+'px)';
		}
	},
	
	fixPng: function(el) {
		el.style.behavior = 'none';
		if (el.nodeName == 'BODY' || el.nodeName == 'TD' || el.nodeName == 'TR') { /* elements not supported yet */
			return;
		}
		el.isImg = false;
		if (el.nodeName == 'IMG') {
			if(el.src.toLowerCase().search(/\.png$/) != -1) {
				el.isImg = true;
				el.style.visibility = 'hidden';
			}
			else {
				return;
			}
		}
		else if (el.currentStyle.backgroundImage.toLowerCase().search('.png') == -1) {
			return;
		}
		var lib = DD_belatedPNG;
		el.vml = {color: {}, image: {}};
		var els = {shape: {}, fill: {}};
		for (var r in el.vml) {
			for (var e in els) {
				var nodeStr = lib.ns + ':' + e;
				el.vml[r][e] = document.createElement(nodeStr);
			}
			el.vml[r].shape.stroked = false;
			el.vml[r].shape.appendChild(el.vml[r].fill);
			el.parentNode.insertBefore(el.vml[r].shape, el);
		}
		el.vml.image.shape.fillcolor = 'none'; /* Don't show blank white shapeangle when waiting for image to load. */
		el.vml.image.fill.type = 'tile'; /* Ze magic!! Makes image show up. */
		el.vml.color.fill.on = false; /* Actually going to apply vml element's style.backgroundColor, so hide the whiteness. */
		
		lib.attachHandlers(el);
		
		lib.giveLayout(el);
		lib.giveLayout(el.offsetParent);
		
		/* set up element */
		lib.applyVML(el);
	}
	
};
try {
	document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
} catch(r) {}
DD_belatedPNG.createVmlNameSpace();
DD_belatedPNG.createVmlStyleSheet();

DD_belatedPNG.fix('.pngbg, img.pngimg');


