// flash functions


// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 115;

var currentBaby = 0;

function getConnectedHomeFlash(babiesStr, alternateContent) {
	if (typeof AC_FL_RunContent != 'function' || typeof DetectFlashVer != 'function') {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {  // if we've detected an acceptable version
			// embed the flash movie
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
				'width', '400',
				'height', '192',
				'src', projectUrl+'/media/howchet/flash/slideshow',
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'transparent',
				'devicefont', 'false',
				'id', 'slideshow',
				'bgcolor', '#ffffff',
				'name', 'slideshow',
				'menu', 'true',
				'allowScriptAccess','sameDomain',
				'allowFullScreen','false',
				'movie', projectUrl+'/media/howchet/flash/slideshow',
				'salign', '',
				'flashVars','babies='+babiesStr+'&confFile='+projectUrl+'/media/lang/flash/conf.cfg'
				); //end AC code
		} else {  // flash is too old or we can't detect the plugin
			/*var alternateContent = 'Alternate HTML content should be placed here.'
				+ 'This content requires the Adobe Flash Player.'
				+ '<a href=http://www.macromedia.com/go/getflash/>Get Flash</a>';*/
			document.write(alternateContent);  // insert non-flash content
		}
	}
}


function right() {
	try{
		getFlash('slideshow').right();
	} catch(e) {}

}
function left() {
	try{
		getFlash('slideshow').left();
	} catch(e) {}
}

function setCurrentBaby(ind) {
	currentBaby = ind;
	$('babyName').innerHTML = nameTab[currentBaby];
}



var healthrecord	= {
	oldLi			: null,
	oldClassName 	: null,
	init			: function() {

		if($('healthrecord') !== null && $('healthrecord').innerHTML !== '') {

			$$('#healthrecord li').each(function(li, i) {
				li.observe('mouseover', function(event) {

					$('healthrecord').className	= 'style-' + li.className;
					$('healthrecord').down('li', healthrecord.oldLi).className = healthrecord.oldClassName;

					healthrecord.oldLi = i;
					healthrecord.oldClassName = li.className;

					li.className = li.className + ' hover';
				});
			});

			healthrecord.oldLi = 0;
			healthrecord.oldClassName = $('healthrecord').down('li', 0).className;
			$('healthrecord').down('li', 0).className = $('healthrecord').down('li', 0).className + ' hover';
		}
	}
}


function updateHeader(object) {
	if(object.playerCreditHeader != undefined) {
		var element = document.getElementById('playerCreditHeader');
		element.innerHTML = object.playerCreditHeader;
	}

	hideCurrentBox();
}

// Refresh a player product content in its list
function updatePlayerProductInList(object) {
	if(object.quantity !== undefined && object.reloadPlayerProduct !== undefined) {
		var product = object.reloadPlayerProduct.split('-');
		if(product[0] !== undefined && product[1] !== undefined) {
			Action.updateProductInList(product[0], product[1], object.qNameProduct, object.quantity);
		}
	}
}

var GetProductDetailAjax = Class.create();
GetProductDetailAjax.prototype = {

	id: 'productBox',
	page: projectUrl +'/member/product/prepare/getDetail',

	execute: function(object) {

		if(object.showBox === true) {
			this.content();
			showBox('productBoxContent');
		}
	}

}
Object.extend(GetProductDetailAjax.prototype, CommonAjax);

var GetActivityDetailAjax = Class.create();
GetActivityDetailAjax.prototype = {

	id: 'productBox',
	page: projectUrl +'/member/baby/prepare/getActivityDetail',

	execute: function(object) {

		if(object.showBox === true) {
			this.content();
			showBox('productBoxContent');
		}
	}

}
Object.extend(GetActivityDetailAjax.prototype, CommonAjax);


var GetPassUsePopUpAjax = Class.create();
GetPassUsePopUpAjax.prototype = {

	id: 'passUseBox',
	interaction: 'info',
	page: projectUrl +'/member/pass/prepare/getConfirm',

	execute: function(object) {

		if(object.close == false) {
			this.content();
			showBox('passUseBoxContent');
		}
	}

}
Object.extend(GetPassUsePopUpAjax.prototype, CommonAjax);


var GetConfirmPopupAjax = Class.create();
GetConfirmPopupAjax.prototype = {

	id: 'confirmBox',
	page: projectUrl +'/member/prepare/getConfirmPopup',

	execute: function(object) {

		if(object.close == false) {
			this.content();
			showBox('confirmBoxContent');
		}
	}

}
Object.extend(GetConfirmPopupAjax.prototype, CommonAjax);


var ScrollbarGroup = {
	init : function(scrolls){
		for(i=0; i<scrolls.length; i++) {
			try {
				ScrollObject	= new Control.ScrollBar(
					$(scrolls[i]).down("div.scroll-content"),
					$(scrolls[i]).down("div.scrollbar"));
			} catch (e) {}
		}

	}
};

var TutorialManager = {
	shown : null,
	toggle : function() {
		if(this.shown == true) {
			this.hide();
		} else {
			this.show();
		}
	},
	show : function() {
		$("customTutorial").setStyle({clip : "rect(auto auto auto auto)"});
		$('customTutorial').down('ul').down('li').addClassName('selected');
		this.shown = true;
	},
	hide : function() {
		$("customTutorial").setStyle({clip : "rect(7px auto 152px 443px)"});
		$('customTutorial').down('ul').down('li').removeClassName('selected');
		this.shown = false;
	},
	init : function() {

		if($('customTutorial') == undefined) {
			return;
		}

		var self = this;
		this.shown = true;
		$('customTutorial').down('ul').down('li').observe('click', function( event ) {
			self.toggle();
		});
	}
}

function displayTutorial(object) {

	if($('customTutorial') == undefined) {
		return;
	}

	if(object.tutorialTitle != undefined) {
		$('tutorialTitle').innerHTML = object.tutorialTitle;
	}
	if(object.tutorialDescription != undefined) {
		$('tutorialDescription').innerHTML = object.tutorialDescription;
	}
	if(object.tutorialImage != undefined) {
		$('tutorialImage').innerHTML = object.tutorialImage;
	}
	if(object.tutorialGift != undefined) {
		$('tutorialGift').innerHTML = object.tutorialGift;
	} else {
		if($('tutorialGift') != undefined) {
			$('tutorialGift').innerHTML = "";
		}
	}

	if(object.tutorialShow != undefined && object.tutorialShow == false) {
		TutorialManager.hide();
	} else {
		TutorialManager.show();
	}
}

