﻿var curClipTimeout;
var curClipImage;

function toggleImage(img)
{
	var oldName = "_on";
	var newName = "_off";
	
	if (img.src.indexOf("_off") >= 0)
	{
		oldName = "_off";
		newName = "_on";
	}
	
	img.src = img.src.replace(oldName, newName);
}

function OnHoverOver(img)
{
	if (img.src.indexOf("_unhover") >= 0)
		img.src = img.src.replace("_unhover", "_hover");
	else
		img.src = img.src.replace(".gif", "_hover.gif");
}

function OnHoverOut(img)
{
	img.src = img.src.replace("_hover", "_unhover");
}

function GetHoverOverSource(img)
{
}

function GetHoverOutSource(img)
{
}

function soundToggle()
{
	var play = (document.getElementById('imgSound').src.indexOf("_off") == -1);
	PlayMusic(play);
}

function MainWindow()
{
	if (document.forms[0].name == "frmMain")
		return window;
	else
		return window.parent;
}

function MainDocument()
{
	return MainWindow().document;
}

function MusicFrame()
{
	return MainWindow().frames[1];
}

function PlayMusic(play)
{
	if (play)
		MusicFrame().location = "PlayMusic.aspx?song=renewal.mp3";
	else
		MusicFrame().location = "blank.htm";
}

function SetSong(img, path)
{
	play = (img.src.indexOf("clip_on") >= 0);

	SetClipImage(curClipImage, !play);
	SetClipImage(img, play);

	curClipImage = (play) ? img : null;
	if (curClipTimeout) clearTimeout(curClipTimeout);
	//PlayMusic(false);

	if (play)
	{
		curClipTimeout = setTimeout('SetClipImage(curClipImage, false)', 20000);
		InsertClip(path);
	}
	else
	{
		PlayMusic(false);
	}
}

function SetClipImage(img, playing)
{
	if (img)
	{
		onoff     = playing ? "off" : "on";
		img.src   = "resources/images/pieces/clip_" + onoff + ".gif";
		img.title = playing ? "Stop" : "Play";
	}
}

function EnterSite(img)
{
	img.style.display = "none";
	document.getElementById("divSiteFrame").style.display = "";
	frameNavigate("Home.aspx");
}

function frameNavigate(url)
{
	document.getElementById("iContentFrame").src = url;
}

function InsertMusic(autoStart)
{
	document.write('<embed id="bgmusic" name="bgmusic" src="resources/media/renewal.mp3" autostart="' + autoStart + '" loop="true" width="0" height="0" hidden="true">');
}

function InsertClip(path)
{
	MusicFrame().location = "PlayMusic.aspx?song=clips/" + path;
}
