
var callback2;

function setMenu()
{
	var menu = $$("#menu .item");
	var fx = new Fx.Elements(menu, {wait: false, duration: 800, transition: Fx.Transitions.Quint.easeOut});
	menu.each(function(item, i) {
		item.setStyle('background-color', '#323431');
		item.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = { 'background-color':'#434542' }
			menu.each(function(other, j) {
				if(i != j) {
					var c = other.getStyle("background-color");
					if(c != '#323431') o[j] = { 'background-color': '#323431' };
				}
			});
			fx.start(o);
		});
	});
	 
	$("menu").addEvent("mouseleave", function(event) {
		var o = {};
		menu.each(function(item, i) {
			o[i] = { 'background-color': '#323431'};
		});
		fx.start(o);
	})
}

function setSubMenu()
{

	var accordion = new Accordion('h1', 'div.atStart', {
		opacity: false,
		show:0
	}, $('nav'));
	
	var acTitles = $ES('h1','nav');
	acTitles.each( function(item,i) {
		item.addEvent("click", function(event) {
			event = new Event(event);
			$('nav').fireEvent( 'scroll', event, 500 );
		});
	} );
	
	var menu = $ES('a.title','nav');
	var fx = new Fx.Elements(menu, {wait: false, duration: 800, transition: Fx.Transitions.Quint.easeOut});
	menu.each(function(item, i) {
		item.setStyle('color', '#aaaaaa');
		item.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = { 'color':'#F07830' }
			menu.each(function(other, j) {
				if(i != j) {
					var c = other.getStyle("color");
					if(c != '#aaaaaa') o[j] = { 'color': '#aaaaaa' };
				}
			});
			fx.start(o);
		});
		item.addEvent("mouseleave", function(event) {
			var o = {};
			menu.each(function(item, i) {
				o[i] = { 'color': '#aaaaaa'};
			});
			fx.start(o);
		});
	});
	
	var prods = $ES('div.tire','nav');
	var fx2 = new Fx.Elements(prods, {wait: false, duration: 300, transition: Fx.Transitions.Quint.easeOut});
	prods.each(function(item, i) {
		item.setStyle('border-left', '10px solid #F07830');
		item.setStyle('border-left-width', '0px');
		item.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = { 'border-left-width':'10px' }
			prods.each(function(other, j) {
				if(i != j) {
					var c = other.getStyle("border-width");
					if(c != '0px') o[j] = { 'border-left-width': '0px' };
				}
			});
			fx2.start(o);
		});
		item.addEvent("mouseleave", function(event) {
		var o = {};
		prods.each(function(item, i) {
			o[i] = { 'border-left-width': '0px'};
		});
		fx2.start(o);
		})
	});
	
}

function checkResolution(  )
{
	var sz = $('main').getSize().size;
	if( window.getWidth() < sz.x || window.getHeight() < sz.y )
	{
		var el = new Element( 'link', { rel:'stylesheet', type:'text/css', href:'style/layout800.css' } );
		el.injectInside( $('main') );
		$('info').getChildren().each( function(item, i) {
			if( item.getTag() == 'img' ) {
				var src= item.getProperty('src');
				item.setProperty( 'src', "." + src.substr(2,src.length-6) + "_800" + src.substr(src.length-4) );
			}
		});
		
	}
}

function needScroll( obj )
{
	var sz = obj.getSize();
	return (sz.scrollSize.y > sz.size.y);
}

function setScrolls()
{
	
	$('nav').addClass( 'noscroll' );
	if( !needScroll( $('nav') ) )
		return;
	else
		$('nav').addClass( 'withscroll' );

	$('navscrolls').setOpacity(1);
	
	var els = [ $('navup'), $('navdown') ];
	var fx = new Fx.Elements(els, {wait: false, duration: 800, transition: Fx.Transitions.Quint.easeOut});
	els.each(function(item, i) {
		item.setStyle('background-color', '#000000');
		item.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = { 'background-color':'#434542' }
			els.each(function(other, j) {
				if(i != j) {
					var c = other.getStyle("background-color");
					if(c != '#000000') o[j] = { 'background-color': '#000000' };
				}
			});
			fx.start(o);
		});
	});
	 
	$('navscrolls').addEvent("mouseleave", function(event) {
		var o = {};
		els.each(function(item, i) {
			o[i] = { 'background-color': '#000000'};
		});
		fx.start(o);
	})

	var scroll = new Fx.Scroll( $('nav'), {
		wait: false,
		duration: 1000,
		offset: {'x': 0, 'y': 0},
		transition: Fx.Transitions.Quad.easeOut
	});
		
	els[0].addEvent( 'mousedown', function() {
		var sz = $('nav').getSize();
		if( sz.scroll.y-80 > 0 )
			scroll.scrollTo( 0, sz.scroll.y-80 );
		else
			scroll.scrollTo( 0, 0 );
	});	
	
	els[1].addEvent( 'mousedown', function() {
		var sz = $('nav').getSize();
		if( sz.scroll.y+sz.size.y+80 < sz.scrollSize.y )
			scroll.scrollTo( 0, sz.scroll.y+80 );
		else
			scroll.scrollTo( 0, sz.scrollSize.y-sz.size.y );
	});

	$('nav').addEvent('mousewheel', function(event) {
		event = new Event(event);
		if (event.wheel == 1) 
			els[0].fireEvent( 'mousedown', event, 100 );
		if( event.wheel == -1 ) 
			els[1].fireEvent( 'mousedown', event, 100 );
	} );
	
	$('nav').addEvent( 'scroll', function() {
		var sz = $('nav').getSize();
		var ad = $E('img', 'navdown');
		var au = $E('img', 'navup');
		if( sz.scroll.y+sz.size.y < sz.scrollSize.y ) {
			if( ad.getProperty( 'src' )!='img/ad.png' ) 
				ad.setProperty( 'src', 'img/ad.png' );
		}
		else
		{
			if( ad.getProperty( 'src' )!='img/anod.png' ) 
				ad.setProperty( 'src', 'img/anod.png' );
		}
		if( sz.scroll.y > 0 ) {
			if( au.getProperty( 'src' )!='img/au.png' ) 
				au.setProperty( 'src', 'img/au.png' );
		}
		else
		{
			if( au.getProperty( 'src' )!='img/anou.png' ) 
				au.setProperty( 'src', 'img/anou.png' );
		}
		if( window.ie && !window.ie7 ) {
			ad.setStyles({ "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + ad.src + "', sizingMethod='scale')"} );
			ad.setProperty( 'src', 'img/spacer.png' );
			au.setStyles({ "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + au.src + "', sizingMethod='scale')"} );
			au.setProperty( 'src', 'img/spacer.png' );
		}
	} );
	
}

function setScroll2() 
{
	$('datos').setStyle( 'height', $('info').getSize().size.y-($('caracteristicas').getSize().size.y+35)+'px' );
	$('datos_texto').setStyle( 'height', $('info').getSize().size.y-($('caracteristicas').getSize().size.y+60)+'px' );
	if( needScroll( $('datos_texto') ) )
	{
		$('datosscroll').setStyle( 'height', $('info').getSize().size.y-($('caracteristicas').getSize().size.y+50)+'px' );
		$('datosscroll').setOpacity(1);
		new VScrollBar( 'datos_texto', 'datosscroll' );
	}
};

function setEmpresaScroll()
{
	new VScrollBar( 'texto_empresa', 'empresascroll' );
}

window.addEvent('domready', function(){

	setMenu();
	setSubMenu();
	
	checkResolution();
	
} );

window.addEvent( 'load', function() {
	if( $defined(callback) )
		callback();
	if( $defined(callback2) )
		callback2();
} );

function derecho(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 2 || e.which == 3))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 3 || event.button == 2)) {
alert("Foto perteneciente a TVGT S.A., todos los derechos reservados.");
return false;
}
return true;
}
document.onmousedown=derecho;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=derecho;


