
/*
 
  Sofa So Good Project (c) All Rights Reserved
 
*/


SLIDESHOW_STARTED=false;
SLIDESHOW_PAUSED=false;
SITE_LANG="ENG";
/*******************************************************/

$(document).ready(function () {
	hidePageElements();
	setTimeout("revealClaim()", 1500);
	setTimeout("revealPageElements()", 4000);	
	initSlideshow(8000);
});

/*********************************************************/

function pullGalleryButton() {
	$("#gallery-button").animate({ 
      		paddingRight:"100px"}, 2000, "easeOutElastic" , releaseGalleryButton);
}

function releaseGalleryButton() {
	$("#gallery-button").animate({ 
      		paddingRight:"0px"}, 2000, "easeOutSine" );
}


function hidePageElements() {
	$("#right-shoulder").hide();
	$("#board-container").hide();
	$("#footer-container").hide();
	$("#header-image").hide();
	$("#claim").hide();
}

function revealPageElements() {
	
	$("#right-shoulder").fadeIn("slow");
	$("#board-container").fadeIn("slow");
	$("#footer-container").fadeIn("slow");
	
}

function revealClaim() {
	$("#claim").fadeIn("slow");
}

function showContent(show) {
	if (show) { 
		$("#section-content").fadeIn("slow");
		$("#board").fadeOut("slow");
		$("#header-image").show("slow");
		pauseSlideshow();
	}
	else {
		$("#content-panel").attr("innerHTML","");
		$("#section-content").fadeOut("slow");
		$("#board").fadeIn("slow");
		if (!SLIDESHOW_STARTED) $("#header-image").hide("slow");
		resumeSlideshow();
	}
	
	showLanguageBar(show);
}


/********* Gallery and Flash *******************/


function initViewer(galleryName) {
	var flashvars = {};
	flashvars.galleryURL = "galleries/gallery_"+galleryName+".xml";
	var params = {};			
	params.allowfullscreen = true;
	params.allowscriptaccess = "always";
	params.bgcolor = "060606";
	swfobject.embedSWF("flash/simpleviewer.swf", "simpleviewer", "100%", "100%", "9.0.124", false,flashvars, params);
		
}

function showViewer(show) {
	
	if (show) $("#flashcontent").fadeIn("slow");
	else {
		
		$("#simpleviewer").empty();
		$("#flashcontent").fadeOut("slow");
	}	
	
}

function showGallery(galleryName, caption) {
	showViewer(true);
	setTimeout("initViewer('"+galleryName+"')", 1000);
	if (caption==null) caption="";
	$("#gallery-caption").attr('innerHTML',caption);
}


/********* generic loading function ****************/


function loadContent(contentName) {
	getPage("section_"+contentName+".html", "#content-panel", refreshLanguage);
	showContent(true);
}


function getPage(pageName, target, callback) {
	$.ajax( {
		type :"POST",
		async :"TRUE",
		dataType :"text/html",
		url :pageName,
		data :"",
    	error: function(){
        	showMessage("Sorry, unable to load the requested content.",target);
    	},
		success : function(response) {
			callbackGetPage(target, response);
			if (callback!=null) callback();
		}
	});
}

function callbackGetPage(target, content) {
	$(target).attr("innerHTML", content);
}

function showMessage(message, target) {
		$(target).attr("innerHTML",message);
}

/**************** LANGUAGE FUNCTIONS ***************************/


function refreshLanguage() {
	
	if (SITE_LANG=="ITA") {
		switchToItalian();
		return;
	}
	if (SITE_LANG=="ENG") {
		switchToEnglish();
		return;
	}
}

function switchToEnglish() {
	$(".lang_it").css("display","none");
	$(".lang_en").css("display","block");
	SITE_LANG="ENG";
}

function switchToItalian() {
	$(".lang_en").css("display","none");
	$(".lang_it").css("display","block");
	SITE_LANG="ITA";
}

function showLanguageBar(show) {
	if (show) $("#lang-bar").fadeIn("slow");
	else $("#lang-bar").fadeOut("slow");
}

/***************************************************************/

/******************** SLIDESHOW *********************************/


function initSlideshow(timeout) {
		loadSlideshow();
		setTimeout("startSlideshow()",timeout);
}

function loadSlideshow() {
	getPage("slideshow.html", "#slideshow-container");
}

function startSlideshow() {
	if (SLIDESHOW_PAUSED) return;
	$("#header-image").show("slow");
	$('#slideshow-container').show();
	SLIDESHOW_STARTED=true;
	$('#slideshow-container').cycle({
		fx: 'fade', 
		speedIn:3000,
		speedOut:1000
	});
}

function pauseSlideshow() {
	SLIDESHOW_PAUSED=true;
	if (SLIDESHOW_STARTED) $('#slideshow-container').cycle('pause');
}

function resumeSlideshow() {
	SLIDESHOW_PAUSED=false;
	if (SLIDESHOW_STARTED) $('#slideshow-container').cycle('resume');
	else startSlideshow();
}

