// JavaScript Document

if (document.images) {
  preload_image = new Image(25,25); 
  preload_image.src="../images/bg_long.png"; 
}

// load and unload events for secondary pages
// Set thickbox loading image
tb_pathToImage = "../../images/thickbox/loadingAnimation.gif";

$(document).ready(function() {
	// page load
	$('#backleft').fadeIn(1200);
	$('#contentarea').fadeIn(1200);
	$('#contentarea2').fadeIn(1200);
	
	$('a#content-show').click(function() {
		resetPage();
		$('#contentshort').slideUp('slow',function(){
			$('#contentlong').slideDown('slow');
		});
		return false;
	});
});

function drawingBoard() {
	$('#contentarea').fadeOut('slow');
	$('#contentarea2').fadeOut('slow',function(){
		window.location = "../"; 
		$('#backleft').fadeOut('slow');
	});
}

function resetPage() {
	$('#casestudynav').fadeOut('fast');
	$('#main').css("height", "770px");
	$('#container').css("height", "980px");
	$('#container').css("background", "#fff url('../../images/bg_long.png') top left");
	$('#bodyfooter').css("background", "#fff url('../../images/bg_long.png') bottom left");
	$('#contentlong').slideUp('slow', function(){
		$('#contentshort').slideDown('slow');		  
	});									
	$('#casestudynav').fadeIn(2000);
}

function mycarousel_itemLoadCallback(carousel, state)
{
	for (var i = carousel.first; i <= carousel.last; i++) {
		if (carousel.has(i)) {
			continue;
		}

		if (i > mycarousel_itemList.length) {
			break;
		}

		// Create an object from HTML
		var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList[i-1])).get(0);

		// Apply thickbox
		tb_init(item);

		carousel.add(i, item);
	}
};

function mycarousel_getItemHTML(item)
{
	var url_m = item.url.replace(/_s.jpg/g, '_m.jpg');
	if (item.type == 'image') {
		return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="136" height="136" border="0" alt="' + item.title + '" /></a>';
	} else if (item.type == 'video') {
		return '<a class="thickbox" href="' + item.url2 + '" title="' + item.title + '"><img src="' + item.url + '" width="136" height="136" border="0" alt="' + item.title + '" /></a>';
	}
};

jQuery(document).ready(function() {
	jQuery('#gallery').jcarousel({
		size: mycarousel_itemList.length,
		itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
	});
});
