// Settings
var imagesPerPage = 4;
var pageHeight = 224;

////////////////////////////////////

var imageObjs = new Array();
parseImageObjects();

if(imageObjs.length > 0) {
	var imageCount = imageObjs.length;
	var thumbPages = Math.ceil(imageCount / imagesPerPage) - 1;
	var currentPage = 0;
	
	// Hide html data objects
	$('#br_objects').hide();
	
	// Populate preview area
	populatePreviewArea(imageObjs);
	
	// Populate initial item
	populateStage(imageObjs[0]);
	
	// Give up arrow its functionality
	$("#br_stage .br_preview .br_up").click(function() {
		if(currentPage > 0) {
		//	$('#br_stage .br_preview .br_thumbs').animate({
		//		top: (--currentPage * pageHeight * -1)
		//	});
		}
	});
	
	// Give down arrow its functionality
	$("#br_stage .br_preview .br_down").click(function() {
		if(currentPage < thumbPages) {
		//	$('#br_stage .br_preview .br_thumbs').animate({
		//		top: (++currentPage * pageHeight * -1)
		//	});
		}
	});
}
else 
	$('#br_stage').hide();

function parseImageObjects() {
	$('#br_objects .br_object').each(function() {
		imageObjs.push({
			thumbURL: $(this).find('.br_image a img').attr('src'),
			imageURL: $(this).find('.br_image a').attr('href'),
			title: $(this).find('.br_title').html(),
			description: $(this).find('.br_description').html()
		});
	});
}

function populatePreviewArea(objs) {
	for(var i=0; i<objs.length; i++)
		$('#br_stage .br_preview .br_thumbs').append('<span><a href="#" onclick="populateStageWithIndex(\'' + i + '\');return false;"><img src="' + objs[i].thumbURL + '" alt="" width="50" height="50" /></a></span>');
}

function populateStageWithIndex(idx) {
	populateStage(imageObjs[idx]);
}

function populateStage(obj) {
	var fadeSpeed = 250;
	
	var stage = $('#br_stage .br_info');
	stage.find('.br_image').fadeOut(fadeSpeed, function() {
		$(this).html('<img src="' + obj.imageURL + '" alt="" />').fadeIn(fadeSpeed);
	});
	stage.find('.br_title').fadeOut(fadeSpeed, function() {
		$(this).html(obj.title).fadeIn(fadeSpeed);
	});
	stage.find('.br_description').fadeOut(fadeSpeed, function() {
		$(this).html(obj.description).fadeIn(fadeSpeed);
	});
}

window.onload = (function(){try{  
	$("#br_stage_wrap").hide();
}catch(e){}});
