function embedIssuu(page) {
   
   if (typeof cat_page !== 'undefined') {
      page = cat_page;
   }
   
   my_layout = 'http%3A%2F%2Fhfgp.com%2Fissuu%2FbasicBlue%2Flayout.xml';
      
   u = document.URL;
   if (u.indexOf('www.') != -1) {
      d = 'www.';
   } else {
      d = '';
   }
   d = d + 'hfgp.com';
   
   var attributes = {
            style: 'width:748px;height:704px;outline:none;',
            classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
            id: 'issuuViewer'
         };
         
         var params = {
            allowfullscreen: 'true',
            allowScriptAccess: 'always',
            menu: 'false',
            wmode: 'transparent'
         };
         
         var flashvars = {
            jsAPIClientDomain: d,
            jsAPIInitCallback: 'attachListener',
            shareMenuEnabled: 'false',
            backgroundImage: 'http%3A%2F%2Fwww.hfgp.com%2Fissuu%2FbasicBlue%2Fcontent-panel-back.jpg',
            backgroundStretch: 'true',
            documentId: '120214182154-4965e8d574134b1d8224991521b9daa8',
            pageNumber: page,
            searchButtonEnabled: 'false',
            printButtonEnabled: 'false',
            shareButtonEnabled: 'false'           
         };
         
         swfobject.embedSWF("http://static.issuu.com/webembed/viewers/style1/v2/IssuuReader.swf", "myContent", "748", "704", "9.0.0", "issuu/swfobject/expressInstall.swf", flashvars, params, attributes);
}

function embedIssuuFull(page) {
   
   if (typeof cat_page !== 'undefined') {
      page = cat_page;
   }
   
   my_layout = 'http%3A%2F%2Fwww.hfgp.com%2Fissuu%2FbasicBlueFull%2Flayout.xml';
      
   u = document.URL;
   if (u.indexOf('www.') != -1) {
      d = 'www.';
   } else {
      d = '';
   }
   d = d + 'hfgp.com';
   
   var attributes = {
            style: 'width:955px;height:700px;outline:none;',
            classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
            id: 'issuuViewer'
         };
         
         var params = {
            allowfullscreen: 'true',
            allowScriptAccess: 'always',
            menu: 'false',
            wmode: 'transparent'
         };
         
         var flashvars = {
            jsAPIClientDomain: d,
            jsAPIInitCallback: 'attachListener',
            embedBackground: '#F5F6F6',
            shareMenuEnabled: 'false',
            backgroundColor: '#F5F6F6',
            backgroundImage: 'http%3A%2F%2Fwww.hfgp.com%2Fissuu%2FbasicBlueFull%2Fcontent-panel-back.jpg',
            backgroundStretch: 'true',
            documentId: '120214182154-4965e8d574134b1d8224991521b9daa8',
            pageNumber: page,
            searchButtonEnabled: 'false',
            printButtonEnabled: 'false',
            shareButtonEnabled: 'false' 
         };
         
         swfobject.embedSWF("http://static.issuu.com/webembed/viewers/style1/v2/IssuuReader.swf", "myContent", "955", "700", "9.0.0", "issuu/swfobject/expressInstall.swf", flashvars, params, attributes);
}

function attachListener() {
   document.getElementById("issuuViewer").addEventListener("change", "pageChange");
}

function pageChange() {
   var current_page = document.getElementById("issuuViewer").getPageNumber();
   var x = current_page%2;
   if (current_page == 1) {
      document.getElementById("print_left").href = "catalog/pdf/" + current_page + "_catalog_page_Hastings-Catalog.pdf";
      document.getElementById("print_right").href = "catalog/pdf/" + current_page + "_catalog_page_Hastings-Catalog.pdf";
   } else if (x == 1) {
      document.getElementById("print_left").href = "catalog/pdf/" + (current_page - 1) + "_catalog_page_Hastings-Catalog.pdf";
      document.getElementById("print_right").href = "catalog/pdf/" + current_page + "_catalog_page_Hastings-Catalog.pdf";
   } else if (x == 0) {
      document.getElementById("print_left").href = "catalog/pdf/" + current_page + "_catalog_page_Hastings-Catalog.pdf";
      document.getElementById("print_right").href = "catalog/pdf/" + (current_page + 1) + "_catalog_page_Hastings-Catalog.pdf";
   }
}

function openCatalog() {
   var p = document.getElementById("issuuViewer").getPageNumber();
   window.open('http://issuu.com/hastingsfiberglassproducts/docs/hastings-catalog/'+p+'?mode=window&backgroundColor=%23222222','Catalog');
   return false;
}

function copyToClipboard() {
  var p = document.getElementById("issuuViewer").getPageNumber();
  var url = 'http://issuu.com/hastingsfiberglassproducts/docs/hastings-catalog/'+p+'?mode=window&backgroundColor=%23222222';
  window.prompt ("Copy to clipboard: Ctrl+C, Enter", url);
}

function page(page_number,obj) {

   if (obj !== 0) {
   
      if (window.previous_element) {
         window.previous_element.parentNode.className = '';
      }
      
      if (window.previous_parent) {
         window.previous_parent.parentNode.className = '';
      }
      
      my_parent = obj.parentNode;
      
      if (my_parent.getElementsByTagName('li').length == 0) {
      
         window.previous_parent = my_parent.parentNode.previousSibling.previousSibling;
         window.previous_element = obj;
         
         window.previous_parent.parentNode.className = 'active';
         window.previous_element.parentNode.className = 'active';
         
      } else {
         
         window.previous_element = obj;
         window.previous_element.parentNode.className = 'active';
         
      }
   
   }
   document.getElementById('issuuViewer').setPageNumber(page_number);
}

function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('GET', strURL);
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            update_nav(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);
}

function update_nav(str){
   var fragment = create(str);
   document.body.insertBefore(fragment, document.getElementById("subnav").childNodes[1]);
}

function search_nav() {
   var form = document.forms['search_form'];
   var search_string = form.search.value;
   var url = 'search_catalog.php?s='+search_string;
   xmlhttpPost(url);
   return false;
}

function create(htmlStr) {
    var frag = document.createDocumentFragment(),
        temp = document.createElement('div');
    temp.innerHTML = htmlStr;
    while (temp.firstChild) {
        frag.appendChild(temp.firstChild);
    }
    return frag;
}

function check_for_num() {
   /* var search_string = document.catalogSearch.search.value;
   if (!isNaN(search_string)) {
      if (search_string > 0) {
         document.getElementById('issuuViewer').setPageNumber(search_string);
         
         return false;
      } else {
         return true;
      }
   } else {
      return true;
   } */
   return true;
}

