// JScript File

 var nohmattawat;

function chgbutton(id, direction)
        {
            document.getElementById("img_" + id).src="images/" + id + "-" + direction + ".jpg";
        }

function extractPageName(hrefString)
{
	var arr = hrefString.split('.');
	arr = arr[arr.length-2].split('/');
	return arr[arr.length-1].toLowerCase();
}

function setPage()
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;
    
    if (hrefString == "http://www.nohmattawat.com/" || hrefString == "http://www.nomattawat.com/" || hrefString == "http://bsnserver/nohmattawat/")
		document.getElementById("img_default").src="images/default-on.jpg";
    else if (document.getElementById("img_" + extractPageName(hrefString))!=null)
        document.getElementById("img_" + extractPageName(hrefString)).src="images/" + extractPageName(hrefString) + "-" + "on" + ".jpg";
}

function showSubmittingMessage()
{
    document.getElementById("submitvotetxt").style.display = "block";
}

function StartMeUp ()
        {
            sea2ep2.play();
        }

function ShutMeDown ()
        {
            sea2ep2.stop();
        }
       
function ShowObj(id)
       {
            var obj = document.getElementById(id);
            obj.display = "inline"; 
       }
       
function HideObj(id)
       {
             var obj = document.getElementById(id);
            obj.display = "none"; 
       }
       
function ToggleDisplay(id)
       {
             var obj = document.getElementById(id);
             if(obj.style.display == "none")
             {
                 obj.style.display = "inline"; 
             }
             else
             {
                obj.style.display = "none";
             }
       }
       
function loadMovie()
{
  nohmattawat = document.getElementById("nohmattawat");
}
       
function changeMovie(movie)
{
   nohmattawat["movie"] = movie; 
}
        
function toggleSummaries(id)
{
    for(var i=0;i<seasonStates.length;i++)
    {
        document.getElementById("season" + i + "_summaries").style.display="none";
    }
    document.getElementById("season" + id + "_summaries").style.display="inline";
} 

function toggleClips(id)
{
    for(var i=1;i<seasonStates.length;i++)
    {
        document.getElementById("season" + i + "_clips").style.display="none";
    }
    if(id != '0')
    { 
        document.getElementById("season" + id + "_clips").style.display="inline";
    } 
} 
       
var seasonStates = ['0', 'up', 'up'];

function chgImgOver(id)
{
   var img =   document.getElementById("img_season" + id);
   if(seasonStates[id] == "up")
   { 
       img.src="images/season" + id + "-upover.jpg";
   }
   else
   {
          img.src="images/season" + id + "-downover.jpg";
   }
} 

function chgImgOut(id)
{
   var img =   document.getElementById("img_season" + id);
   img.src="images/season" + id + "-" + seasonStates[id] + ".jpg";
} 

function chgSeasonState(id)
{
    var img =   document.getElementById("img_season" + id);
    if(seasonStates[id] == "up")
   { 
        for(var i=0;i<seasonStates.length;i++)
       {
            seasonStates[i] = "up";
            if(i != 0)
            { 
                document.getElementById("img_season" + i).src = "images/season" + i + "-" + seasonStates[i] + ".jpg";
            } 
       }
        seasonStates[id] = "down";
        toggleClips(id);
        toggleSummaries(id);
        chgSeasonEpisodeState(id, 0); 
   }
   else
   {
          seasonStates[id] = "up";
          toggleClips('0');
          toggleSummaries('0');
           chgSeasonEpisodeState(0, 0);
   }
   //alert(1);
   //alert("images/season" + id + "-" + seasonStates[id] + ".jpg");
   img.src="images/season" + id + "-" + seasonStates[id] + ".jpg"; 
   //alert(22); 
}
 
var seasonEpisodeStates = new Array(3)

seasonEpisodeStates[0] = ['0'];

seasonEpisodeStates[1] = ['0', 'up', 'up', 'up', 'up', 'up']; 

seasonEpisodeStates[2] = ['0', 'up', 'up', 'up', 'up', 'up', 'up', 'up', 'up', 'up']; 

function chgEpisodeImgOver(seasonID, episodeID)
{
   var img =   document.getElementById("img_season" + seasonID + "_episode" + episodeID);
   if(seasonEpisodeStates[seasonID][episodeID] == "up")
   { 
       img.src="images/season" + seasonID + "_episode" + episodeID + "-over.jpg";
   }
   else
   {
         img.src="images/season" + seasonID + "_episode" + episodeID + "-over.jpg";
   }
}  

function chgEpisodeImgOut(seasonID, episodeID)
{
   var img =   document.getElementById("img_season" + seasonID + "_episode" + episodeID);
   img.src="images/season" + seasonID + "_episode" + episodeID + "-" + seasonEpisodeStates[seasonID][episodeID] + ".jpg";
} 

function chgSeasonEpisodeState(seasonID, episodeID)
{
   if(seasonEpisodeStates[seasonID][episodeID] == "up")
   { 
       for(var i=0;i<seasonEpisodeStates.length;i++)
       {
            for(var j=0;j<seasonEpisodeStates[i].length;j++)
            {
                seasonEpisodeStates[i][j] = "up";
                if(i != 0 && j != 0)
                { 
                    document.getElementById("img_season" + i + "_episode" + j).src = "images/season" + i + "_episode" + j + "-" + seasonEpisodeStates[i][j] + ".jpg";
                } 
             } 
       }
      seasonEpisodeStates[seasonID][episodeID] = "down";
       
       if(seasonID != 0 &&  episodeID != 0)
       {
           var img =   document.getElementById("img_season" + seasonID + "_episode" + episodeID);
           img.src="images/season" + seasonID + "_episode" + episodeID + "-" + seasonEpisodeStates[seasonID][episodeID] + ".jpg";
       }
        changeMovie("sea" + seasonID + "ep" + episodeID + ".swf");  
   }
   else
   {
          seasonEpisodeStates[seasonID][episodeID] = "up";
          changeMovie("sea" + seasonID + "ep0.swf"); 
   }
}

function switchVideo (id)
{
    for(var i=0;i<2;i++)
    {
        document.getElementById("version" + i).style.display="none";
    }
    document.getElementById("version" + id).style.display="inline";
}

function switchVideo(versionId)
{
    nohmattawat = document.getElementById("nohmattawat");
    changeMovie("videos/season_2_episode_1_" + versionId + "_remote.swf");
}

window.onload=setPage;