// JavaScript function to display drop-down menu on Ian Wright's Wedding Photography website
// (c) 2010 Flipside Web Design
// Author: Richard Adams - r.adams@flipside.co.uk

var maxwidth=600;
var barwidth=228;
var barheight=93;

var browser = '';

// Detect browser
if (navigator.appName.indexOf('Microsoft') != -1) { browser = 'IE' }
else if (navigator.appName.indexOf('Netscape') != -1) { browser = 'Netscape' }
else { browser = 'IE' } // bit pointless
var version = navigator.appVersion;

function moveBar(andHeight) {
if (browser=='IE') { var w = document.body.clientWidth; var h = document.body.clientHeight; }
else if (browser=='Netscape') { var w = window.innerWidth - 20; var h = window.innerHeight; }
else { var w = 800; var h = 400; }

if (document.getElementById) { var photostrip = document.getElementById('photostrip') }
else if (document.all) { var photostrip = document.all['photostrip'] }
else if (document.layers) { var photostrip = document.layers['photostrip'] }

if (photostrip)
  {
  if (w-barwidth > maxwidth) { photostrip.style.left = w-barwidth }
  if (barheight) { photostrip.style.top = barheight }
  if (andHeight) { photostrip.style.height = h-barheight-12 }
  }
}

function printMenu(thispage) {


var myClass = '';

document.write('<ul class=menu>');

if (thispage=='home') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_home"><a href="index.html" onMouseOver="showMenu(\'home\')" onMouseOut="hideMenu(\'home\')" class=topMenu>Home</a></li>');

if (thispage=='imageblog') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_imageblog"><a href="imageblog.html" onMouseOver="showMenu(\'imageblog\')" onMouseOut="hideMenu(\'imageblog\')" class=topMenu>Image Blog</a></li>');

if (thispage=='aboutus') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_aboutus"><a href="aboutus.html" onMouseOver="showMenu(\'aboutus\')" onMouseOut="hideMenu(\'aboutus\')" class=topMenu>About Us</a></li>');

if (thispage=='availability') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_availability"><a href="availability.html" onMouseOver="showMenu(\'availability\')" onMouseOut="hideMenu(\'availability\')" class=topMenu>Availability</a></li>');

if (thispage=='gallery') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_gallery"><a href="cgi-bin/gallery.cgi" onMouseOver="showMenu(\'gallery\')" onMouseOut="hideMenu(\'gallery\')" class=topMenu>Gallery</a></li>');

if (thispage=='slideshows') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_slideshows"><a href="cgi-bin/gallery.cgi?slideshows=1" onMouseOver="showMenu(\'slideshows\')" onMouseOut="hideMenu(\'slideshows\')" class=topMenu>Slideshows</a></li>');

if (thispage=='weddings') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_weddings"><a href="cgi-bin/recent.cgi" onMouseOver="showMenu(\'weddings\')" onMouseOut="hideMenu(\'weddings\')" class=topMenu>Recent Weddings</a></li>');

if (thispage=='examples') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_examples"><a href="cgi-bin/examples.cgi" onMouseOver="showMenu(\'examples\')" onMouseOut="hideMenu(\'examples\')" class=topMenu>Wedding Examples</a></li>');

if (thispage=='packages') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_packages"><a href="packages.html" onMouseOver="showMenu(\'packages\')" onMouseOut="hideMenu(\'packages\')" class=topMenu>Packages</a></li>');

if (thispage=='venues') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_venues"><a href="cgi-bin/venues.cgi" onMouseOver="showMenu(\'venues\')" onMouseOut="hideMenu(\'venues\')" class=topMenu>Venues</a></li>');

if (thispage=='portraits') { myClass='topMenuOn' } else { myClass='topMenu' }
document.write('<li class=menu id="menuTab_portraits"><a href="portrait.html" onMouseOver="showMenu(\'portraits\')" onMouseOut="hideMenu(\'portraits\')" class=topMenu>Portraits</a></li>');

var currentLink=thispage;
printSubmenus();
moveBar();
}

var posLeft = 0;
var posTop = 0;
var right = 0;

var stayopen = 0;
var currentmenu = '';
var currentLink='';
var menuID = '';
var count = 0;

var substayopen = 0;
var currentsubmenu = '';
var currentSubLink='';
var submenuID = '';
var subcount = 0;

function showMenu(menuID) {
  if (currentmenu != '') { stayopen = 0; closeMenu(); }
  var menuTab = document.getElementById("menuTab_"+menuID);
  var menuDiv = document.getElementById(menuID);
  findPos(menuTab);
  menuDiv.style.left = (posLeft-9)+'px';
  menuDiv.style.visibility = 'visible';
  stayopen = 1;
  currentmenu = menuID;
}

function hideMenu(menuID) {
  stayopen = 0;
  var menu = document.getElementById(menuID);

  setTimeout("closeMenu()", 2000);
}

function closeMenu() {
  if (stayopen == 1) { setTimeout("closeMenu()", 2000); return; }
  if (!currentmenu) { return }

  closeSubMenu();

  if (document.getElementById) { var element = document.getElementById(currentmenu).style }
  else if (document.all) { var element = document.all[currentmenu].style }
  else if (document.layers) { var element = document.layers[currentmenu] }

  element.visibility = 'hidden';
  currentmenu = '';
}

function showSubMenu(submenuID) {
  if (currentsubmenu != '') { substayopen = 0; closeSubMenu(); }
  var subMenu = document.getElementById(submenuID);

  // Find position for sub menu
  var currentMenuItem = document.getElementById(currentmenuitem);

  if (!subMenu || !currentMenuItem) { return }

  findPos(currentMenuItem);
  var width = currentMenuItem.offsetWidth;

  subMenu.style.visibility = 'visible';
  subMenu.style.left = (posLeft+width+1)+'px';
  subMenu.style.top = posTop+'px';
  stayopen = 1;
  currentsubmenu = submenuID;
}

function hideSubMenu(submenuID) {
  substayopen = 0;
  var subMenu = document.getElementById(submenuID);

  if (!subMenu) { currentsubmenu = ''; return; }

  setTimeout("closeSubMenu()", 2000);
}

function closeSubMenu() {
  if (substayopen == 1) { setTimeout("closeSubMenu()", 2000); return; }
  if (!currentsubmenu) { return }

  var subMenu = document.getElementById(currentsubmenu)

  subMenu.style.visibility = 'hidden';
  currentsubmenu = '';
  stayopen = 0;
  hideMenu(currentmenu);
}

function printSubmenus() {

printMenustart('home');
printMenuitem('index.html', 'Home - Welcome');
printMenuitem('contactus.html', 'Contact details and form');
printMenuend();

printMenustart('aboutus');
printMenuitem('aboutus.html', 'About Us');
printMenuitem('commissions.html', 'Commissions');
printMenuitem('cgi-bin/contact.cgi', 'Contact Details');

printMenuitem('cgi-bin/links.cgi', 'Links to related sites');
printMenuend();

printMenustart('availability');
printMenuitem('availability.html', 'Availability');

printMenuend();

printMenustart('gallery');
printMenuitem('cgi-bin/gallery.cgi', 'Gallery Overview');
printMenuitem('cgi-bin/gallery.cgi?sid=23', 'Portfolio One');
printMenuitem('cgi-bin/gallery.cgi?sid=24', 'Portfolio Two');
printMenuitem('cgi-bin/gallery.cgi?sid=25', 'Reportage One');
printMenuitem('cgi-bin/gallery.cgi?sid=26', 'Reportage Two');
printMenuitem('cgi-bin/gallery.cgi?sid=32', 'Black and White Gallery One');
printMenuitem('cgi-bin/gallery.cgi?sid=35', 'Black and White Gallery Two');
printMenuitem('cgi-bin/gallery.cgi?sid=38', 'Sepia');
printMenuitem('cgi-bin/gallery.cgi?sid=36', 'Church Weddings');
printMenuitem('cgi-bin/gallery.cgi?sid=20', 'Ceremony Gallery');
printMenuitem('cgi-bin/gallery.cgi?sid=27', 'Guests and Groups');
printMenuitem('cgi-bin/gallery.cgi?sid=15', 'Wedding Details (Part One)');
printMenuitem('cgi-bin/gallery.cgi?sid=18', 'Wedding Details (Part Two)');
printMenuitem('cgi-bin/gallery.cgi?sid=33', 'The Art of Wedding Celebrations');

printMenuend();

printMenustart('slideshows');
printMenuitem('cgi-bin/gallery.cgi?slideshows=1', 'Slideshow Overview');
printMenuitem('cgi-bin/slideshow.cgi?sid=23', 'Portfolio One');
printMenuitem('cgi-bin/slideshow.cgi?sid=24', 'Portfolio Two');
printMenuitem('cgi-bin/slideshow.cgi?sid=25', 'Reportage One');
printMenuitem('cgi-bin/slideshow.cgi?sid=26', 'Reportage Two');
printMenuitem('cgi-bin/slideshow.cgi?sid=32', 'Black and White Gallery One');
printMenuitem('cgi-bin/slideshow.cgi?sid=35', 'Black and White Gallery Two');
printMenuitem('cgi-bin/slideshow.cgi?sid=38', 'Sepia');
printMenuitem('cgi-bin/slideshow.cgi?sid=36', 'Church Weddings');
printMenuitem('cgi-bin/slideshow.cgi?sid=20', 'Ceremony Gallery');
printMenuitem('cgi-bin/slideshow.cgi?sid=27', 'Guests and Groups');
printMenuitem('cgi-bin/slideshow.cgi?sid=15', 'Wedding Details (Part One)');
printMenuitem('cgi-bin/slideshow.cgi?sid=18', 'Wedding Details (Part Two)');
printMenuitem('cgi-bin/slideshow.cgi?sid=33', 'The Art of Wedding Celebrations');

printMenuend();

printMenustart('weddings');
printMenuitem('cgi-bin/recent.cgi', 'Recent Weddings');
printMenuitem('cgi-bin/buyprints.cgi', 'Buying Prints');
printMenuitem('cgi-bin/examples.cgi', 'Wedding Examples');
printMenuitem('cgi-bin/recent.cgi?type=Event', 'Recent Events');
printMenuend();

printMenustart('examples');
printMenuitem('cgi-bin/examples.cgi', 'Wedding Examples');
printMenuitem('cgi-bin/recent.cgi', 'Recent Weddings');
printMenuend();

printMenustart('packages');
printMenuitem('cgi-bin/showpage.cgi?page=packages.html', 'Packages Outline');

printMenuend();

printMenustart('imageblog');
printMenuitem('cgi-bin/showpage.cgi?page=guide1.html', 'An Illustrated Guide: Part 1');
printMenuitem('cgi-bin/showpage.cgi?page=guide2.html', 'An Illustrated Guide: Part 2');
printMenuitem('cgi-bin/showpage.cgi?page=gg.html', 'Guests and Groups');
printMenuitem('cgi-bin/showpage.cgi?page=sepia.html', 'Sepia');
printMenuitem('cgi-bin/showpage.cgi?page=celebrations.html', 'The Art of Wedding Celebrations');
printMenuitem('cgi-bin/showpage.cgi?page=timeless.html', 'Timelessless of Monochrome Images');
printMenuitem('cgi-bin/showpage.cgi?page=testi.html', 'What Our Brides and Grooms Say');

printMenuend();

printMenustart('venues');
printMenuitem('cgi-bin/venues.cgi', 'Reception Venues');
printMenuitem('cgi-bin/showpage.cgi?page=bishops.html', 'Bishop\'s Court, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=bor.html', 'Boringdon Hall, Plymouth');
printMenuitem('cgi-bin/showpage.cgi?page=burgh.html', 'Burgh Island, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=clovelly.html', 'Clovelly, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=combe.html', 'Combe House, Gittisham, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=escot.html', 'Escot House, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=huntsham.html', 'Huntsham Court, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=kitleyhouse.html', 'Kitley House, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=maunsel.html', 'Maunsel House, Somerset');
printMenuitem('cgi-bin/showpage.cgi?page=powderhamcastle.html', 'Powderham Castle, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=reed.html', 'Reed Hall, Exeter University');
printMenuitem('cgi-bin/showpage.cgi?page=stoodleigh.html', 'Stoodleigh Court, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=belvedere.html', 'The Haldon Belvedere, Devon');
printMenuitem('cgi-bin/showpage.cgi?page=haldon.html', 'The Lord Haldon Hotel, Devon');

printMenuend();

printMenustart('portrait');
printMenuitem('cgi-bin/showpage.cgi?page=portrait.html', 'Portrait Photography');

printMenuend();

// Add in sub-menus
// SUBMENUS
}

function printMenustart(menuname) {
document.write("<div id=\"" + menuname + "\" class=menuBlock onMouseOver=\"stayopen=1; substayopen=1\" onMouseOut=\"stayopen=0\">");
}

function printSubMenustart(menuname) {
document.write("<div id=\"" + menuname + "\" class=subMenuBlock onMouseOver=\"substayopen=1\" onMouseOut=\"substayopen=0\">");
}

function printMenuitem(link, item, hassub) {
count++;
if (!link) { link = '#' }
if (hassub) {
  document.write("<a class=\"menuItemWithSub\" id='cell"+count+"' onMouseOver=\"stayopen=1; currentmenuitem='cell"+count+"'; showSubMenu('"+hassub+"')\" onMouseOut=\"hideSubMenu('"+hassub+"')\" href=\""+link+"\" id='tab"+count+"' class=menu>" + item + "</a>\n");
  }
else {
  document.write("<a class=menuItem id='cell"+count+"' onMouseOver=\"stayopen=1; currentmenuitem='cell"+count+"'; showSubMenu('"+hassub+"')\" onMouseOut=\"hideSubMenu('"+hassub+"')\" href=\""+link+"\" id='tab"+count+"'>" + item + "</a>\n")
  }
}

function printMenuend() {
document.write("</div>");
}

function printSubMenuitem(link, item) {
subcount++;
document.write("<a class=menuItem onMouseOver=\"stayopen=1; substayopen=1;\" href=\""+link+"\" id='tab"+subcount+"'>"+item+"</a>\n");
}

function printSubMenuend() {
document.write("</div>");
}

function findPos(obj) {
if (!obj) { return }
var curleft = curtop = 0;
if (obj.offsetParent) {
  curleft = obj.offsetLeft
  curtop = obj.offsetTop
  while (obj = obj.offsetParent) {
    curleft += obj.offsetLeft
    curtop += obj.offsetTop
  }
}
posLeft = curleft;
posTop = curtop;
}

// Testimonials: View at random
function testy(classname) {
if (!classname) { classname ='' }
testimonials = new Array(
'testimonial 1',
'testimonial 2',
'testimonial 3',
'testimonial 4',
'testimonial 5'
);

var testy = Math.floor(Math.random() * testimonials.length);
document.write('<div align=center><p class=testimonial'+classname+'>'+testimonials[testy]+'<br><a href="references.html">View more references</a></p></div>');
}

function resizestrip() {
if (browser=='IE') { var w = document.body.clientWidth; var h = document.body.clientHeight; }
else if (browser=='Netscape') { var w = window.innerWidth - 20; var h = window.innerHeight; }
else { var w = 800; var h = 400; }

if (document.getElementById) { var photostrip = document.getElementById('photostrip') }
else if (document.all) { var photostrip = document.all['photostrip'] }
else if (document.layers) { var photostrip = document.layers['photostrip'] }

if (photostrip)
  {
  photostrip.style.width = w-12;
  }
}

function changePic(thispic) {
var picsrc=thispic.src;
picsrc = picsrc.replace(/thmnails\//, '');

if (document.getElementById) { var mainpic = document.getElementById('mainphoto') }
else if (document.all) { var mainpic = document.all['mainphoto'] }
else if (document.layers) { var mainpic = document.layers['mainphoto'] }

mainpic.src=picsrc;
}

// ORDERING PRINTS

var rows = 15;
var gotwid = 0; // Set in buyprints.cgi if sending details

function printrows() {
  for (var row=1; row<=rows; row++) {
    document.write('<tr bgcolor=#c5ae63><td><input type=text name="ref'+row+'" value="" size=20></td>')
    document.write('<td><select name="size'+row+'" onChange="calcMe('+row+')"><option value="0">Select...');
    document.write('<option>6x4')
    document.write('<option>7x5')
    document.write('<option>9x6')
    document.write('<option>10x8')
    document.write('<option>12x8')
    document.write('<option>15x10')
    document.write('<option>20x16')
    document.write('</select></td>')
    document.write('<td align=center><select name="finish'+row+'"><option value="0">Select...');
    document.write('<option>Gloss')
    document.write('<option>Matt')
    document.write('</select></td>')
    document.write('<td align=center><input type=text name="quantity'+row+'" value="" size=5 onChange="calcMe('+row+')" onKeyUp="calcMe('+row+')" onFocus="calcMe('+row+')" onBlur="calcMe('+row+')"></td>')
    document.write('<td><input type=text name="price'+row+'" value="" size=5 class=readonlyright readonly></td>')
    document.write('</tr>');
  }
  document.write('<input type=hidden name="rows" value="'+rows+'">');
}

function calcMe(row) {
  var eq = eval('printform.quantity'+row);
  var q = eq.value;
  var es = eval('printform.size'+row);
  var s = es[es.selectedIndex].text;
  var type = printform.type.value;

  var price = 0;
  if (s=='6x4') { price = 2.75 }
  if (s=='7x5') { price = 3.95 }
  if (s=='9x6') { price = 4.50 }
  if (s=='10x8') { price = 12.50 }
  if (s=='12x8') { price = 12.50 }
  if (s=='15x10') { price = 17.50 }
  if (s=='20x16') { price = 40 }
  var ep = eval('printform.price'+row);
  var qprice = price * q;

  qpricestr = dp(qprice)

  if (q>0 && (qprice-0)>0) { ep.value = qpricestr } else { ep.value = '' }

  var totalprints = 0;
  var subtotal = 0;
  var postage = 0;
  var totalprice = 0;
  for (var row=1; row<=rows; row++) {
    var eq = eval('printform.quantity'+row);
    totalprints += eq.value-0;
    var ep = eval('printform.price'+row);
    subtotal += ep.value-0;
  }
  if (printform.type.value=='Event') { postage = 1 }
  else if (subtotal>=15) { postage = 0 }
  else { postage = 2.5 }

  totalprice=subtotal+postage;

  if (totalprints>0) { printform.totalprints.value=totalprints } else { printform.totalprints.value='' }
  if (subtotal>0) { printform.subtotal.value=dp(subtotal) } else { printform.subtotal.value='' }
  printform.postage.value=dp(postage);
  if (totalprice>0) { printform.totalprice.value=dp(totalprice) } else { printform.totalprice.value='' }
}

function checkform() {
var error = '';
if (!gotwid) { if (printform.wid.selectedIndex<1) { error = error + ' * Please select the photo set / wedding / event you wish to order prints from\n' } }
if (!printform.totalprints.value) { error = error + ' * Please select some prints to order\n' }
if (!printform.name.value) { error = error + ' * Please enter your name\n' }
if (!printform.address.value) { error = error + ' * Please enter your address\n' }
if (!printform.postcode.value) { error = error + ' * Please enter your postcode\n' }
if (!printform.phone.value) { error = error + ' * Please enter your phone number\n' }
if (!printform.email.value) { error = error + ' * Please enter your e-mail address (or \'none\')\n' }

if (error) { alert('Please note the following to place your order:\n\n'+error); return false; }
return true;
}

function dp(todp) {
var dp = todp.toString();
pos = dp.indexOf('\.');
if (pos < 0) { dp = dp + '.00'; pos = dp.length-2 }
dp = dp.substr(0, pos+3);
if (dp.indexOf('\.') > (dp.length-3)) { dp = dp+'0' }
return dp;
}

function moveStript(andHeight) {
var stripwidth = 224;
if (browser=='IE') { var w = document.body.clientWidth; var h = document.body.clientHeight; }
else if (browser=='Netscape') { var w = window.innerWidth - 20; var h = window.innerHeight; }
else { var w = 800; var h = 400; }

if (document.getElementById) { var photostrip = document.getElementById('photolist') }
else if (document.all) { var photostrip = document.all['photolist'] }
else if (document.layers) { var photostrip = document.layers['photolist'] }

if (photostrip)
  {
  if (w-stripwidth > maxwidth) { photostrip.style.left = w-stripwidth }
  if (barheight) { photostrip.style.top = barheight }
  if (andHeight) { photostrip.style.height = h-barheight-12 }
  }
}

