// JavaScript Document
function trace(s) {  try { console.log(s) } catch (e) { alert(s) }}; // only for debug

var pageSetUp = function() {
// set up the page
	var contentLeft = $('contentLeft').getCoordinates() ; // returns left top height width right integer numbers
	var contentRight = $('contentRight').getCoordinates() ; // returns left top height width right integer numbers
	var mcgDiff = contentLeft.height - contentRight.height;
	if( mcgDiff < 0 ) $('contentLeft').setStyle('height',contentRight.height) ; else  $('contentRight').setStyle('height',contentLeft.height) ; 

	$('topSlide').setStyles({'overflow':'hidden',height:105});
	$('slider').getElements('img[class=thumbs]').setStyle('opacity',0.7);
//	$('topSlideBG').setStyles({'opacity':'0.7'});


}

function setUpSlimboxSlides() {
	$('slider').getElements('a').slimbox({
		loop: false,
//			initialWidth: 1024,
//			initialHeight: 768,
		overlayOpacity: 0.6,
		overlayFadeDuration: 700,
		imageFadeDuration: 1000,
		resizeDuration: 0,
		captionAnimationDuration: 0,
		resizeTransition: Fx.Transitions.Elastic.easeOut,
		counterText: "slide/diapositiva <strong>{x}</strong> / <strong>{y}</strong>. <br />Arrow/flecha <-- (p) for previous/para anterior <br />Arrow/flecha --> (n) for next/para proxima.<br />esc (q, x) Close/cerrar.",
//		counterText: "This is slide <strong>{x}</strong> of a total of <strong>{y}</strong>.Use left arrow (or p) or right arrow (or n) for previous and next slides. esc (or q) to quit.",
		closeKeys: [27, 88, 67, 81],
		previousKeys: [37, 80, 16],
		nextKeys: [39, 78, 17]
		});
}


function setUpTopSlide () {
var lastTopSlideClicked;
	$('slider').getElements('img[class=thumbs]').each(function(topImage){ //Catches each image
		topImage.addEvent('mouseenter', function(){ //Adds effect to the div, not the a tag
			topImage.setStyle('opacity',1);
		})
		topImage.addEvent('mouseleave', function(){ //Adds effect to the div, not the a tag
			if(!$chk(topImage.get('clicked'))) topImage.setStyle('opacity',0.7);
		})
	});
// topSlide left right movement
	var topSlide = new Scroller('topSlide', {area: 250, velocity: 0.1});
	$('topSlide').addEvent('mouseenter', topSlide.start.bind(topSlide));
	$('topSlide').addEvent('mouseleave', topSlide.start.bind(topSlide));
	topSlide.start();
}



window.addEvent('domready', function() { //here we add functions that fire when the dom is ready.. images probably not ready
//	use the load function otherwise rounded_corners.htc causes problems
	pageSetUp();
});

window.addEvent('load', function() { //here we add functions that fire when the page is ready
//	probably nothing here;
	setUpSlimboxSlides();// remember to set up the slimbox slideshow
	setUpTopSlide() 
});
