
if (document.getElementsByTagName)
{
	window.onload = init;
//	window.onresize = handleResize;

	is_ie = navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.indexOf("Opera") == -1;
	
	var vers = navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE ') + 5);
	vers = vers.substring(0, vers.indexOf(';'));
	vers = parseInt(vers, 10);
	
	var is_ie6 = (vers < 7);

	if (is_ie)
	{
		if(is_ie6){
			document.write('<link rel="stylesheet" type="text/css" media="screen" href="../../css/ie/homeie6.css" />');
		}
		document.write('<link rel="stylesheet" type="text/css" media="screen" href="../../css/ie/home.css" />');
	}
}

var resizeChecker;

function init(){


	var destacs = gn.getElementsByClassName(document.getElementById("contente"), "destac", "div");

	var boxes = gn.getElementsByClassName(document.getElementById("contente") , "box", "div");

	var boxesMini = gn.getElementsByClassName(document.getElementById("contente") , "boxMini", "div");

	for(var i = 0; i < boxesMini.length; i++){
		boxes[boxes.length] = boxesMini[i];
	}

	var b;

    for(var i = 0; i < boxes.length; i++){
		b = new Destacado(boxes[i], i);
	}

	for (var i=0; i< destacs.length ; i++ )
	{
		new Over(destacs[i]);
	}

}

function Over(el){
	
	this.el = el;

	var imgsDestac = this.el.getElementsByTagName('img');
	for(var i = 0; i < imgsDestac.length; i++){
		if(imgsDestac[i].className.indexOf('over') > -1){
			this.imgOverDestac = imgsDestac[i];
		}

		if(imgsDestac[i].className.indexOf('out') > -1){
			this.imgOutDestac = imgsDestac[i];
		}
	}


	el.onmouseover = function(){
		this.overCallback()
	}
	el.onmouseout = function(){
		this.outCallback()
	}

	var self = this;

	el.overCallback = function(){
		
		self.showImage();
	}
	
	el.outCallback = function(){
		self.hideImage();
	}
	
}

Over.prototype.showImage = function(){

	if(this.imgOverDestac){
		this.imgOverDestac.style.visibility = 'visible';

		if(this.imgOutDestac){
			this.imgOutDestac.style.visibility = 'hidden';
		}
	}
}

Over.prototype.hideImage = function(){
	if(this.imgOverDestac){
		this.imgOverDestac.style.visibility = 'hidden';

		if(this.imgOutDestac){
			this.imgOutDestac.style.visibility = 'visible';
		}
	}

}


function Destacado(el, count){
	this.el = el;
	
	this.showing = false;
	
	this.obj = 'Destacado'+count;
	
	eval(this.obj+' = this');

	this.p = this.el.getElementsByTagName('p')[0];
	this.p.style.display = 'block';
	this.p.style.height = 'auto';
	this.height = parseInt(this.p.offsetHeight, 10);
	this.p.style.height = '0px';
	this.p.style.overflow = 'hidden';

    if (this.el.className.lastIndexOf('big') > -1) return;
	
	this.p.style.display = 'none';
	
	this.h2 = this.el.getElementsByTagName('h2')[0];
	
	
	var imgs = this.el.getElementsByTagName('img');
	for(var i = 0; i < imgs.length; i++){
		if(imgs[i].className == 'over'){
			this.imgOver = imgs[i];
		}

		if(imgs[i].className == 'out'){
			this.imgOut = imgs[i];
		}
	}
	
	
	if(is_ie && is_ie6){
		if(this.el.className.indexOf('boxMini') > -1){
			var clase = this.el.className.replace('boxMini ','');
		}
		else{
			if(this.el.className.indexOf('box') > -1){
				var clase = this.el.className.replace('box ','');
			}
		}
	    attachEventToElement(this.el, clase);   
	}
	else{

		el.onmouseover = function(){
			this.overCallback()
		}
		el.onmouseout = function(){
			this.outCallback()
		}
	}	
	
	
	var self = this;
	
	el.overCallback = function(){
		self.show();
	}
	
	el.outCallback = function(){
		self.hide();
	}
}

Destacado.prototype.show = function(){
	clearTimeout(this.timer);
	var h = parseInt(this.p.style.height, 10);

	if (h >= this.height / 3) return;
	clearTimeout(this.timer);
	// al hacer rollover en la imagen (si existe una imagen con la class 'over') se cambia la imagen
	if(this.imgOver){
		this.imgOver.style.display = 'block';

		if(this.imgOut){
			this.imgOut.style.display = 'none';
		}
	}

	this.showing = true;
	this.p.style.height = (this.height / 3)+'px';
	

	this.p.style.display = 'block';
	if(this.p.parentNode.className.indexOf('boxMini') > -1){
		this.h2.style.display = 'block';
	}
	else
	{
		if(this.p.parentNode.className.indexOf('box') > -1){
			this.h2.style.display = 'none';
		}
	}
	this.el.style.zIndex = 10;
	this.timer = setTimeout(this.obj+'.loop(true)', 20);
}

Destacado.prototype.hide = function(){
	this.timer = setTimeout(this.obj+'.doHide()', 50);	
}

Destacado.prototype.doHide = function(){

		clearTimeout(this.timer);
		this.showing = false;
		this.el.style.zIndex = 1;
		this.loop(false);

		if(this.imgOver){
		this.imgOver.style.display = 'none';

		if(this.imgOut){
			this.imgOut.style.display = 'block';
		}
	}
}

Destacado.prototype.loop = function(show){
	
	var h = parseInt(this.p.style.height, 10);
	if (show){
			if (h + 5 < this.height){
					this.p.style.height = (h + 5)+'px';
			
					this.timer = setTimeout(this.obj+'.loop(true)', 20);
			
			}
			else
			{
					this.p.style.height = this.height+'px';
			}

		
	}

	else{

		if (h - 10 > 0){

			this.p.style.height = (h - 10)+'px';
			this.timer = setTimeout(this.obj+'.loop(false)', 20);		
		}
		else{
			this.p.style.display = 'none';
			this.h2.style.display = 'block';
		}
		
	}

	
}


/*
function checkResize(){
    if (Box.needResize && !Box.resizing) Box.layout(true);
	
}

function init(){

    var boxes = gn.getElementsByClassName(document.getElementById("content") , "box", "div")

	var boxesMini = gn.getElementsByClassName(document.getElementById("content") , "boxMini", "div")
    
    if (boxes.length < 1) return;
    
    resizeChecker = setInterval('checkResize()', 250);
    
	BoxMini.init();
	Box.init();
	
}
var ttt = 0;
function handleResize(){
    
	//if (!Box.resizing) Box.layout(true);
	Box.needResize = true;
	BoxMini.needResize = true;
}


Box = {
	items:			new Array(),
	marginChecker:	null,
	holder:			null,
	maxH:           0,
	inited:			false,
	needResize:     false,
	resizing:       false	
}

BoxMini = {
	items:			new Array(),
	marginChecker:	null,
	holder:			null,
	maxH:           0,
	inited:			false,
	needResize:     false,
	resizing:       false	
}

Box.init = function(){
	this.holder = document.getElementById("content");
	var boxes = gn.getElementsByClassName(this.holder , "box", "div")
	
	this.marginChecker = document.createElement('div');
	this.marginChecker.style.position = 'absolute';
	this.marginChecker.style.top = 0;
	this.marginChecker.style.left = 0;
	this.holder.appendChild(this.marginChecker);


	for (var i = 0; i < boxes.length; i++){
		this.items[i] = new Destacado(boxes[i]);
	}	
	this.holder.style.height = this.maxH + "px";
	Box.inited = true;
	setTimeout('Box.layout()', 10);
	
}

BoxMini.init = function(){
	this.holder = document.getElementById("content");
	var boxesMini = gn.getElementsByClassName(this.holder , "boxMini", "div")
	
	this.marginChecker = document.createElement('div');
	this.marginChecker.style.top = 0;
	this.marginChecker.style.left = 0;
	this.holder.appendChild(this.marginChecker);


	for (var i = 0; i < boxesMini.length; i++){
		this.items[i] = new Destacado(boxesMini[i]);
	}	
	this.holder.style.height = this.maxH + "px";
	BoxMini.inited = true;
	
}

Box.layout = function(bol){
	if (!this.inited) return;
	this.resizing = true;
	for (var i = 0; i < Box.items.length; i++) Box.items[i].el.style.position = "static";
	
	var marginCheckerPos = gn.getAbsolutePosition(this.marginChecker);
	var pos = new Array();
    
    this.maxH = 0;
    	
	for (var i = 0; i < this.items.length; i++){
		this.items[i].prepareLayout(marginCheckerPos);
	}
	
    this.doLayout()

}


Box.doLayout = function(){

	for (var i = 0; i < this.items.length; i++){
		this.items[i].layout();
	} 
	this.holder.style.height = this.maxH + "px";
	
	this.needResize = false;
	this.resizing = false;	
}

function Destacado(el, pos){
	this.el = el;
	this.pos = pos;
	
	this.showing = false;

	this.parent = el.parentNode;
	
	if(this.el.className.indexOf('boxMini') > -1){
		this.obj = 'boxMini'+BoxMini.items.length;
	}
	else{
		if(this.el.className.indexOf('box') > -1){
			this.obj = 'box'+Box.items.length;
		}
	}

	eval(this.obj+' = this');
	
	this.p = this.el.getElementsByTagName('p')[0];
	this.p.style.display = 'block';
	this.p.style.height = 'auto';
	this.height = parseInt(this.p.offsetHeight, 10);
    if (this.el.className.lastIndexOf('big') > -1) return;
	
	this.p.style.display = 'none';

	
	this.orgHeight = this.el.offsetHeight;

	if(this.el.className.indexOf('boxMini') > -1){
		this.prepareLayout( gn.getAbsolutePosition(BoxMini.marginChecker));
	}
	else{
		if(this.el.className.indexOf('box') > -1){
			this.prepareLayout( gn.getAbsolutePosition(Box.marginChecker));
		}
	}


	
	this.h2 = this.el.getElementsByTagName('h2')[0];
	
	
	var imgs = this.el.getElementsByTagName('img');
	for(var i = 0; i < imgs.length; i++){
		if(imgs[i].className == 'over'){
			this.imgOver = imgs[i];
		}

		if(imgs[i].className == 'out'){
			this.imgOut = imgs[i];
		}
	}

	if (!is_ie) {
		el.onmouseover = function(){
			this.overCallback()
		}
		el.onmouseout = function(){
			this.outCallback()
		}
	}
	else{

		if(this.el.className.indexOf('boxMini') > -1){
		var clase = this.el.className.replace('boxMini ','');
	}
	else{
		if(this.el.className.indexOf('box') > -1){
			var clase = this.el.className.replace('box ','');
		}
	}
	    
	    attachEventToElement(this.el, clase);   
	}
	
	
	
	var self = this;
	
	el.overCallback = function(){
		
		self.show();
	}
	
	el.outCallback = function(){
		self.hide();
	}
	
	
}

Destacado.prototype.prepareLayout = function(offset){
	
	this.pos = gn.getAbsolutePosition(this.el);
	
	this.pos.x -= (offset.x + 6);
	this.pos.y -= (offset.y + 6);

	Box.maxH = Math.max(Box.maxH, this.pos.y + this.height );
	BoxMini.maxH = Math.max(BoxMini.maxH, this.pos.y + this.height );
}

Destacado.prototype.layout = function(){
	this.el.style.top = this.pos.y+'px';
	//this.el.style.left = this.pos.x+'px';	
	if(this.el.className.indexOf('box') > -1){
		this.el.style.position = 'absolute';
	}
	this.parentHeight = this.parent.offsetHeight;
	this.parent.style.height = this.parentHeight + this.orgHeight + 7 +'px';

}





Destacado.prototype.show = function(){

	var h = parseInt(this.p.style.height, 10);
	if (h >= this.height / 3) return;
	clearTimeout(this.timer);
	// al hacer rollover en la imagen (si existe una imagen con la class 'over') se cambia la imagen
	if(this.imgOver){
		this.imgOver.style.display = 'block';

		if(this.imgOut){
			this.imgOut.style.display = 'none';
		}
	}

	this.showing = true;
	this.p.style.height = (this.height / 3)+'px';
	
//	alturaParent = parent.p.style.height+this.p.style.height;
	this.p.style.display = 'block';
	if(this.p.parentNode.className.indexOf('boxMini') > -1){
		this.h2.style.display = 'block';
	}
	else
	{
		if(this.p.parentNode.className.indexOf('box') > -1){
			this.h2.style.display = 'none';
		}
	}
	this.el.style.zIndex = 10;
	this.timer = setTimeout(this.obj+'.loop(true)', 20);
}

Destacado.prototype.hide = function(){

		clearTimeout(this.timer);
		this.showing = false;
		this.el.style.zIndex = 1;
		this.loop(false);

		if(this.imgOver){
		this.imgOver.style.display = 'none';

		if(this.imgOut){
			this.imgOut.style.display = 'block';
		}
	}
}

Destacado.prototype.loop = function(show){
	
	var h = parseInt(this.p.style.height, 10);
	if (show){
			if (h + 5 < this.height){
					this.p.style.height = (h + 5)+'px';
			
					this.timer = setTimeout(this.obj+'.loop(true)', 20);
			
			}
			else
			{
					this.p.style.height = this.height+'px';
					this.parent.style.height = this.parentHeight + this.orgHeight + h - 5 +'px';
			}

		
	}

	else{

		if (h - 10 > 0){

			this.p.style.height = (h - 10)+'px';
			this.timer = setTimeout(this.obj+'.loop(false)', 20);		
		}
		else{
			this.p.style.display = 'none';
			this.h2.style.display = 'block';
			this.parent.style.height = this.parentHeight + this.orgHeight + h +'px';
		}
		
	}

	
}


function rollover($id,$ruta){
	var $imagen = document.getElementById($id);
	$imagen.setAttribute("src",$ruta);
}
*/