﻿/* JavaScript Written by Sam Deering 2010 */

/* Displays a random magic quote and source when the webpage is loaded. */
function randommagicquote() {
	//quote
	var txt_quote = new Array ();
	txt_quote[0] = "Magic is believing in yourself, if you can do that, you can make anything happen.";
	txt_quote[1] = "Love can sometimes be magic. But magic can sometimes... just be an illusion.";
	txt_quote[2] = "One man's magic is another man's engineering. Supernatural is a null word.";
	txt_quote[3] = "That's the thing with magic. You've got to know it's still here, all around us, or it just stays invisible for you.";
	txt_quote[4] = "Using words to describe magic is like using a screwdriver to cut roast beef.";
	txt_quote[5] = "The power of Thought, the magic of the Mind!";
	txt_quote[6] = "The universe is full of magical things, patiently waiting for our wits to grow sharper.";
	txt_quote[7] = "The magician & politician have much in common: they both draw our attention away from what they are really doing."
	txt_quote[8] = "Style is a magic wand, and turns everything to gold that it touches."
	txt_quote[9] = "Logic only gives man what he needs...Magic gives him what he wants."
	txt_quote[10] = "You'll like this, not a lot, but you'll like it."
	//source
	var txt_source = new Array ();
	txt_source[0] = "Johann Wolfgang (German Playwright, Poet, Novelist and Dramatist. 1749-1832)"
	txt_source[1] = "Javan (Iranian born American Inventor, (invented gas laser 1960) b.1946)"
	txt_source[2] = "Tom Robbins (American Novelist. b.1936)"
	txt_source[3] = "Charles de Lint (Celtic folk musician and story teller, b.1951)"
	txt_source[4] = "Tom Robbins (American Novelist. b.1936)"
	txt_source[5] = "Lord Byron (English Romantic poet and satirist, 1788-1824)"
	txt_source[6] = "Eden Phillpotts (English science-fiction Writer 1862-1960)"
	txt_source[7] = "Ben Okri (Nigerian author, 1959)"
	txt_source[8] = "Logan Pearsall Smith quotes (American Writer, 1865-1946)"
	txt_source[9] = "Tom Robbins (American Novelist. b.1936)"
	txt_source[10] = "Paul Daniels (British Magician)"
		
	//Convert the random number into an integer because the random() method throws a floating point (decimal) number between 0.0 and 1.0
	//The variable i now contains a floating point (decimal) number between 0 and 1. 
	//We have to convert it to an integer between 0 to 6 so that it can be used as an index to retrieve the string from the txt_quote array.
	//Math.floor() is used to round down this number. Thus, 0.345... would result in 0 and 6.893.. would be floored to 6.
	var i = Math.floor(11*Math.random())
	
	document.write("<font class=style3>")
	document.write("\""+txt_quote[i]+"\"");
	document.write("</font>")
	
	//document.write("<br>");
	document.write("  ");
	
	document.write('<font class="style5">')
	document.write(txt_source[i]);
	document.write("</font>")
	
	document.write("<br><br>");
}

//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }
  //long year
  y += 2000

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'January':( 2==m)?'February':(3==m)?'March':
    ( 4==m)?'April':( 5==m)?'May':(6==m)?'June':
    ( 7==m)?'July':( 8==m)?'August':(9==m)?'September':
    (10==m)?'October':(11==m)?'November':'December';

  return "" +
    (d<10?"0"+d:d) + " " +
    mmm + " " +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}

// display the last modified date
function lastupdate() {
	document.write("Last update on " + date_lastmodified());
}

//
function homeclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="homepage.htm"; 
	//changeOpacityTo(0);
	showRedStar(0);
}

//
function aboutclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="aboutme.htm" ; 
	//changeOpacityTo(1);
	showRedStar(1);
}

//
function portfolioclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="portfolio.htm" ; 
	//changeOpacityTo(2);
	showRedStar(2);
}

//
function blogclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="blog.htm" ; 
	//objFrame.src="http://www.codingmagician.com/blog/" ;
	
	//default iframe height to 800px
	//parent.setIframeHeight('main_frame');
	//goSetHeight();
	
	//objFrame.height = "800px";
	//changeOpacityTo(3);
	showRedStar(3);
}

//
function contactclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="contact.htm" ; 
	//changeOpacityTo(4);
	showRedStar(4);
}

//
function sitemapclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="sitemap.htm" ; 
	//changeOpacityTo(0);
	showRedStar(0);
}

function hobbiesclick() {
	var objFrame=document.getElementById("main_frame");
	objFrame.src="hobbies.htm" ; 
	//changeOpacityTo(2);
	showRedStar(2);
}



function menuhoverout(menu_number) {
//inactive image files (1)
var home_img_file1 = 'images/menu/menu_home.gif';
var about_img_file1 = 'images/menu/menu_aboutme.gif';
var portfolio_img_file1 = 'images/menu/menu_portfolio.gif';
var blog_img_file1 = 'images/menu/menu_blog.gif';
var contact_img_file1 = 'images/menu/menu_contact.gif';

//active image files (2)
var home_img_file2 = 'images/menu/menu_home_active.gif';
var about_img_file2 = 'images/menu/menu_aboutme_active.gif';
var portfolio_img_file2 = 'images/menu/menu_portfolio_active.gif';
var blog_img_file2 = 'images/menu/menu_blog_active.gif';
var contact_img_file2 = 'images/menu/menu_contact_active.gif';

//hover image files (3)
var home_img_file3 = 'images/menu/menu_home_hover.gif';
var about_img_file3 = 'images/menu/menu_aboutme_hover.gif';
var portfolio_img_file3 = 'images/menu/menu_portfolio_hover.gif';
var blog_img_file3 = 'images/menu/menu_blog_hover.gif';
var contact_img_file3 = 'images/menu/menu_contact_hover.gif';

/*
Action Events

on click
	- ALWAYS SHOW active image 2
	- ALL OTHERS SHOW inactive 1
on mousein
	- IF image is not active 2 SHOW hover image 3
on mouseout
	- IF image is not active 2 SHOW inactive image 1
*/
	
switch (menu_number){
	case 0:
	
		var current_img_src = document.getElementById("home-button-img").src;
		//alert(document.getElementById("home-button-img").src.substr(str.length-home_img_file2.length));
		//alert(current_img_src.substr(current_img_src.length-home_img_file2.length) + " == " + home_img_file2 + " " + (current_img_src.substr(current_img_src.length-home_img_file2.length) == home_img_file2));
		if (current_img_src.substr(current_img_src.length-home_img_file2.length) != home_img_file2) {
			document.getElementById("home-button-img").src=home_img_file1;
		}
	break;
	
	case 1:
		var current_img_src = document.getElementById("about-button-img").src;
		if (current_img_src.substr(current_img_src.length-about_img_file2.length) != about_img_file2) {
			document.getElementById("about-button-img").src=about_img_file1;
		}
	break;
	
	case 2:
		var current_img_src = document.getElementById("portfolio-button-img").src;
		if (current_img_src.substr(current_img_src.length-portfolio_img_file2.length) != portfolio_img_file2) {
			document.getElementById("portfolio-button-img").src=portfolio_img_file1;
		}
	break;
	
	case 3:
		var current_img_src = document.getElementById("blog-button-img").src;
		if (current_img_src.substr(current_img_src.length-blog_img_file2.length) != blog_img_file2) {
			document.getElementById("blog-button-img").src=blog_img_file1;
		}
	break;
	
	case 4:
		var current_img_src = document.getElementById("contact-button-img").src;
		if (current_img_src.substr(current_img_src.length-contact_img_file2.length) != contact_img_file2) {
			document.getElementById("contact-button-img").src=contact_img_file1;
		}
	break;
	
	default:
		//active
	break;
		}
}

function menuhoverin(menu_number) {
//inactive image files (1)
var home_img_file1 = 'images/menu/menu_home.gif';
var about_img_file1 = 'images/menu/menu_aboutme.gif';
var portfolio_img_file1 = 'images/menu/menu_portfolio.gif';
var blog_img_file1 = 'images/menu/menu_blog.gif';
var contact_img_file1 = 'images/menu/menu_contact.gif';

//active image files (2)
var home_img_file2 = 'images/menu/menu_home_active.gif';
var about_img_file2 = 'images/menu/menu_aboutme_active.gif';
var portfolio_img_file2 = 'images/menu/menu_portfolio_active.gif';
var blog_img_file2 = 'images/menu/menu_blog_active.gif';
var contact_img_file2 = 'images/menu/menu_contact_active.gif';

//hover image files (3)
var home_img_file3 = 'images/menu/menu_home_hover.gif';
var about_img_file3 = 'images/menu/menu_aboutme_hover.gif';
var portfolio_img_file3 = 'images/menu/menu_portfolio_hover.gif';
var blog_img_file3 = 'images/menu/menu_blog_hover.gif';
var contact_img_file3 = 'images/menu/menu_contact_hover.gif';

/*
Action Events

on click
	- ALWAYS SHOW active image 2
	- ALL OTHERS SHOW inactive 1
on mousein
	- IF image is not active 2 SHOW hover image 3
on mouseout
	- IF image is not active 2 SHOW inactive image 1
*/
	
switch (menu_number){
	case 0:

		var current_img_src = document.getElementById("home-button-img").src;
		//alert(document.getElementById("home-button-img").src.substr(str.length-home_img_file2.length));
		//alert(current_img_src.substr(current_img_src.length-home_img_file2.length) + " == " + home_img_file2 + " " + (current_img_src.substr(current_img_src.length-home_img_file2.length) == home_img_file2));
		if (current_img_src.substr(current_img_src.length-home_img_file2.length) != home_img_file2) {
			document.getElementById("home-button-img").src=home_img_file3;
		}
	break;
	
	case 1:
		var current_img_src = document.getElementById("about-button-img").src;
		if (current_img_src.substr(current_img_src.length-about_img_file2.length) != about_img_file2) {
			document.getElementById("about-button-img").src=about_img_file3;
		}
	break;
	
	case 2:
		var current_img_src = document.getElementById("portfolio-button-img").src;
		if (current_img_src.substr(current_img_src.length-portfolio_img_file2.length) != portfolio_img_file2) {
			document.getElementById("portfolio-button-img").src=portfolio_img_file3;
		}
	break;
	
	case 3:
		var current_img_src = document.getElementById("blog-button-img").src;
		if (current_img_src.substr(current_img_src.length-blog_img_file2.length) != blog_img_file2) {
			document.getElementById("blog-button-img").src=blog_img_file3;
		}
	break;
	
	case 4:
		var current_img_src = document.getElementById("contact-button-img").src;
		if (current_img_src.substr(current_img_src.length-contact_img_file2.length) != contact_img_file2) {
			document.getElementById("contact-button-img").src=contact_img_file3;
		}
	break;
	
	default:
		//active
	break;
		}
}

function showRedStar(menu_number) {
//inactive image files (1)
var home_img_file1 = 'images/menu/menu_home.gif';
var about_img_file1 = 'images/menu/menu_aboutme.gif';
var portfolio_img_file1 = 'images/menu/menu_portfolio.gif';
var blog_img_file1 = 'images/menu/menu_blog.gif';
var contact_img_file1 = 'images/menu/menu_contact.gif';

//active image files (2)
var home_img_file2 = 'images/menu/menu_home_active.gif';
var about_img_file2 = 'images/menu/menu_aboutme_active.gif';
var portfolio_img_file2 = 'images/menu/menu_portfolio_active.gif';
var blog_img_file2 = 'images/menu/menu_blog_active.gif';
var contact_img_file2 = 'images/menu/menu_contact_active.gif';

/*
Action Events

on click
	- ALWAYS SHOW active image 2
	- ALL OTHERS SHOW inactive 1
on mousein
	- IF image is not active 2 SHOW hover image 3
on mouseout
	- IF image is not active 2 SHOW inactive image 1
*/

switch (menu_number){
	case 0:
		//active
		document.getElementById('home-button-img').src=home_img_file2;
		//inactive
		document.getElementById('about-button-img').src=about_img_file1;
		document.getElementById('portfolio-button-img').src=portfolio_img_file1;
		document.getElementById('blog-button-img').src=blog_img_file1;
		document.getElementById('contact-button-img').src=contact_img_file1;
	break;
	
	case 1:
		//active
		document.getElementById('about-button-img').src=about_img_file2;
		//inactive
		document.getElementById('home-button-img').src=home_img_file1;
		document.getElementById('portfolio-button-img').src=portfolio_img_file1;
		document.getElementById('blog-button-img').src=blog_img_file1;
		document.getElementById('contact-button-img').src=contact_img_file1;
	break;
	
	case 2:
		//active
		document.getElementById('portfolio-button-img').src=portfolio_img_file2;
		//inactive
		document.getElementById('about-button-img').src=about_img_file1;
		document.getElementById('home-button-img').src=home_img_file1;
		document.getElementById('blog-button-img').src=blog_img_file1;
		document.getElementById('contact-button-img').src=contact_img_file1;
	break;
	
	case 3:
		//active
		document.getElementById('blog-button-img').src=blog_img_file2;
		//inactive
		document.getElementById('portfolio-button-img').src=portfolio_img_file1;
		document.getElementById('about-button-img').src=about_img_file1;
		document.getElementById('home-button-img').src=home_img_file1;
		document.getElementById('contact-button-img').src=contact_img_file1;
	break;
	
	case 4:
		//active
		document.getElementById('contact-button-img').src=contact_img_file2;
		//inactive
		document.getElementById('blog-button-img').src=blog_img_file1;
		document.getElementById('portfolio-button-img').src=portfolio_img_file1;
		document.getElementById('about-button-img').src=about_img_file1;
		document.getElementById('home-button-img').src=home_img_file1;
	break;
	
	default:
		//active
		document.getElementById('home-button-img').src=home_img_file2;
		//inactive
		document.getElementById('about-button-img').src=about_img_file1;
		document.getElementById('portfolio-button-img').src=portfolio_img_file1;
		document.getElementById('blog-button-img').src=blog_img_file1;
		document.getElementById('contact-button-img').src=contact_img_file1;
	break;
}
}

//tide up opacity code
/*
function changeOpacity( objID, opacity )
{
  document.all[objID].style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
}
*/

function changeOpacityTo(menu_number) {
	var theRules = new Array();
	if (document.styleSheets[0].cssRules) {
		theRules = document.styleSheets[0].cssRules;
	} else if (document.styleSheets[0].rules) {
		theRules = document.styleSheets[0].rules;
	}
	switch (menu_number)
	{
	case 0:
	  //homepage
	  
	  /*Netscape*/
	  theRules[menu_number].style.opacity = 1;
	  theRules[1].style.opacity = 0.5;
	  theRules[2].style.opacity = 0.5;
	  theRules[3].style.opacity = 0.5;
	  theRules[4].style.opacity = 0.5;
	  
	  /*IE*/
	  theRules[menu_number].style.filter = "alpha(opacity=100)";
	  theRules[1].style.filter = "alpha(opacity=50)";
	  theRules[2].style.filter = "alpha(opacity=50)";
	  theRules[3].style.filter = "alpha(opacity=50)";
	  theRules[4].style.filter = "alpha(opacity=50)";

	  break;
	case 1:
	  //aboutme
	  
	  /*Netscape*/
	  theRules[0].style.opacity = 0.5;
	  theRules[menu_number].style.opacity = 1;
	  theRules[2].style.opacity = 0.5;
	  theRules[3].style.opacity = 0.5;
	  theRules[4].style.opacity = 0.5;

	  /*IE*/
	  theRules[0].style.filter = "alpha(opacity=50)";
	  theRules[menu_number].style.filter = "alpha(opacity=100)";
	  theRules[2].style.filter = "alpha(opacity=50)";
	  theRules[3].style.filter = "alpha(opacity=50)";
	  theRules[4].style.filter = "alpha(opacity=50)";

	  break;
	case 2:
	  //portfolio
	  
	  /*Netscape*/
	  theRules[0].style.opacity = 0.5;
	  theRules[1].style.opacity = 0.5;
	  theRules[menu_number].style.opacity = 1;
	  theRules[3].style.opacity = 0.5;
	  theRules[4].style.opacity = 0.5;
	  
	  /*IE*/
	  theRules[0].style.filter = "alpha(opacity=50)";
	  theRules[1].style.filter = "alpha(opacity=50)";
	  theRules[menu_number].style.filter = "alpha(opacity=100)";
	  theRules[3].style.filter = "alpha(opacity=50)";
	  theRules[4].style.filter = "alpha(opacity=50)";

	  break;
	case 3:
	  //blog
	  
	  /*Netscape*/
	  theRules[0].style.opacity = 0.5;
	  theRules[1].style.opacity = 0.5;
	  theRules[2].style.opacity = 0.5;
	  theRules[menu_number].style.opacity = 1;
	  theRules[4].style.opacity = 0.5;
	  
	  /*IE*/
	  theRules[0].style.filter = "alpha(opacity=50)";
	  theRules[1].style.filter = "alpha(opacity=50)";
	  theRules[2].style.filter = "alpha(opacity=50)";
	  theRules[menu_number].style.filter = "alpha(opacity=100)";
	  theRules[4].style.filter = "alpha(opacity=50)";

	  break;
	case 4:
	  //contact
	  
	  /*Netscape*/
	  theRules[0].style.opacity = 0.5;
	  theRules[1].style.opacity = 0.5;
	  theRules[2].style.opacity = 0.5;
	  theRules[3].style.opacity = 0.5;
	  theRules[menu_number].style.opacity = 1;
	  
	  /*IE*/
	  theRules[0].style.filter = "alpha(opacity=50)";
	  theRules[1].style.filter = "alpha(opacity=50)";
	  theRules[2].style.filter = "alpha(opacity=50)";
	  theRules[3].style.filter = "alpha(opacity=50)";
	  theRules[menu_number].style.filter = "alpha(opacity=100)";

	  break;
	default:
	  //homepage
	  
	  /*Netscape*/
	  theRules[menu_number].style.opacity = 1;
	  theRules[1].style.opacity = 0.5;
	  theRules[2].style.opacity = 0.5;
	  theRules[3].style.opacity = 0.5;
	  theRules[4].style.opacity = 0.5;
	  
	  /*IE*/
	  theRules[menu_number].style.filter = "alpha(opacity=100)";
	  theRules[1].style.filter = "alpha(opacity=50)";
	  theRules[2].style.filter = "alpha(opacity=50)";
	  theRules[3].style.filter = "alpha(opacity=50)";
	  theRules[4].style.filter = "alpha(opacity=50)";

	  break;
	}
}

function reloadLogoImage() {
	var picImages = document.createElement('img');
	picImages.src = "images/magic_hat2_binary_stars.gif";
	
	
	if (getBrowser() = "Netscape") {
		picImages.setAttribute('class',"style17"); //works for FF
	}
	
	/*
	else {
		picImages.class = "style17"; //works for IE
	}
	*/
		
    var myImage = document.getElementById('logo');
    myImage.parentNode.replaceChild(picImages,myImage);
    document.addEventListener('DOMContentLoaded', reloadLogoImage, false);
}

function getBrowser() {
//Mozilla
//document.write("Browser CodeName: " + navigator.appCodeName);
//document.write("<br /><br />");

//Netscape
//document.write("Browser Name: " + navigator.appName);
//document.write("<br /><br />");
return navigator.appName;

//document.write("Browser Version: " + navigator.appVersion);
//document.write("<br /><br />");
//document.write("Cookies Enabled: " + navigator.cookieEnabled);
//document.write("<br /><br />");
//document.write("Platform: " + navigator.platform);
//document.write("<br /><br />");
//document.write("User-agent header: " + navigator.userAgent);
}

function reloadCurtainsImage() {
	var picImages = document.createElement('img');
	picImages.src = "images/the_show.gif";
    var myImage = document.getElementById('curtains');
    myImage.parentNode.replaceChild(picImages,myImage);
    document.addEventListener('DOMContentLoaded', reloadCurtainsImage, false);
}

function startspinning() {
	document.getElementById('banner-img').src='images/banner_spinning.gif';
}

function stopspinning() {
	document.getElementById('banner-img').src='images/banner.gif';
}

/* used to display a full image from a clicked thumbnail image in a new window */
function newWin(foto)
  {
  nImage = new Image();
  nImage.src = foto;
  width = screen.width;
  height = screen.height;
  i = nImage.width;
  j = nImage.height;
  k = 'no';
    if (i > screen.width)
      {
        i = screen.width - 80;
        j = nImage.height + 30;
        k = 'yes';
       }
     if (j > screen.height)
       {
         j = screen.height - 100;
         i = nImage.width + 40;
         k = 'yes';
       }
     if (width == 0 || height == 0)
       {
         i = 640;
         j = 480;
         k = 'yes';
       }
     else
       {
         i = i + 40
         j = j + 30
       }
  myWin= open("", "_blank", 
  "width="+i+",height="+j+",status=no,toolbar=no,menubar=no,scrollbars="+k+",resizable="+k+"");
  myWin.document.open();
  myWin.document.write("<html><head><title>Coding Magician - Image Preview</title></head><body bgcolor='#C0C0C0' leftmargin='7'><p align='center' style='margin-left: 10; margin-top: 10'><img border='0' src='");
  myWin.document.write(foto);
  myWin.document.write("'></p></body></html>");
  myWin.document.close();
  }
  
function getDocHeight(doc) {
var docHt = 0, sh, oh;
if (doc.height) docHt = doc.height;
else if (doc.body) {
if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
if (sh && oh) docHt = Math.max(sh, oh);
}
return docHt;
}

function setIframeHeight(iframeName) {
var iframeWin = window.frames[iframeName];
var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
if ( iframeEl && iframeWin ) {
iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
var docHt = getDocHeight(iframeWin.document);
// need to add to height to be sure it will all show
if (docHt) iframeEl.style.height = docHt + 30 + "px";
}
}

function loadIframe(iframeName, url) {
if ( window.frames[iframeName] ) {
window.frames[iframeName].location = url;
return false;
}
else return true;
}


function goSetHeight() {
if (parent == window) return;
// arg: id of iframe element this doc is to be loaded into
else parent.setIframeHeight('main_frame');
}

//-->

