var obj =
{
	'data' :
	[
		{
		    'text': slideTxt01,
			'width' : 330
		},
		{
		    'text': slideTxt02,
			'width' : 420
		},
		{
		    'text': slideTxt03,
			'width' : 420
		},
		{
		    'text': slideTxt04,
			'width' : 440
		},
		{
		    'text': slideTxt05,
			'width' : 420
		},
		{
		    'text': slideTxt06,
			'width' : 450
		},
		{
		    'text': slideTxt07,
			'width' : 450
		}
	]
}

var total_rows = obj.data.length;
var rows = 0;
var image_index = 0;
var delay = 2000;

$(document).ready(function()
{
	var zIndex_stack = 7;
	
	$('#slide li').each(function(i, item)
	{
		$(item).css({zIndex : (zIndex_stack - i)});
		
		if (i > 0) { $(item).css({opacity : 0}); }
	});
	setTimeout(function() { fadeImage(delay); }, delay);
	setTimeout(function() { swapText(delay); }, (delay + 1500));
	
	$("#slider-item").easySlider({
								 	auto: false,
									continuous: true,
									controlsShow: true,
									speed: 300,
									numeric: true
								});
	
	// remove slide control text
	$("#controls > li a").html('&nbsp;');
	
	$("#nav-bg").css({opacity: 0.7});
	$("#nav li").eq(6).css({border: 'none'});
	
	$("a[rel='dl']").each(function(i, item)
	{
		$(item).click(function()
		{
			$($(item).attr('href')).slideToggle(200);
		});
	});
	$("a[rel=fancy]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex) + ' / ' + (currentArray.length-2) + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
	 });
});

function fadeImage(delay)
{
	var total_images = $('#slide li').length;
	var current_image = image_index;
	var next_image = image_index == (total_images - 1) ? 0 : image_index + 1;
	
	$('#slide li')
	.eq(current_image)
	.css({opacity : 1})
	.animate({opacity : 0}, 3000);
	
	$('#slide li')
	.eq(next_image)
	.css({opacity : 0})
	.animate({opacity : 1}, 3000, function()
	{
		setTimeout(function() { fadeImage(delay); }, (delay));
		setTimeout(function() { swapText(delay); }, (delay + 1500));
	});
	
	if (image_index < (total_images - 1))
		image_index++
	else
		image_index = 0;
}

function swapText(delay)
{
	rows++;
	rows = rows == total_rows ? 0 : rows;
	
		$("#tag-slide .tag-bg .text").animate({opacity: 0}, 100, function()
		{
			$("#tag-slide .tag-bg .text").html('');
			
			$("#tag-slide .tag-bg").animate({width: obj.data[rows].width + 'px'}, 100, function()
			{
				$("#tag-slide .tag-bg .text").html(obj.data[rows].text);
				
				$("#tag-slide .tag-bg .text").animate({opacity: 1}, 100);
			})
		});
}
