/**
 * java script include for Tessera Collection 
 */

/* a popup window with an image in it */
function popupWindow(url) {
  TC_popupImageWindow = window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=50,screenY=20,top=20,left=50');
  if (window.focus) { TC_popupImageWindow.focus()}
}

/* a popup window with an link in it */
function TC_popupWindow(url, popup_width, popup_height, scrollbars_resize) {
  TC_popupLinkWindow = window.open(url,'popupLinkWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+scrollbars_resize+',resizable='+scrollbars_resize+',copyhistory=no,width='+popup_width+',height='+popup_height+',screenX=100,screenY=100,top=100,left=100');
  if (window.focus) { TC_popupLinkWindow.focus(); }
  if (window.resizeTo) { TC_popupLinkWindow.resizeTo(popup_width, popup_height); }
}

/* a popup window with an link in it */
function TC_PopupBanner(banner_string, time_date, cookie_path, cookie_domain) {
/* The test for the popup window is credited as follows: */
/*  Function:      setEvents
    Creation Date: April 5, 2004
    Programmer:    Edmond Woychowsky
    Purpose:       The purpose of this function is to attempt to open
                   a popup window to determine if a popup blocker is
                   enabled.

    Update Date:            Programmer:         Description:
 */

//var TC_popupBannerWindow;                           // Window
//var reWork = new RegExp('object','gi'); // Regular expression

//  try 
//  {
    TC_popupBannerWindow = window.open("","popupBannerWindow","dependent=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=300,height=200,screenX=610,screenY=100,top=100,left=610");
    TC_popupBannerWindow.document.write('<html><head><title>Tessera Collection - Free Shipping</title></head>');
    TC_popupBannerWindow.document.write('<meta http-equiv="Refresh" content="5; url="javascript:window.close()"');
    TC_popupBannerWindow.document.write('<body bgcolor="#daddb9">');
    TC_popupBannerWindow.document.write('<img name="Free Shipping" src="/tcc/images/TesseraCollection/FreeShippingBanner.gif" alt="Free Shipping">');
    TC_popupBannerWindow.document.write('<br><a align="right" href="javascript:window.close()">Close</a></body>');
//    if (window.focus) { TC_popupBannerWindow.focus(); }
//    if (window.setTimeout) {TC_popupBannerWindow.setTimeout("self.close()", 15000); }
//  }
//  catch(e) { }

/*  if (!reWork.test(String(TC_popupBannerWindow)))
  {
    setCookie('popup_banner', 'Blocked', time_date-(60*60*24*365*5), cookie_path, cookie_domain);
  }
  else
  {
    setCookie('popup_banner', 'Displayed', time_date+(60*60), cookie_path, cookie_domain);
  }
*/
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that swaps down images. */
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function TC_SelectAll(object) {
   object.select();
} 

function TC_swap_picture(image_path, width, height){
	var med_pict = document.getElementById("med_pict");
	med_pict.src = image_path + "-Md.jpg";
  med_pict.width = width;
  med_pict.height = height;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function MyShowImage(new_image) {
  var source = new_image.getAttribute("href");
  src_href = source.split("?");
  src_size_href = src_href[1].split(";");
  if (!document.getElementById("prodimg")) return true;
  var prod_img = document.getElementById("prodimg");

  if (document.getElementById("medprodtext"))
  {
      prod_img.innerHTML = save_innerHTML;
      prod_img = document.getElementById("prodimg");
  }

  var image = prod_img.getElementsByTagName("img");
  var anchor = prod_img.getElementsByTagName("a");
  for (var i = 0; i < image.length; i++)
	{
		if (image[i].className == "medimage") 
    {
  		image[i].setAttribute("src",src_href[0]);
  		image[i].setAttribute("width",src_size_href[0]);
  		image[i].setAttribute("height",src_size_href[1]);

      if (anchor[i].className == "medimage") 
      {
        var popup_url;
        if (POPUP_IMAGE_FILE.match("osCsid") == "osCsid")
        {
          popup_url = POPUP_IMAGE_FILE+"&image="+src_size_href[2]+"&name="+image[i].getAttribute("alt");
        }
        else
        {
          popup_url = POPUP_IMAGE_FILE+"?image="+src_size_href[2]+"&name="+image[i].getAttribute("alt");
        }
        anchor[i].onclick = function() {
          popupWindow(popup_url);
          return false;
        }
      }
		}
	}
  return false;
}
/*
v1.03 Copyright (c) 2006 Stuart Colville
http://muffinresearch.co.uk/archives/2006/04/29/getelementsbyclassname-deluxe-edition/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial 
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
IN THE SOFTWARE.
*/
  
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;    
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();                              
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
  var arrClass = strClass.split(delim);    
  for (var i = 0, j = objColl.length; i < j; i++) {                         
    var arrObjClass = objColl[i].className.split(' ');   
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]); 
          break comparisonLoop;
        }
      }
    }
  }
  return arr; 
}

// To cover IE 5 Mac lack of the push method
Array.prototype.push = function(value) {this[this.length] = value; };

function MyShowText(new_text) {
  var href = new_text.getAttribute("href");
  src_text = href.split("?");
  tags = src_text[1].split("&");
  tag_fields = tags[0].split("=");
  if (!document.getElementById("prodimg")) return true;
  var prod_img = document.getElementById("prodimg");
  var image = prod_img.getElementsByTagName("img");
  var anchor = prod_img.getElementsByTagName("a");
/*  var text = document.createTextNode(unescape(tag_fields)); */
  for (var i = 0; i < image.length; i++)
	{
		if (image[i].className == "medimage") 
    {
      if (anchor[i].className == "medimage") 
      {
        var my_parent = image[i].parentNode;
        if (getElementsByClassName("medimageparent", "div"))
        {
          save_innerHTML  = prod_img.innerHTML;
        }
        prod_img.innerHTML = '<div id="medprodtext">'+unescape(tag_fields[1])+'</div>';
        setEmailOnClick();
      }
		}
	}
  return false;
}

function getThumbImages() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("thumbscroll")) return false;
  var thumb_images = document.getElementById("thumbscroll");
  var images = getElementsByClassName("imagefile", "a", document);
  for ( var i=0; i < images.length; i++) {
    images[i].onclick = function() {
      return MyShowImage(this);
	}
    images[i].onkeypress = images[i].onclick;
  }

  var text = getElementsByClassName("textfile", "a", document);
  for ( var i=0; i < text.length; i++) {
    text[i].onclick = function() {
      return MyShowText(this);
	}
    text[i].onkeypress = text[i].onclick;
  }
}

function setProdimgPopup() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("prodimg")) return false;
  var prodimg_images = document.getElementById("prodimg");
  var anchor = prodimg_images.getElementsByTagName("a");
  for (var i=0; i<anchor.length; i++) {
    if (anchor[i].getAttribute("class") == "popup") {
      anchor[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
  }
}


function setEmailOnClick()
{
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  var email_link = getElementsByClassName("getemail", "a", document);
  for ( var i=0; i < email_link.length; i++) {
    email_link[i].onclick = function() {
      return setEmail(this);
	}
    email_link[i].onkeypress = email_link[i].onclick;
  }
}

function setEmail(email_link)
{
  var email_handle = email_link.getAttribute("alt");
  var email_subject = email_link.getAttribute("title");
  address='tesseracollection.com';
  address=(email_handle + '@' + address);
  address=("mailto:" + address + "?");
  address=(address + "subject=" + email_link.getAttribute("title"));
  email_link.setAttribute("href", address);

  return true;
}


addLoadEvent(getThumbImages);
addLoadEvent(setEmailOnClick);

