// JavaScript Document

//if screen is smaller than 1024 use stylesheet2 for smaller fonts
if (screen.availWidth < 1024)
{
   document.write('<link href="stylesheet1.css" rel="stylesheet" type="text/css">');       
} else {
   document.write('<link href="stylesheet.css" rel="stylesheet" type="text/css">');   
}  

//Set is_ie variable for based on browser for use in code  
var agt=navigator.userAgent.toLowerCase();
var is_ie   = (agt.indexOf("msie") != -1);

if(parent.frames.length>0)
{	
  //alert('this page is trying to load classicvideo.ca in a subframe - now taking you directly to classicvide.ca ...');
  //window.top.location="http://www.classicvideo.ca";
}	

function gotopage(apage)
{	
  window.location = apage;
}  

//***************************************************************************
//
//      text fade effect
//
//***************************************************************************

var hexChars = "0123456789ABCDEF";

function Dec2Hex (Dec)
{
   var a = Dec % 16;
   var b = (Dec - a)/16;
   hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
   return hex;
}

function CHANGEBG (begin, end)
{   
   steps = steps -1; 
   redA     = begin.charAt(0) + begin.charAt(1);
   red_valA = parseInt(redA,'16');
   redB     = end.charAt(0) + end.charAt(1);
   red_valB = parseInt(redB,'16');
   red_int  = ((red_valB - red_valA) / steps) * -20;
   grnA     = begin.charAt(2) + begin.charAt(3);
   grn_valA = parseInt(grnA,'16');
   grnB     = end.charAt(2) + end.charAt(3);
   grn_valB = parseInt(grnB,'16');
   grn_int  = ((grn_valB - grn_valA) / steps) * -20;
   bluA     = begin.charAt(4) + begin.charAt(5);
   blu_valA = parseInt(bluA,'16');
   bluB     = end.charAt(4) + end.charAt(5);
   blu_valB = parseInt(bluB,'16');
   blu_int  = ((blu_valB - blu_valA) / steps) * -20;
 
   red = red_valA;
   grn = grn_valA;
   blu = blu_valA;

   red -= red_int;
   red_round = Math.round(red);
   red_hex = Dec2Hex(red);
   grn -= grn_int;
   grn_round = Math.round(grn);
   grn_hex = Dec2Hex(grn);
   blu -= blu_int;
   blu_round = Math.round(blu);
   blu_hex = Dec2Hex(blu);
 
   return(red_hex + grn_hex + blu_hex);
}

function colorfade()
{
   	  tmp = CHANGEBG("000066", "E6E4DE");	
	  document.getElementById(theDiv).style.color = tmp;
	  	  
	  if (tmp != "E6E4DE")
	  {	    		
	  	setTimeout("colorfade()",10);	  	
	  } else {
	  	setTimeout("randomDiv()", 500);
	  }	    
}

// PRICE BAR FADE EFFECT
function colorfadebar()
{
   step = 2;
   steps = 50;
   cnt=0;

   do
   {
      //tmp = CHANGEBG("ffffff", "91A0FF")
	  tmp = CHANGEBG("6EA2DF", "FFFFFF");
      document.write("<TD HEIGHT=100% width=1%  BGCOLOR='#" + tmp + "'></TD>");
   } while (tmp != "FFFFFF");
}



var step = 2;
var steps = 50;
var cnt=0;
var theDiv ;
var lastDiv = 0;


function randomDiv()
{
   step = 2;
   steps = 100;
   cnt=0;
   do 
   {
      tmpnum = (Math.random() * 10) + 1;
      nextDiv = Math.round(tmpnum) ;     // rounding #.99 up
   } while (lastDiv == nextDiv)
   lastDiv = nextDiv;	     
   theDiv = 'qcDiv' + nextDiv;
   document.getElementById(theDiv).style.color = "000066";
   colorfade();   
}   
    

//used to set parameters and open a new window
function openNewWindow(theURL, type)
{   
   if (type == 'acoupon')
   {
        new_window = window.open(theURL,"new", "directories=no,location=no,menubar=yes,resizable=yes,status=yes,toolbar=no,scrollbars=yes,width=625,height=475,left=0,top=0");
		new_window.focus();   
   } else {
        new_window = window.open(theURL,"new", "directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes,scrollbars=yes,left=0,top=0");
		new_window.focus();
   }
   
}


var urlAddress = "http://www.classicvideo.ca";
var pageName = "Classic Video";
function addToFavorites()
{
	if (window.external)
	{
		window.external.AddFavorite(urlAddress,pageName);		
	}
	else
	{
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function mouseoverImage(theimage)
{

	if (is_ie)
	{	     	
	  theimage.style.cursor='hand';
    } else {
	  theimage.style.cursor='pointer';	     	  
	}	 				
}

function showImage(theImage)
{
	classic_pop = window.open(theImage,"new", "directories=no,location=no,menubar=no,resizable=yes,status=yes,toolbar=no,scrollbars=yes,width=645,height=475,left=0,top=0");
	classic_pop.focus();   
}





// Teletype-Scroll-Fade Text and Banner Image Effect script

//these effects are started by calling 
// random_Banner() which loads the first banner picture randomly 
//the images onload event is trigged and tsf_Browsers() is called which makes sure visitors
//browser can support the effects and then it begins looping through the functions:
// tsf_Go() initializes and re-sets all variables
// tsf_Teletype() displays text with teletype effect
// tsf_ScrollFade() scrolls text down while fading test and banner image
// tsf_Banner() selects and loads next banner image in sequence 
// tsf_ShowBanner() fades in new banner image and calls tsf_Go() to re-start loop

//declare and initialize variables
var show_tsf = 0;
var tsfTimer;
var message; 
var colour;
var character;
var to_print;
var ypos;
var next = 0;
var fade;
var picFade = 0;
var messages = new Array() ;
var colours = new Array();

//test for browser compatibility 
//call tsf_Show if browser if compatible to opacity effect
function tsf_Browser()
{		
	
	if (message_cnt <= 0)
	{
	//	messages not loaded set timer to return and exit function
		tsfTimer = window.setTimeout("tsf_Browser()", 200);
		return;
	}
	
	window.clearTimeout(tsfTimer);
	if (show_tsf == 0)
	{
		//if not home page then select a random message to start with
		tmpnum = (Math.random() * messages.length);
        next = Math.round(tmpnum) ;     // rounding #.99 up	   	
	}
	
 	if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
  	{
  	 	tsf_Go();
	} else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
  	   	tsf_Go();
	}
		
}

//initializes and re-sets all variables
//calls tsf_teletype()
function tsf_Go()
{	
	window.clearTimeout(tsfTimer);
	character = 0;
	to_print = "";
	ypos = 0;	
	txtFade = 100;	
    message = messages[next];
	colour = colours[next];
    if (next == (messages.length - 1)) 
    {
	next = 0;
   	} else {
	next++;
   	}
    
	if (show_tsf == 1)
	{
	document.getElementById("teletext").innerHTML = ""; 
	document.getElementById("teletext").style.top = ypos;  	
    setOpacity ("teletext", txtFade);
    }
    window.status = "";
	
	window.clearTimeout(tsfTimer);
	
	//alert(colours[next]);
    tsf_Teletype();
}

function tsf_Teletype()
{
	window.clearTimeout(tsfTimer);	
 	if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
    {
		if (show_tsf = 1)
		{
		document.getElementById("teletext").innerHTML = message;
		tsfTimer = window.setTimeout("tsf_ScrollFade()", 4000);
		}
		
	} else {		
		if (character <= message.length - 1) 
		{	
			to_print = message.charAt(character);
			if (show_tsf == 1)
			{
			document.getElementById("teletext").style.color = "#" + colour;		
			document.getElementById("teletext").innerHTML +=  to_print;		
			}
			window.status += to_print;
			character++;		
			tsfTimer = window.setTimeout("tsf_Teletype()", 80);				
		} else {
			window.clearTimeout(tsfTimer);			
			if (show_tsf == 1)
			{
			tsf_ScrollFade();		
			} else {
			//alert(show_tsf);
			window.setTimeout("tsf_Go()", 900);
			}		
		}
	}

}	

//scrolls completed text message and fades out message and banner picture
//calls tst_Banner() once message is scrolled out of range
function tsf_ScrollFade()
{
	window.clearTimeout(tsfTimer);
	if (is_ie)
	{	scrolldown = 55; } else { scrolldown = 25; }
   	if (ypos <= scrolldown)
   	{
	//window.status = ypos;
	ypos += 1;
	txtFade -= 3;
	picFade -= 3;
    document.getElementById("teletext").style.top = ypos;     	
	setOpacity ("teletext", txtFade);
	tsfTimer = window.setTimeout("tsf_ScrollFade()", 60);
	} else {
	window.clearTimeout(tsfTimer);
	tsfTimer = window.setTimeout("tsf_Go()", 300);				
	}

}	

//this function is called whenever a div opacity if being adjusted
function setOpacity (divName, opacity)
{	
  //window.clearTimeout(tsfTimer);
  if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
  {
  document.getElementById(divName).style.MozOpacity= opacity/100;
  } else if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) { 
  document.getElementById(divName).filters.alpha.opacity=opacity;
  }
  
} 

//movie search from movie_search_title and index
function requestSearch()
{	
	
	title = document.frmSearch.title.value;	
	if (title<1)
	{
		alert('Please enter something to search for.');
		document.frmSearch.title.focus();
		return false;
	}		
	PopSearch();	
	document.frmSearch.submit();						
}

//sliding navigation menu script
function stopFilm()
{
	if (window.sfTimer)
	{
		window.clearTimeout(sfTimer);
	}
}


function slideFilm()
{
	//window.clearTimeout(sfTimer);
	for (cnt=1;cnt<=totalimages;cnt++)
	{
		aimg = "film" + cnt;
		//alert(aimg);
		tmp = parseInt(document.getElementById(aimg).style.left);
		//window.status = tmp;	
		document.getElementById(aimg).style.left = tmp - 1;
		if (tmp <= -64)
		{
			tmp = parseInt(document.getElementById(fileend).style.left) + 64;
			document.getElementById(aimg).style.left = tmp;
			fileend = aimg;
		}
			
	}
	
	sfTimer = window.setTimeout("slideFilm()", 60);		
}	



