function buildItemInfo ( data ) {
	
	var valueItem	= data.valueItem;
	var itemTitle	= $('#itemDescr p.title');
	var itemDescr	= $('#itemDescr p.descr');
	var itemPricing	= $('#itemInfo');
	var infoWrapper = $('#itemDescr');
	var infoWrapperClass = '';
	if(valueItem) infoWrapperClass = 'valueItem';
	itemTitle.html(data.title);
	itemDescr.html(data.descr);
	itemPricing.html(data.pricingInfo);
	infoWrapper.attr({'class' : infoWrapperClass});
	
}

function buildThemeItem ( data, index ) {
	
	var valueItem	= data.valueItem;
	var itemTitle	= $('#itemDescr p.title');
	var itemDescr	= $('#itemDescr p.descr');
	var itemPricing	= $('#itemInfo');
	var imgSrc		= data.thmSrc;
	var imgClass;
	var imagelink;
	
	if (index == 0) {
		imgClass = "active thm" + index;
	} else {
		imgClass = "thm" + index;
	}

	var infoWrapper = $('#itemDescr');
	var infoWrapperClass = '';
	if(valueItem) infoWrapperClass = 'valueItem';
	
	var preClass;
	var preTitle;
	var preDescr;
	var prePricing;
	
	wrappedThumb = $('<div></div>');
	thumbnail = $('<img>').attr({ src: (themeData.imgPath + imgSrc), "class" : imgClass})
	.hover(
		function(){

			preTitle = itemTitle.html();
			preDescr = itemDescr.html();
			prePricing = itemPricing.html();
			preClass = infoWrapper.attr('class');

			itemTitle.html(data.title);
			itemDescr.html(data.descr);
			itemPricing.html(data.pricingInfo);
			infoWrapper.attr({'class' : infoWrapperClass});
			
			$(this).addClass('hover');
			
		},
		function(){
			
			itemTitle.html(preTitle);
			itemDescr.html(preDescr);
			itemPricing.html(prePricing);
			infoWrapper.attr({'class' : preClass});
			
			$(this).removeClass('hover');
			
		}
	)
	.click(
		function() {
			
			$('#itemThms img.active').removeClass('active');
			$(this).addClass('active');
			
			itemTitle.html(data.title);
			itemDescr.html(data.descr);
			itemPricing.html(data.pricingInfo);
			
			if(data.valueItem) infoWrapperClass = 'valueItem';
			infoWrapper.attr({'class' : infoWrapperClass});
			
			preTitle = itemTitle.html();
			preDescr = itemDescr.html();
			prePricing = itemPricing.html();
			preClass = infoWrapper.attr('class');
			
			buildItemView (data.images);
			buildItemExtra (data.wearThisLook);
			
		}
	);
	
	wrappedThumb.append(thumbnail);
	return wrappedThumb;
}

	// JQ ZOOM SETUP
	
	var jqzOptions = {
		zoomType		: 'reverse',
		showEffect		: 'show',
		fadeinSpeed		: 'slow',
		hideEffect		: 'hide',
		fadeoutSpeed	: 'slow',
		zoomWidth		: 332,
		zoomHeight		: 381,
		xOffset			: 7,
		yOffset			: 0,
		imageOpacity	: 1,
		position		: 'right',
		title			: false,
		lens			: false,
		preload			: 1
		};

function buildItemExtra ( data ) {
	
	var accessorize = $('#accessorize');
	var accessorizeimg = $('<img>').attr({ src: (data.image), 'class' : 'tooltip', 'title' : data.accPrice });
	var workforyou = $('#workforyou');
	
	accessorize.html(data.accCopy);
	workforyou.html(data.workCopy);
	$('#howtoImages').html(accessorizeimg);
	tooltip();
	
}

function buildItemView ( data ) {
	var itemWrapper = $('#itemView div.imageWrapper');
	var count = data.length;
	var itemIndex = 0;
	
	itemWrapper.empty();
	
	do {
		var thumbnail = $('<img>').attr({ src: (themeData.imgPath + data[itemIndex].thmSrc)});
		var linkItem = $('<a></a>').attr("href", (themeData.imgPath + data[itemIndex].lrgSrc)).attr("class", 'view' + itemIndex).attr("alt", data[itemIndex].label);
		linkItem.append(thumbnail);
		itemWrapper.append(linkItem);
		//$('a.view' + itemIndex).jqzoom(jqzOptions);		
		itemIndex ++;
		
	} while ( itemIndex < count );
	
	var label = $('#itemView a:visible').attr('alt');
	$('#itemLabel').html(label);
	
	$('#itemNext').click(function(){
		if ($('#itemView a:last').hasClass('hide')) {
			var label = $('#itemView a').not('.hide').next().attr('alt');
			$('#itemView a').not('.hide').addClass('hide').next().removeClass('hide').jqzoom(jqzOptions);
			$('#itemLabel').html(label);
		}
	});
	
	$('#itemPrev').click(function(){
		if ($('#itemView a:first').hasClass('hide')) {
			var label = $('#itemView a').not('.hide').prev().attr('alt');
			$('#itemView a').not('.hide').addClass('hide').prev().removeClass('hide').jqzoom(jqzOptions);
			$('#itemLabel').html(label);
		}
	});

	if ( count > 1 ) {
		$('#itemNext, #itemPrev').show();	
		}
		
	$('#itemView a').not(':first').addClass('hide')
	$('#itemView a:first').jqzoom(jqzOptions);
	
}

function build_theme_items () {
	
	var themeItemContainer = $('#itemThms');
	var count = themeData.items.length;
	var itemIndex = 0;
	
	themeItemContainer.empty();
	
	do {

		themeItemContainer.append ( buildThemeItem ( themeData.items [itemIndex], itemIndex ));
		itemIndex ++;
		
	} while ( itemIndex < count );
	
	// PREP THE UP & DOWN SLIDER
	$('#itemUp').click(
		function(){
			var displacement = 230;
			var minY = '0px';
			var yPos = themeItemContainer.css('top');
			if (yPos != '0px') themeItemContainer.animate({top: '+=' + displacement + 'px'},{queue:true,duration:500});
		});
	
	$('#itemDown').click(
		function(){
			var displacement = 230;
			var minY = '-0px';
			var maxY = '-' + Math.ceil((count - 3) / 3) * 230 + 'px';
			var yPos = themeItemContainer.css('top');
			if (yPos != minY && yPos != maxY && count > 3) themeItemContainer.animate({top: '-=230px'},{queue:true,duration:500});
		});

	if (  count > 3 ) {
		$('#itemUp, #itemDown').addClass('activated');
	}
	
	buildItemView(themeData.items [0].images);
	buildItemInfo(themeData.items [0]);
	buildItemExtra(themeData.items [0].wearThisLook);
	
}