var tradegothic13 = {
	src: '/swf/tradegothic13.swf'
};
var tradegothic13_footer = {
	src: '/swf/tradegothic13.swf'
};
var century_schoolbook24 = {
	src: '/swf/century_schoolbook.swf'
};
var century_schoolbook18 = {
	src: '/swf/century_schoolbook.swf'
};
var scott13 = {
	src: '/swf/scott13.swf'
};
var scott16 = {
	src: '/swf/scott13.swf'
};
var scott13_gallerydetail = {
	src: '/swf/scott13.swf'
};
var scott16_gallerydetail = {
	src: '/swf/scott13.swf'
};
sIFR.delayCSS = true;
sIFR.activate(tradegothic13);
sIFR.activate(century_schoolbook24);
sIFR.activate(century_schoolbook18);
sIFR.activate(scott13);
sIFR.activate(scott16);

/*sIFR.replace(tradegothic13, {
	selector: '#box #header ul.main_nav li span',
	css: [
	'.sIFR-root {color:#6c86a4; font-size:13px; text-transform:uppercase; text-align:center}',
	,'a:link { color: #6c86a4; }'
	,'a:hover { color: #b83328; }'	
	],	
	wmode: 'transparent', tuneHeight: -8, offsetTop:0, fixHover:'true'
});*/
/*sIFR.replace(tradegothic13_footer, {
	selector: '#box #inside_footer ul.footer_nav li span',
	css: [
	'.sIFR-root {color:#6c86a4; font-size:13px; text-transform:uppercase; text-align:center}',
	,'a:link { color: #6c86a4; }'
	,'a:hover { color: #b83328; }'	
	],	
	wmode: 'transparent', tuneHeight: -8, offsetTop:0, fixHover:'true'
});*/
sIFR.replace(century_schoolbook24, {
	selector: '#contentbox h1',
	css: [
	'.sIFR-root {color:#c31231; font-size:24px; text-transform:uppercase; text-align:left}',
	],	
	wmode: 'transparent', tuneHeight: 0, offsetTop:0, fixHover:'true'
});
sIFR.replace(century_schoolbook18, {
	selector: '#contentbox h2',
	css: [
	'.sIFR-root {color:#c31231; font-size:18px; text-align:left}',
	],	
	wmode: 'transparent', tuneHeight: 0, offsetTop:0, fixHover:'true'
});
sIFR.replace(scott16, {
	selector: 'ul.gallery li a span',
	css: [
	'.sIFR-root {color:#333333; font-size:16px; text-align:center}',
	],	
	wmode: 'transparent', tuneHeight: -6, offsetTop:0, fixHover:'true'
});
sIFR.replace(scott13, {
	selector: 'ul.gallery li small',
	css: [
	'.sIFR-root {color:#333333; font-size:13px; text-align:center}',
	],	
	wmode: 'transparent', tuneHeight: 0, offsetTop:0, fixHover:'true'
});
sIFR.replace(scott16_gallerydetail, {
	selector: 'table.gallerydetail span',
	css: [
	'.sIFR-root {color:#333333; font-size:16px; text-align:center; }',
	],	
	wmode: 'transparent', tuneHeight: -6, offsetTop:0, fixHover:'true'
});
sIFR.replace(scott13_gallerydetail, {
	selector: 'table.gallerydetail small',
	css: [
	'.sIFR-root {color:#333333; font-size:13px; text-align:center; }',
	],	
	wmode: 'transparent', tuneHeight: 0, offsetTop:0, fixHover:'true'
});
/*
if(typeof sIFR == "function"){
	sIFR.replaceElement(named({sSelector:"#box #header ul.main_nav li a", sFlashSrc:"/swf/tradegothic13.swf", sColor:"#6c86a4", sLinkColor:"#6c86a4", sBgColor:"#d8d186", sHoverColor:"#b83328", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=1", sCase:"upper"}));
	sIFR.replaceElement(named({sSelector:"#box #inside_footer ul.footer_nav li a", sFlashSrc:"/swf/tradegothic13.swf", sColor:"#6c86a4", sLinkColor:"#6c86a4", sBgColor:"#d8d186", sHoverColor:"#b83328", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=1", sCase:"upper"}));
	sIFR.replaceElement(named({sSelector:"#contentbox h1", sFlashSrc:"/swf/century_schoolbook24.swf", sColor:"#c31231", sLinkColor:"#c31231", sBgColor:"#FFFFFF", sHoverColor:"#c31231", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1", sCase:"upper"}));
	sIFR.replaceElement(named({sSelector:"#contentbox h2", sFlashSrc:"/swf/century_schoolbook18.swf", sColor:"#c31231", sLinkColor:"#c31231", sBgColor:"#FFFFFF", sHoverColor:"#c31231", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));
	sIFR.replaceElement(named({sSelector:"ul.gallery li a span", sFlashSrc:"/swf/scott16.swf", sColor:"#333333", sLinkColor:"#333333", sBgColor:"#FFFFFF", sHoverColor:"#333333", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
	sIFR.replaceElement(named({sSelector:"ul.gallery li small", sFlashSrc:"/swf/scott13.swf", sColor:"#333333", sLinkColor:"#333333", sBgColor:"#FFFFFF", sHoverColor:"#333333", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
	sIFR.replaceElement(named({sSelector:"table.gallerydetail span", sFlashSrc:"/swf/scott16.swf", sColor:"#333333", sLinkColor:"#333333", sBgColor:"#FFFFFF", sHoverColor:"#333333", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
	sIFR.replaceElement(named({sSelector:"table.gallerydetail small", sFlashSrc:"/swf/scott13.swf", sColor:"#333333", sLinkColor:"#333333", sBgColor:"#FFFFFF", sHoverColor:"#333333", sWmode:"transparent", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
}
*/

var customMessageUpdateInterval;


var myrules = {
	'#box #header .home_link' : function(el){
		el.onclick = function(){
			window.location='/';
		}
	},
	'.header_ecom #checkout_btn' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_checkout_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_checkout_btn.png';
		}
	},
	'.header_ecom #search_btn' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_search_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_search_btn.png';
		}
		el.onclick = function(){
			$('search_form').submit();
		}
	},
	'#sub_header #shop_by_product' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_shopby_product_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_shopby_product_btn.png';
		}
	},
	'#sub_header #shop_by_pet' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_shopby_pet_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_shopby_pet_btn.png';
		}
	},
	'#sub_header #shop_by_brand' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_shopby_brand_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_shopby_brand_btn.png';
		}
	},
	'#sub_header #shop_by_overstock' : function(el){
		el.onmouseover = function(){
			this.src = '/img/p_shopby_overstock_hover_btn.png';
		}
		el.onmouseout = function(){
			this.src = '/img/p_shopby_overstock_btn.png';
		}
	},
	'.story #story_read' : function(el){
		el.onmouseover = function(){
			this.src = '/images/story/story1_but_read_on.gif';
		}
		el.onmouseout = function(){
			this.src = '/images/story/story1_but_read_off.gif';
		}
	},
	'#pic_thumbnails a' : function(element){
      element.onclick = function(){
		 $('pic_thumbnails').getElementsBySelector('li').each(function(listEl){listEl.show();});
         $('large_img').src = this.href;
         $('large_img').title = this.title + " (click for larger version)";
         $('large_img').alt = this.title;
		 $('largeProductImageLink').href = this.rel;
		 this.parentNode.hide();
         return false;
      }
    },
	'#add_custom_message' : function(element){
      element.onclick = function(){
		  if(this.checked){
			  $('custom_message_field').show();
		  }
		  else{
			  $('custom_message_field').hide();
		  }
      }
    },
	'#custom_message_entry' : function(element){
      element.onfocus = function(){
		  customMessageUpdateInterval = window.setInterval(updateCustomMessageLength,500);
      }
      element.onblur = function(){
		  clearInterval(customMessageUpdateInterval);
      }
    },
	'#largeProductImageLink' : function(element){
      element.onclick = function(){
		  var win = new Window({destroyOnClose:true, className:"alphacube", id:"largeImageWindow", width: 640, height:480, resizable:false, minimizable:false, maximizable:false, onClick: function(){top.Windows.close('largeImageWindow')}});
		  win.setHTMLContent("<center><img src='"+element.href+"' onClick=\"top.Windows.close('largeImageWindow')\" title='Click to close' /></center>");
		  win.showCenter();
		  win.setTitle($('large_img').alt);
		  return false;
      }
    },
	'#chewsOrganic_content #form_name' : function(el){
		el.onfocus = function(){
			if(this.value=="Your Name") this.value = "";
			this.style.color='#000000';
			this.style.backgroundColor='#FAF9C6';
			this.style.border='1px solid #910000';
		}
		el.onblur = function(){
			if(this.value=="") this.value = "Your Name";
			this.style.color='#666666';
			this.style.backgroundColor='#ffffff';
			this.style.border='1px solid #A7A6AA';
		}
	},
	'#chewsOrganic_content #form_email' : function(el){
		el.onfocus = function(){
			if(this.value=="Your E-Mail Address") this.value = "";
			this.style.color='#000000';
			this.style.backgroundColor='#FAF9C6';
			this.style.border='1px solid #910000';
		}
		el.onblur = function(){
			if(this.value=="") this.value = "Your E-Mail Address";
			this.style.color='#666666';
			this.style.backgroundColor='#ffffff';
			this.style.border='1px solid #A7A6AA';
		}
	}
};
Behaviour.register(myrules);

function updateCustomMessageLength(){
	var len = $F('custom_message_entry').length;
	if(len>500){
		$('custom_message_entry').value = $F('custom_message_entry').substring(0, 500);
		$('custom_message_length').innerHTML = "<b style='color:red'>500</b>";
	}
	else if(len == 500){
		$('custom_message_length').innerHTML = "<b style='color:red'>500</b>";
	}
	else{
		$('custom_message_length').innerHTML = len;
	}
}    


function validateVariants(f){
	/*
	 * Rewrite this to reflect the updated scope
	 */
	 
	 /*
	if(f.variants){
		if(f.variants.length==undefined){
			if(f.variants.checked) {
				Element.hide('variant_error');
				return true;
			}
			else {
				Element.show('variant_error');
				return false;
			}
		}
		else{
			var radio_choice = false;
			for (counter = 0; counter < f.variants.length; counter++){
				if (f.variants[counter].checked) radio_choice = true; 			
			}
			if (!radio_choice)	{
				Element.show('variant_error');
				return (false);
			}
			Element.hide('variant_error');
			return (true);
		}
	}
	* */
	return true;
}

/* Nifty */
var niftyOk=(document.getElementById && document.createElement && Array.prototype.push);
var niftyCss=false;

String.prototype.find=function(what){
return(this.indexOf(what)>=0 ? true : false);
}

var oldonload=window.onload;
if(typeof(NiftyLoad)!='function') NiftyLoad=function(){};
if(typeof(oldonload)=='function')
    window.onload=function(){oldonload();AddCss();NiftyLoad()};
else window.onload=function(){AddCss();NiftyLoad()};

function AddCss(){
niftyCss=true;
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","niftyCorners.css");
l.setAttribute("media","screen");
//document.getElementsByTagName("head")[0].appendChild(l);
}

function Nifty(selector,options){
if(niftyOk==false) return;
if(niftyCss==false) AddCss();
var i,v=selector.split(","),h=0;
if(options==null) options="";
if(options.find("fixed-height"))
    h=getElementsBySelector(v[0])[0].offsetHeight;
for(i=0;i<v.length;i++)
    Rounded(v[i],options);
if(options.find("height")) SameHeight(selector,h);
}

function Rounded(selector,options){
var i,top="",bottom="",v=new Array();
if(options!=""){
    options=options.replace("left","tl bl");
    options=options.replace("right","tr br");
    options=options.replace("top","tr tl");
    options=options.replace("bottom","br bl");
    options=options.replace("transparent","alias");
    if(options.find("tl")){
        top="both";
        if(!options.find("tr")) top="left";
        }
    else if(options.find("tr")) top="right";
    if(options.find("bl")){
        bottom="both";
        if(!options.find("br")) bottom="left";
        }
    else if(options.find("br")) bottom="right";
    }
if(top=="" && bottom=="" && !options.find("none")){top="both";bottom="both";}
v=getElementsBySelector(selector);
for(i=0;i<v.length;i++){
    FixIE(v[i]);
    if(top!="") AddTop(v[i],top,options);
    if(bottom!="") AddBottom(v[i],bottom,options);
    }
}

function AddTop(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Top");
if(options.find("small")){
    d.style.marginBottom=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginBottom=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginBottom=(p-5)+"px";
for(i=1;i<=lim;i++)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingTop="0";
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Bottom");
if(options.find("small")){
    d.style.marginTop=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginTop=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginTop=(p-5)+"px";
for(i=lim;i>0;i--)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateStrip(index,side,color,border,btype){
var x=CreateEl("b");
x.className=btype+index;
x.style.backgroundColor=color;
x.style.borderColor=border;
if(side=="left"){
    x.style.borderRightWidth="0";
    x.style.marginRight="0";
    }
else if(side=="right"){
    x.style.borderLeftWidth="0";
    x.style.marginLeft="0";
    }
return(x);
}

function CreateEl(x){
return(document.createElement(x));
}

function FixIE(el){
if(el.currentStyle!=null && el.currentStyle.hasLayout!=null && el.currentStyle.hasLayout==false)
    el.style.display="inline-block";
}

function SameHeight(selector,maxh){
var i,v=selector.split(","),t,j,els=[],gap;
for(i=0;i<v.length;i++){
    t=getElementsBySelector(v[i]);
    els=els.concat(t);
    }
for(i=0;i<els.length;i++){
    if(els[i].offsetHeight>maxh) maxh=els[i].offsetHeight;
    els[i].style.height="auto";
    }
for(i=0;i<els.length;i++){
    gap=maxh-els[i].offsetHeight;
    if(gap>0){
        t=CreateEl("b");t.className="niftyfill";t.style.height=gap+"px";
        nc=els[i].lastChild;
        if(nc.className=="niftycorners")
            els[i].insertBefore(t,nc);
        else els[i].appendChild(t);
        }
    }
}

function getElementsBySelector(selector){
var i,j,selid="",selclass="",tag=selector,tag2="",v2,k,f,a,s=[],objlist=[],c;
if(selector.find("#")){ //id selector like "tag#id"
    if(selector.find(" ")){  //descendant selector like "tag#id tag"
        s=selector.split(" ");
        var fs=s[0].split("#");
        if(fs.length==1) return(objlist);
        f=document.getElementById(fs[1]);
        if(f){
            v=f.getElementsByTagName(s[1]);
            for(i=0;i<v.length;i++) objlist.push(v[i]);
            }
        return(objlist);
        }
    else{
        s=selector.split("#");
        tag=s[0];
        selid=s[1];
        if(selid!=""){
            f=document.getElementById(selid);
            if(f) objlist.push(f);
            return(objlist);
            }
        }
    }
if(selector.find(".")){      //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    if(selclass.find(" ")){   //descendant selector like tag1.classname tag2
        s=selclass.split(" ");
        selclass=s[0];
        tag2=s[1];
        }
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass==""){
    for(i=0;i<v.length;i++) objlist.push(v[i]);
    return(objlist);
    }
for(i=0;i<v.length;i++){
    c=v[i].className.split(" ");
    for(j=0;j<c.length;j++){
        if(c[j]==selclass){
            if(tag2=="") objlist.push(v[i]);
            else{
                v2=v[i].getElementsByTagName(tag2);
                for(k=0;k<v2.length;k++) objlist.push(v2[k]);
                }
            }
        }
    }
return(objlist);
}

function getParentBk(x){
var el=x.parentNode,c;
while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
    el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}

function getBk(x){
var c=getStyleProp(x,"backgroundColor");
if(c==null || c=="transparent" || c.find("rgba(0, 0, 0, 0)"))
    return("transparent");
if(c.find("rgb")) c=rgb2hex(c);
return(c);
}

function getPadding(x,side){
var p=getStyleProp(x,"padding"+side);
if(p==null || !p.find("px")) return(0);
return(parseInt(p));
}

function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}

function rgb2hex(value){
var hex="",v,h,i;
var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
var h=regexp.exec(value);
for(i=1;i<4;i++){
    v=parseInt(h[i]).toString(16);
    if(v.length==1) hex+="0"+v;
    else hex+=v;
    }
return("#"+hex);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    r[i]=r[i].toString(16);
    if(r[i].length==1) r[i]="0"+r[i];
    }
return("#"+r[0]+r[1]+r[2]);
}

/* onDOMready */
Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);
    
    this._readyCallbacks.each(function(f) { f() });
    this._readyCallbacks = null;
},
  onDOMReady : function(f) {
    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);
        
        /*@cc_on @*/
        /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady(); 
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});


Event.observe(window, 'load', function(){
		Nifty(".potlist li,div.subcategory_listing li","same-height none");
		Nifty("div.potimg,#bluebox","small");
	}, false);



/* Email anti-spam */
Event.observe(window, 'load', function(){
  elements = document.getElementsByClassName('email'); 
  if(elements){
	  for(i=0;i<elements.length;i++){
		address_to_replace=elements[i].firstChild;
		real_address=address_to_replace.nodeValue.replace("*a*", "@");
		address_to_replace.nodeValue=real_address;
		address_to_replace.parentNode.setAttribute("href", "mailto:"+real_address);
	  }
  }
  bio_elements = document.getElementsByClassName('bio'); 
  if(bio_elements){
	  for(i=0;i<bio_elements.length;i++){
		  Element.toggle(bio_elements[i]);
	  }
  }
});