var officeImages;
var officeImagesIndex;
var officeLoading;

function loadOffice(images, title){
	officeImages = images.split(",");
	officeImagesIndex = -1;
	officeLoading = false;
	$("#officeDisplayBg").css({opacity:0.7});
	
	if(FlashDetect.installed){
		var html = '<embed src="./assets/title.swf" width="500" height="36" wmode="transparent" flashvars="color='+mainColor+'&text='+title+'"></embed>';
		$("#officeDisplayTitle").html(html);
		$("#officeDisplayTitle").css({left:46});
	}
	$("#officeDisplay").css({display:"block",visibility:"hidden",opacity:0});
	if(officeImages.length>0){
		officeChangeImage(1);
		BgOnComplete = officeFadeIn;
	}else{
		officeFadeIn();	
	}
	if(officeImages.length>1){
		addOfficeControllersEvents();
	}else{
		$("#officeControllers").css({display:"none"});
	}
}
function officeFadeIn(){
	$("#officeDisplay").css({visibility:"visible"}).delay(10).animate({opacity:1},350);
}
function officeChangeImage(value){
	if(!officeLoading){
		officeLoading = true;
		officeImagesIndex += value;
		if(officeImagesIndex < 0){
			officeImagesIndex = officeImages.length-1
		}
		if(officeImagesIndex >= officeImages.length){
			officeImagesIndex = 0;	
		} 
		BgOnLoad = resetOfficeLoading;
		changeBg(officeImages[officeImagesIndex]);
	}
}

function resetOfficeLoading(){
	officeLoading = false;
}

function addOfficeControllersEvents(){
	$("#officeControllers span").css({opacity:0.4});
	$("#officeControllers div").css({cursor:"pointer"});
	$("#officeControllers div").mouseover(function(){
		$(this).children("span").stop(true).animate({backgroundColor:mainColor,opacity:0.8},200);
	});
	$("#officeControllers div").mouseout(function(){
		$(this).children("span").stop(true).animate({backgroundColor:"#000000",opacity:0.4},200);
	});
	$("#officeControllers div").click(function(){
		var value = ($(this).attr("id") == "prev") ? -1 : 1;
		officeChangeImage(value);
	});	
	$(document).keyup(function(event) {
  		if (event.which == 37) {
			officeChangeImage(-1);
   		}
		if (event.which == 39) {
			officeChangeImage(1);
   		}
	});
}
var counter = 0;

