var extrasIndex;
var extrasImages;
var extrasPage;
var extrasPageX;
var extrasPageMemo = 0;
var extrasTotal;
var extrasStatus;
var extrasItemsPerPage = 4;
function initExtras(colors,images){
	var pn = getHistory(-1).split("/");
	var memo = Boolean("/"+pn[1] == $.address.path());
	extrasPage = (memo) ? extrasPageMemo : 0;
	extrasPageX = -1380*extrasPage;
	extrasImages = images.split(","); 
	extrasTotal = Math.ceil(extrasImages.length/extrasItemsPerPage);
	extrasStatus = "ok";
	extrasIndex = extrasPage*extrasItemsPerPage;
	extrasPageMemo = extrasPage;
	//
	$("#extrasList").css({left:extrasPageX});
	changeColors(colors);
	extrasNavEvents();
	extrasNavControl();
	$(".extrasItemText span").css({color:COLOR_1});
	$(".extrasItemOver").css({backgroundColor:COLOR_1,opacity:0});
	$(".extrasItem #image").html("");
	$(".extrasItem").css({visibility:"hidden",opacity:0,backgroundColor:COLOR_2});
	loadExtrasImages();
	$("#pageContent").stop(true).css({visibility:"visible",opacity:0}).delay(0).animate({opacity:1},300);
}
function extrasRemoveMouseEvents(){
	$(".extrasItem").unbind("mouseover");
	$(".extrasItem").unbind("mouseout");	
	$(".extrasItem #image img").unbind("load");	
}
function extrasAddMouseEvents(target){
	$(target).mouseover(function(){
		$(this).children(".extrasItemOver").stop(true).animate({opacity:1},150);
		$("#"+$(this).attr("id")+" .extrasItemText span").stop(true).animate({color:COLOR_2},150);
	});
	$(target).mouseout(function(){
		$(this).children(".extrasItemOver").stop(true).animate({opacity:0},150);
		$("#"+$(this).attr("id")+" .extrasItemText span").stop(true).animate({color:COLOR_1},150);
	});	
}
function loadExtrasImages(){
	if(extrasIndex < (extrasPage*extrasItemsPerPage+extrasItemsPerPage)){
		if($("#extrasItem"+extrasIndex).length > 0){
			$("#extrasItem"+extrasIndex+" #image").html('<img src="'+extrasImages[extrasIndex]+'" />');
			$("#extrasItem"+extrasIndex).css({visibility:"visible"});
			$("#extrasItem"+extrasIndex+" #image img").load(function(){
				if($(this).width() < 689){
					$(this).css({width:689,height:"auto"});
				}
				$("#extrasItem"+extrasIndex).css({visibility:"visible"}).animate({opacity:1},150,function(){
					extrasAddMouseEvents(this);
					if(hitTestPoint($(this),MOUSE_X, MOUSE_Y)){
						$(this).mouseover();
					}
					extrasIndex++;
					loadExtrasImages();
				});
			});
		}else{
			prelaoderVisibility(false);
		}
		/*
		if($("#extrasItem"+extrasIndex+" img").attr("src") == undefined){
			$("#extrasItem"+extrasIndex+" img").attr("src",extrasImages[extrasIndex]);
			$("#extrasItem"+extrasIndex+" img").load(function(){
				$(this).animate({opacity:1},200,function(){
					extrasIndex++;
					loadExtrasImages();	
				});
			});
		}else{
			$("#extrasItem"+extrasIndex+" img").stop(true).animate({opacity:1},200,function(){
				extrasIndex++;
				loadExtrasImages();	
			});
			
		}
		*/
	}else{
		prelaoderVisibility(false);	
	}
}
function extrasNavEvents(){
	if($.address.pathNames()[0] != "curated"){
		navRightClickEvent = extrasChangePage;
		navRightClickParam = 1;
		navLeftClickEvent = extrasChangePage;
		navLeftClickParam = -1;
	}
}
function extrasChangePage(value){
	if(extrasStatus == "ok"){
		prelaoderVisibility(true);
		extrasStatus = "fade";
		extrasPage += value;
		if(extrasPage >= extrasTotal){
			extrasPage = extrasTotal-1;
		}
		if(extrasPage < 0){
			extrasPage = 0;
		}
		extrasNavControl();
		extrasPageX = -1380*extrasPage;
		extrasPageMemo = extrasPage;
		extrasRemoveMouseEvents();
		$("#extrasList").stop(true).animate({opacity:0},100,function(){
			$(this).css({left:extrasPageX}).animate({opacity:1},100,function(){
				extrasStatus="ok";
				extrasIndex = extrasPage*extrasItemsPerPage;
				$(".extrasItem #image").html("");
				$(".extrasItem").css({visibility:"hidden",opacity:0});
				loadExtrasImages();
			});	
		});
	}
}
function extrasNavControl(){
	$("#navRight").css({visibility:"visible"});
	$("#navLeft").css({visibility:"visible"});
	if($.address.pathNames()[0] != "curated"){
		if(extrasPage == extrasTotal-1){
			$("#navRight").css({visibility:"hidden"});
		}
		if(extrasPage == 0){
			$("#navLeft").css({visibility:"hidden"});
		}
	}
}

