

// Cain's Journal
// --------------

function storyGetPage(page) {
	document.getElementById('navbar').fromjsgoToPage(page);	;
	storyHighlightCurrentStory(page,totalBookviewerPages);
}
function storyHighlightCurrentStory(id,total) {
	for (j=0; j<=total; j++) {
		document.getElementById('story-link-' + j).className = "story-link";
	}
	document.getElementById('story-link-' + id).className = "story-link-underline";
}


// Flashtext Template
// ------------------


function resizeFlashTextDiv(flashtextdivid,flashwidth,flashheight) {
	document.getElementById(flashtextdivid).style.width = flashwidth + 'px';
	document.getElementById(flashtextdivid).style.height = flashheight + 'px';
}


// Candle Footer
// ------------------


var vScrollDetector;
var vMouseWheelDetector;
var	vSafari;
var vMouseWheelDirection;
var divOffset;

function InitializeCandle() {
	vScrollDetector = true;
	vMouseWheelDetector = false;
	vMouseWheelDirection = 0;

	// Set up Listeners
	if (window.addEventListener)
		window.addEventListener('DOMMouseScroll', wheel, false);
	window.onmousewheel = document.onmousewheel = wheel;

	// Scroll Listener
	window.onscroll = callScroll;

	// OnResize Listener
	window.onresize = scrollEvent;

	callScroll();

}

function wheel(event){
	if (Browser.ie) {}
	else {
		vScrollDetector = false;
		vMouseWheelDetector = true;
	}
}

function callScroll(msg) {
	if (vMouseWheelDetector == false) {
		vScrollDetector = true;
		vMouseWheelDetector = false;
	}
	scrollEvent(msg);
}

function getScreenPosition()	{
	var position = 0;
	if (typeof window.pageYOffset != 'undefined') {
		position = window.pageYOffset;
	}
	else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)
	{ 	position = document.documentElement.scrollTop;
	}
	else if (typeof document.body.scrollTop != 'undefined') {
		position = document.body.scrollTop;
	}
	return position;
}


function scrollEvent(msg) {

	verticalDistance = getScreenPosition();
	divOffset = document.getElementById('blizzardlogo').offsetTop;
	if (Browser.ie) {
		divOffset = divOffset + 400;
	}
	ScrollFlashCall(verticalDistance,divOffset,vMouseWheelDetector);
	vScrollDetector = true;
	vMouseWheelDetector = false;
}


function ScrollFlashCall(scrollvalue,offsetvalue,mousewheel) {

	document.getElementById(vFlashCandleID).UpdateCandlePosition(scrollvalue, offsetvalue, giveWindowSize(),mousewheel);
}

function giveWindowSize() {
  var windowInnerHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-Internet Explorer
	windowInnerHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE6 (standards compliant mode)
	windowInnerHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE4 compatible
	windowInnerHeight = document.body.clientHeight;
  }
  return windowInnerHeight;
}


// Navigation Sound Cookie Detector
// --------------------------------

function createSoundCookie(soundvolume,soundstatus) {
//	alert('soundvolume: ' + soundvolume + '   soundstatus=' + soundstatus);
	loadScript((jsRoot + 'cookies.xml?soundvolume=' + soundvolume + '&soundstatus=' + soundstatus), 'cookiejson');
}

// Language Change request
// -----------------------

function flashLanguageChange(language) {
	var newLang = charReplace(language,'-','_');
	loadScript((jsRoot + 'cookies.xml?cookieLangId=' + newLang + '&callback=flashLanguageChangeFallback'), 'cookiejson');
}

function charReplace(str,oldchar,newchar) {
	// Replaces all oldchar by newchar in the str string.  In this case, it replaces the - by _ in the language string.  
	var newstr = "" + str;
	while (newstr.indexOf(oldchar)>-1) {
		pos= newstr.indexOf(oldchar);
		newstr = "" + (newstr.substring(0, pos) + newchar + 
		newstr.substring((pos + oldchar.length), newstr.length));
	}
	return newstr;
}

function flashLanguageChangeFallback(result) {
	locale = result['cookieLangId'];
	if(!locale)
		locale = 'en-US';
	// Language has changed, reload document.
	document.location.reload();		
}


//Flash Video Player

function callvideo(flvars,height,width)
{ 	documentBody = document.getElementsByTagName("body")[0];
	windowHeight = (window.innerHeight) ? window.innerHeight : documentBody.clientHeight;
	windowWidth = (window.innerWidth) ? window.innerWidth : documentBody.clientWidth;

	if(!document.getElementById("blackout")){ 	
		blackout = createElement("div");
		blackout.onclick = function(){hideMovie()};
		blackout.id = "blackout";
	blackout.style.height = document.documentElement.scrollHeight + 'px';

		
		documentBody.insertBefore(blackout, documentBody.firstChild);
	
		}
	else { show('blackout'); }
	
		movie_obj = createElement("div");
		movie_obj.className = "movieobj"; 	
		movie_obj.style.left = windowWidth/2-width/2+"px";
		movie_obj.style.top = windowHeight/2-height/2+"px";
		movie_obj.style.height = Number(height)+ 20 +"px"
		movie_obj.style.width = Number(width)+ 20 +"px";

		setTimeout(function(){
		setFlash(movie_obj, 'movieObjguts', mediactx+'_video/player/video_loader.swf', "100%", "100%", [
					['movie', mediactx + '_video/player/video_loader.swf'],
					['base', mediactx + '_video/player/'],
					['allowFullScreen', 'true'],
					['allowScriptAccess', 'always'],
					['flashvars', 'vidArr=' + flvars + "&ht="+height+"&wd="+width]
				], 'noFlashErr',true);
							 },600);
			
		documentBody.insertBefore(movie_obj, documentBody.firstChild);
		

}

function hideMovie()
{ 
	blckout = document.getElementById("blackout")
	documentBody.removeChild(movie_obj);
	hide(blackout);
}

var dllink;

function dlvideo(vloc)
{ 	height=297; width=700;
	dllink = vloc
	agetest = AgeGate.verify()
	
	if(String(agetest) == "false" || String(agetest) == "null")
{  
	documentBody = document.getElementsByTagName("body")[0];
	windowHeight = (window.innerHeight) ? window.innerHeight : documentBody.clientHeight;
	windowWidth = (window.innerWidth) ? window.innerWidth : documentBody.clientWidth;

	if(!document.getElementById("blackout")){ 	
		blackout = createElement("div");
		blackout.onclick = function(){hideMovie()};
		blackout.id = "blackout";
	blackout.style.height = document.documentElement.scrollHeight + 'px';

		
		documentBody.insertBefore(blackout, documentBody.firstChild);
	
		}
	else { show('blackout'); }
	
		movie_obj = createElement("div");
		movie_obj.className = "movieobj"; 	
		movie_obj.style.left = windowWidth/2-width/2+"px";
		movie_obj.style.top = windowHeight/2-height/2+"px";
		movie_obj.style.height = Number(height)+ 20 +"px"
		movie_obj.style.width = Number(width)+ 20 +"px";

		
		setFlash(movie_obj, 'movieObjguts', mediactx+'_video/player/dl_block.swf', "100%", "100%", [
					['movie', mediactx + '_video/player/dl_block.swf'],
					['base', mediactx + '_video/player/'],
					['allowFullScreen', 'true'],
					['bgcolor', '000000'],
					['allowScriptAccess', 'always'],
					['flashvars', 'mediactx=' + mediactx]
				], 'noFlashErr',true);
		
			
		documentBody.insertBefore(movie_obj, documentBody.firstChild);
		
	}
	else window.location.href = dllink;
}

function dl_ok()
{   
	setTimeout(hideMovie, 400);
	window.location.href = dllink;
}

// Flash GetURL Workaround for standard linkage on the main site (avoid Root)
function getFlashLink(flashurl,absolute) {
	var rellink = jsRoot;
	if (absolute == false) {
		rellink = "";
	}
	window.location = rellink + flashurl;
}


function mov_wiz(flvars,height,width)
{
	movie_obj = document.getElementById("wizmov");
	setFlash(movie_obj, 'movieObjguts', mediactx+'_video/player/video_loader.swf', width, height, [
					['movie', mediactx + '_video/player/video_loader.swf'],
					['base', mediactx + '_video/player/'],
					['allowFullScreen', 'true'],
					['allowScriptAccess', 'always'],
					['flashvars', 'vidArr=' + flvars + "&ht="+height+"&wd="+width]
				], 'noFlashErr',true);
							 

	}
