// JavaScript Document

// Copyright Mike Laye, image-access.net

// JavaScript Document

  jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}
var goPage = function(thisPanel) {
    switch (thisPanel) {
	 case "BLOG":
      var reqCatID = getCatID(thisPanel);
      var thisSectionText = "test"
     thisSectionText = '<div class="text">' + thisSectionText + '<\/div>';
     $("#Blog").html(thisSectionText) ;
     break;
	 
     case "PRINT ROOM":
   //  var target="#Printroom";
    var thisHTML = "<img src='graphics\/bg_printroom.gif' \/>";
     $("#Printroom .right_wide").html(thisHTML) ;
   //  $("#Printroom .right_wide").addClass("whiteBG") ;
     var reqCatID = getCatID(thisPanel);
     var thisSectionText = eval(thisFolioRoot + "[" + reqCatID + "]['keyimage_info']")
    thisSectionText = '<div class="text">' + thisSectionText + '<\/div>';
    $("#Printroom .left_narrow").html(thisSectionText) ;
    doSubNav(thisPanel);
     break;
     case "BOOKSHOP":
     //  var target="#Bookshop";
     var reqCatID = getCatID(thisPanel);
     var thisSectionText = eval(thisFolioRoot + "[" + reqCatID + "]['keyimage_info']")
     thisSectionText = '<div class="text bookshop">' + thisSectionText + '<\/div>';
     $("#Bookshop .left_narrow").html(thisSectionText) ;
    // $("#Bookshop .right_wide").addClass("whiteBG") ;
     doSubNav(thisPanel);
     break;
     case "COMMISSIONED WORK" :
  //   var target="#Commissioned";
  //  $("#Commissioned .right_wide").addClass("whiteBG") ;
    doSubNav(thisPanel);
    goImages(thisPanel,0,0,"thumbs");
    setSelected("#commNav li", 0, "selected") ;
     break;
     case "LIBRARY":
     var reqCatID = getCatID(thisPanel);
     var titleHTML = "<div class='text'>" + eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][0]['html_content']"); + "<\/div>";
    var thisHTML = "<a href='http:\/\/www.lensmodern.com\/photographer_bio.php?id=83' target='_blank'><img src='graphics/" + eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][0]['keyimage']") + "' alt='Licensing of my Photographs is available from Lensmodern.com' \/><\/a>";
    $("#Library .left_narrow").html(titleHTML);
    $("#Library .right_wide").html(thisHTML);
     break;
     case "BIOGRAPHY & CONTACT":
     var reqCatID = getCatID(thisPanel);
    var thisSectionText = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][0]['html_content']");
     var thisHTML = '<div class="biogText">' + thisSectionText + '<\/div>';
     //thisHTML = thisHTML + '' ;
    $("#Biography .right_wide").html(thisHTML)  ;
     break;
    }
   //  var currentIndex = $(target).prevAll().length;
    // alert(currentIndex) ;

}

var doMainNav = function() {
      var thisHTML = "<ul>";
      thisArray = eval(thisFolioRoot);
      for (var i in thisArray) {
      var thisCat = thisArray[i]['mainnav_title'];
   switch (thisCat.toUpperCase()) {
    case "PRINT ROOM":
    var thisPanelName = "#Printroom";
    break;
    case "BOOKSHOP":
    var thisPanelName = "#Bookshop";
    break;
    case "COMMISSIONED WORK":
    var thisPanelName = "#Commissioned";
    break;
    case "COMMISSIONED WORK":
    var thisPanelName = "#Commissioned";
    break;
    case "LIBRARY":
    var thisPanelName = "#Library";
    break;
    case "BIOGRAPHY & CONTACT":
    var thisPanelName = "#Biography";
    break;
    case "BLOG":
    var thisPanelName = "#Blog";
    break;
    default:
    var thisPanelName = "#Home";
    }
     thisHTML = thisHTML + "<li><a href='" + thisPanelName + "'>" + thisCat + "<\/a><\/li>";
/*         thisHTML = thisHTML + "<li><a href='Javascript:goPage(\"" + thisCat + "\")'>" + thisCat + "<\/a><\/li>";   */
      }
      thisHTML = thisHTML + "<\/ul>";
     $("nav").html(thisHTML);
}

var doSubNav = function(reqCat) {
var reqCatID;
	thisArray = eval(thisFolioRoot);
for (var i in thisArray) {var thisCat = thisArray[i]['mainnav_title'];	if (thisCat.toUpperCase() == reqCat.toUpperCase()) {reqCatID = i;}}
var thisSubSection = eval(thisFolioRoot + "[" + reqCatID + "]['subnav']");
switch (reqCat.toUpperCase()) {
case "COMMISSIONED WORK":
var thisHTML = "<ul id='commNav'>";
var buttPrefix = "comm_";
for (var i=0;i<thisSubSection.length;i++) {
var thisSubMenuTitle = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['subnav_title']");
var thisHTMLStyle = "background-image:url(../graphics/" + buttPrefix + "button" + i + "_f2.gif);";
if (thisSubMenuTitle.length>12) {thisHTMLStyle = thisHTMLStyle + "height:50px;";}
//thisHTML = thisHTML + "<li style='" + thisHTMLStyle + "'><a href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"thumbs\");'>" + thisSubMenuTitle.toUpperCase() + "</a><\/li>";
thisHTML = thisHTML + "<li style='" + thisHTMLStyle + "'><a href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"thumbs\");'><img src='graphics\/" + buttPrefix + "button" + i + ".gif' alt='" + thisSubMenuTitle.toUpperCase() + "' \/><span>" + thisSubMenuTitle.toUpperCase() + "<\/span></a><\/li>";
}
thisHTML = thisHTML + "<\/ul>";
$("#Commissioned .left_narrow").html(thisHTML) ;
break;
case "PRINT ROOM":
var thisHTML = "<ul id='printNav'>";
for (var i=0;i<thisSubSection.length;i++) {
var thisSubMenuTitle = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['subnav_title']");
var thisKeyImage = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['keyimage']");
thisHTML = thisHTML + "<li><a href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"full\");'><img src='key_images\/" + thisKeyImage + "' \/>" + thisSubMenuTitle + "</a><\/li>";
}
thisHTML = thisHTML + "<\/ul>";
$("#Printroom .right_wide").append(thisHTML) ;
break;
case "BOOKSHOP":
var thisHTML = "<ul id='bookNav'>";
for (var i=0;i<thisSubSection.length;i++) {
var thisSubMenuTitle = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['subnav_title']");
var thisKeyText = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['keyimage_info']");
var thisImageFolio = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + i + "]['subnav_folio']");
var thisKeyImage = thisImageFolio[0].filename;
thisHTML = thisHTML + "<li><a href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"thumbs\");'><img src='core\/ti\/" + thisKeyImage + "' \/></a><a class='bookTitle' href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"thumbs\");'>" + thisSubMenuTitle + "</a>" + thisKeyText ;
if (thisSubMenuTitle.toUpperCase() != "SEAGULLS ARE MAGIC EAST") {
thisHTML = thisHTML + "<p><a class='previewLink' href='Javascript:goImages(\"" + reqCat + "\"," + i + ",0,\"thumbs\");'>Preview the book<\/a>"; }
thisHTML = thisHTML + "<\/li>";
}
thisHTML = thisHTML + "<\/ul>";
$("#Bookshop .right_wide").html(thisHTML) ;
break;
default:
//var thisHTML = "<ul>";/* */
}
}

function goImages(reqCat,reqFolioID,reqStart,reqFormat) {
// --- EDHEALEY EDIT --- //
 SELECTED_SUBCAT_ID = reqFolioID;
 if(reqCat.toUpperCase()=="BOOKSHOP"){
	setBook({code:thisArray[0].subnav[SELECTED_SUBCAT_ID].text_short_1});
 }
// --- END OF EDHEALEY EDIT --- //
    if(reqCat.toUpperCase()=="COMMISSIONED WORK") { setSelected("#commNav li", reqFolioID, "selected") ; }
		if (reqFormat == "full") {
		  getFullImage(reqCat,reqFolioID,reqStart,"","");
		 }
		else {
		 getThumbs(reqCat,reqFolioID,reqStart);
		}
	}

function setSelected(reqElement, reqID, reqClass) {
   // reset selected top nav items
   for (var i=0;i<($(reqElement).length);i++) {
   $(reqElement).eq(i).removeClass(reqClass) ;   }
   // and set the new one
    $(reqElement).eq(reqID).addClass(reqClass);
}

var getCatID = function(reqCat) {
var thisArray = eval(thisFolioRoot);
for (var i in thisArray) {
      var theCat = thisArray[i]['mainnav_title'];
if (reqCat.toUpperCase() == theCat.toUpperCase()) { var reqCatID = i;}
}
return reqCatID;
}

var getThumbs = function(reqCat,reqFolioID) {
 reqCatID = getCatID(reqCat);
var thisImageFolio = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + reqFolioID + "]['subnav_folio']");
// alert (thisImageFolio);
var thisHTML =  "<div class='thumbs_holder'><ol class='thumbs'>";
//var thisPosition = "left";
for (var i=0;i<thisImageFolio.length;i++) {
var reqImageFormat = "";
thisHTML =  thisHTML + "<li><div class='thumbs_image'><a href='Javascript:getFullImage(\"" + reqCat + "\",\"" + reqFolioID + "\", " + i + ",\"" + reqImageFormat +  "\",\"\");'><img src='" + thumbsImageDir + "\/" + thisImageFolio[i].filename + "' alt='" + copyline + "' \/><\/a><\/div><\/li>";
}

// ONLY NEEDED FOR EXTRA CELL OUTLINES
/*var thisgrid = thumbrows * thumbcols;

if (thisgrid > thisImageFolio.length) { var thisExtraCells = thisgrid-thisImageFolio.length;}
else {var thisExtraCells = (thumbcols - (thisImageFolio.length % thumbcols));
if (thisExtraCells == thumbcols) {thisExtraCells = 0;}
}
	for (var i=0;i<(thisExtraCells);i++) {
thisHTML =  thisHTML + "<li><table><tr><td class='thumbs'><\/td><\/tr><\/table><\/li>";
} */
//alert(thisHTML);
thisHTML =  thisHTML + "<\ol><!--<p class='clear_all'> <\/p>--><\/div>";
switch (reqCat.toUpperCase()) {
case "COMMISSIONED WORK":
$("#Commissioned .right_wide").html(thisHTML) ;
break;
case "BOOKSHOP":
$("#Bookshop .right_wide").html(thisHTML) ;
//var titleHTML = "<div class='text'>" + textPrintroom[reqFolioID][0] + "<\/div>" ;
//$("#Bookshop .left_narrow").html(titleHTML);
var titleHTML = "<div class='text'>" + thisArray[reqCatID]['subnav'][reqFolioID].keyimage_info + "<\/div>";
//titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="red_link" href="Javascript:goPage(\'BOOKSHOP\');">OTHER TITLES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="javascript:nada();" onclick="window.open(\'buy.php?thisBook=' + reqFolioID + '&amp;select=form&amp;title=Chloe&amp;filename=cfg_0300.jpg&amp;thissizeinfo=125cm x 98cm \/ 49&quote; x 39&quote;&amp;thissizeinfo2=&amp;thissizeinfoB=61cm x 51cm \/ 24&quote; x 20&quote;&amp;thissizeinfoB2=\',\'buywin\',\'width=615,height=450,scrollbars=yes,menubar=0\');">ORDER</a></li></ul>' ;

titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="white_link" href="Javascript:doAboutBook(\'' + reqCatID + '\',\'' + reqFolioID + '\');">ABOUT THE BOOK<\/a></li><li><a class="red_link" href="Javascript:goPage(\'BOOKSHOP\');">OTHER TITLES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="#" >Buy the Book</a></li></ul>' ;

$("#Bookshop .left_narrow").html(titleHTML);
//$("#Bookshop .left_narrow").html("<p>Book description here<\/p>");
break;
case "PRINT ROOM" :
$("#Printroom .right_wide").html(thisHTML) ;
var titleHTML = "<div class='text'>" + thisArray[reqCatID]['subnav'][reqFolioID].keyimage_info + "<\/div>";
titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="red_link" href="Javascript:goPage(\'PRINT ROOM\');">OTHER GALLERIES<\/a></li></ul><\/div>' ;
$("#Printroom .left_narrow").html(titleHTML);
break;
}};

function getFullImage(reqCat,reqFolioID,reqNum,reqImageFormat,reqDirection) {
var reqCatID = getCatID(reqCat);
var thisFullImage = thisArray[reqCatID]['subnav'][reqFolioID]['subnav_folio'][reqNum].filename;
//var thisHTML = "<a href='Javascript:getThumbs(\"" + reqCat + "\"," + reqFolioID + " );'><img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/><\/a>" ;
 var thisHTML = "<img src=\"" + fullImageDir + "\/" + thisFullImage + "\" alt=\"" + copyline + "\" \/>" ;
 
// --- EDHEALEY EDIT --- //
 SELECTED_SUBCAT_ID = reqFolioID;
 SELECTED_IMAGE_ID = reqNum;
 SELECTED_IMAGE_FILENAME = thisFullImage;
// --- END OF EDHEALEY EDIT --- //

switch (reqCat.toUpperCase()) {
case "COMMISSIONED WORK":
thisHTML = "<a href='Javascript:getThumbs(\"" + reqCat + "\"," + reqFolioID + " );'>" + thisHTML + "<\/a>" ;
thisHTML = "<div id='full'><div class=full_image>" + thisHTML + "<\/div></div>";
thisHTML = thisHTML + "<div class='full_nav'><\/div>";
$("#Commissioned .right_wide").html(thisHTML);
break;
case "PRINT ROOM":
thisHTML = "<a href='Javascript:getThumbs(\"" + reqCat + "\"," + reqFolioID + " );'>" + thisHTML + "<\/a>" ;
thisHTML = "<div id='full'><div class=full_image>" + thisHTML + "<\/div></div>";
thisHTML = thisHTML + "<div class='full_nav'><\/div>";
$("#Printroom .right_wide").html(thisHTML);
var titleHTML = "<div class='text'>" + thisArray[reqCatID]['subnav'][reqFolioID].keyimage_info + "<\/div>";


// --- EDHEALEY EDIT --- //
//titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="red_link" href="Javascript:goPage(\'PRINT ROOM\');">OTHER GALLERIES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="javascript:nada();" onclick="window.open(\'buy.php?thisImg=' + thisFullImage + '&amp;select=form&amp;title=Chloe&amp;filename=cfg_0300.jpg&amp;thissizeinfo=125cm x 98cm \/ 49&quote; x 39&quote;&amp;thissizeinfo2=&amp;thissizeinfoB=61cm x 51cm \/ 24&quote; x 20&quote;&amp;thissizeinfoB2=\',\'buywin\',\'width=615,height=450,scrollbars=yes,menubar=0\');">ORDER</a></li></ul><\/div>' ;' ;

titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="red_link" href="Javascript:goPage(\'PRINT ROOM\');">OTHER GALLERIES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="#" >Print Sales</a></li></ul>' ;

// --- END OF EDHEALEY EDIT --- //

$("#Printroom .left_narrow").html(titleHTML);
break;
case "BOOKSHOP":
thisHTML = "<a href='Javascript:getThumbs(\"" + reqCat + "\"," + reqFolioID + " );'>" + thisHTML + "<\/a>" ;
thisHTML = "<div id='full'><div class=full_image>" + thisHTML + "<\/div></div>";
thisHTML = thisHTML + "<div class='full_nav'><\/div>";
$("#Bookshop .right_wide").html(thisHTML);
//var titleHTML = "<div class='text'>Info here<\/div>" ;
// var titleHTML = "<div class='text'>" + textPrintroom[reqFolioID][0] + "<\/div>" ;
var titleHTML = "<div class='text'>" + thisArray[reqCatID]['subnav'][reqFolioID].keyimage_info + "<\/div>";

//titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="red_link" href="Javascript:goPage(\'BOOKSHOP\');">OTHER TITLES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="javascript:nada();" onclick="window.open(\'buy.php?thisBook=' + reqFolioID + '&amp;select=form&amp;title=Chloe&amp;filename=cfg_0300.jpg&amp;thissizeinfo=125cm x 98cm \/ 49&quote; x 39&quote;&amp;thissizeinfo2=&amp;thissizeinfoB=61cm x 51cm \/ 24&quote; x 20&quote;&amp;thissizeinfoB2=\',\'buywin\',\'width=615,height=450,scrollbars=yes,menubar=0\');">ORDER</a></li></ul>' ;

titleHTML = titleHTML + '<div class="PrintOrderLink"><ul><li><a class="white_link" href="Javascript:doAboutBook(\'' + reqCatID + '\',\'' + reqFolioID + '\');">ABOUT THE BOOK<\/a></li><li><a class="red_link" href="Javascript:goPage(\'BOOKSHOP\');">OTHER TITLES<\/a></li><li><a href="PDFs/thePICTURE_TandC.pdf" target="_blank">Terms &amp; Conditions</a></li><li><a class="orderButton" href="#" >Buy the Book</a></li></ul>' ;
$("#Bookshop .left_narrow").html(titleHTML);
break;
}
//if (reqCat != 0) {
getFullImageNav(reqCat,reqCatID,reqFolioID,reqNum);
// }
}

function getFullImageNav(reqCat,reqCatID,reqFolioID,reqNum) {
	var thisFolio = eval(thisFolioRoot + "[" + reqCatID + "]['subnav'][" + reqFolioID + "]['subnav_folio']");
var thisImageTitle = thisArray[reqCatID]['subnav'][reqFolioID]['subnav_folio'][reqNum].content_1;
//alert(thisImageTitle);
	var thisFolioLength = thisFolio.length;
	var prevNum = reqNum;
//	if (thisAdj) {prevNum=prevNum-1;}
if (prevNum > 0)
	{ var thisprevHTML = "<a href='Javascript:getFullImage(\"" + reqCat + "\"," + reqFolioID + "," + (prevNum-1) + ",\"\",\"prev\");'>&lt;<\/a>"; }
else { var thisprevHTML = "&lt;";}
if (reqNum < (thisFolioLength-1))
	{ var thisnextHTML = "<a href='Javascript:getFullImage(\"" + reqCat + "\"," + reqFolioID + "," + (reqNum+1) + ",\"\",\"next\");'>&gt;<\/a>"; }
else {var thisnextHTML = "&gt;"; }
var thiscountHTML = (reqNum+1) + " \/ " + thisFolioLength;
var thisThumbsLinkHTML = "<a href='Javascript:getThumbs(\"" + reqCat + "\"," + reqFolioID + ");' id='butt_thumbs'><img src='graphics/thumbs.gif' alt='view thumbnails' title='view thumbnails'><\/a>";
var thisHTML = thisThumbsLinkHTML + thisImageTitle + "<ul id='nav_butts'><li id='butt_prev'>" + thisprevHTML + "<\/li><li id='butt_count'>" + thiscountHTML + "<\/li><li id='butt_next'>" + thisnextHTML + "<\/li><\/ul>";
switch (reqCat.toUpperCase()) {
case "COMMISSIONED WORK": /**/
$("#Commissioned .full_nav").html(thisHTML);
break;
case "PRINT ROOM" :
$("#Printroom .full_nav").html(thisHTML);
break;
case "BOOKSHOP" :
$("#Bookshop .full_nav").html(thisHTML);
break;
}
	}

function doMailSignUp(reqlang) {
 var thisBenefitsText = "<iframe src ='benefits_gb.htm' width='425' height='250'></iframe>";
    // var thisBenefitsText = "<iframe src ='mail_list_gb.htm' width='425' height='250'></iframe>";
  	$("#dialog_benefit").html(thisBenefitsText);
    $("#dialog_benefit").dialog("open");
 }

 function doAboutBook(reqCatID,reqFolioID) {
   var moreBookTitle  = thisArray[reqCatID]['subnav'][reqFolioID].subnav_title;
    var moreBookInfo =  "<h2>" + moreBookTitle + "</h2>" + thisArray[reqCatID]['subnav'][reqFolioID].long_description ;
//alert(moreBookInfo);
$("#dialog_book_about").html( moreBookInfo);
$("#dialog_book_about").dialog("open");
 }


