function CheckForm(ObjForm,mQty,iscolor,SizeAttribute,ISEmb)
{

if (iscolor == 1) 
{
if (ObjForm.color.value == 0) {
alert("Please Select Color");
myTabs.expandit(0);
//ObjForm.color.focus();
return false;
}
}

if (SizeAttribute == 'True') 
{
if (ObjForm.size.value == '0:0') {
alert("Please Select Size");
myTabs.expandit(0);
//ObjForm.size.focus();
return false;
}
}

if (ObjForm.qty.value == 0 || ObjForm.qty.value == '') {
alert("Please Enter Valid Quantity");
ObjForm.qty.value='';
//myTabs.expandit(0);
ObjForm.qty.focus();
return false;
}

if (ObjForm.qty.value > mQty) {
alert("This item is only available in " + mQty + " quantity(s)");
ObjForm.qty.value='1';
myTabs.expandit(0);
ObjForm.qty.focus();
return false;
}

if (isInteger(ObjForm.qty.value)== false)
		{
          alert("Please Enter Numeric Values");
			ObjForm.qty.value='';
			myTabs.expandit(0);
			ObjForm.qty.focus();
	    	return false;
		}


if (ISEmb=='1')

{
	embtxt1=ObjForm.embtxt1.value;
    embtxt2=ObjForm.embtxt2.value;
    embtxt3=ObjForm.embtxt3.value;
    embfont=ObjForm.embfont.value;
    embcolor=ObjForm.embthreadcolor.value;
    emblocation=ObjForm.emblocation.value;
    embfont2=ObjForm.embfont2.value;
    embcolor2=ObjForm.embthreadcolor2.value;
    emblocation2=ObjForm.emblocation2.value;
    embfont3=ObjForm.embfont3.value;
    embcolor3=ObjForm.embthreadcolor3.value;
    emblocation3=ObjForm.emblocation3.value;
    logostyle=ObjForm.LogoStyle.value;
//    logocolor=ObjForm.LogoThreadColor[0].value;
    logolocation=ObjForm.embLogolocation.value;


    
 if (embtxt1=='' && embcolor !='') {
  alert("First Line is Necessary for Emb");
   myTabs.expandit(2);
  ObjForm.embtxt1.focus();
  ObjForm.embtxt2.value=""
  ObjForm.embtxt3.value=""
  return false;
  }
   
 if (embtxt1=='' && emblocation !='') {
  alert("First Line is Necessary for Emb");
  myTabs.expandit(2);
  ObjForm.embtxt1.focus();
  ObjForm.embtxt2.value=""
  ObjForm.embtxt3.value=""
   return false;
   }
if (embtxt1 != '' && embfont =='') {
       alert("Select Font First");
       myTabs.expandit(2);
		ObjForm.embfont.focus();      
   		return false;
       }
       
       
 if (embtxt1 != '' && embcolor =='') {
       alert("Select Embroidery Color"); 
       myTabs.expandit(2);
       ObjForm.embthreadcolor.focus();
         return false;
       }
       
 if (embtxt1 != '' && emblocation =='') {
 alert("Select Location");
 myTabs.expandit(2);
     ObjForm.emblocation.focus();
     return false;
       }

 if (embtxt1=='' && embfont !='') {
		alert("First Line is Necessary for Emb");
		myTabs.expandit(2);
 		ObjForm.embtxt1.focus();
  ObjForm.embtxt2.value=""
  ObjForm.embtxt3.value=""
  		 return false;
   		}
   
if (embtxt1=='' && embtxt2 !='') {
	alert("First Line is Necessary for Emb");
	myTabs.expandit(2);
	ObjForm.embtxt1.focus();
	
  ObjForm.embtxt2.value=""
  ObjForm.embtxt3.value=""
	return false;
   }
   
if (embtxt1=='' && embtxt3 !='') {
 alert("First Line is Necessary for Emb");
  ObjForm.embtxt2.value=""
  ObjForm.embtxt3.value=""
  myTabs.expandit(2);
  ObjForm.embtxt1.focus();
return false;
}

if (embtxt1 !='' && embtxt3 !='' && embtxt2 =='') {
  alert("Enter 2nd Line");
  myTabs.expandit(2);
  ObjForm.embtxt2.focus();
  ObjForm.embtxt3.value=""
  return false;
  }

  
  //For Emb 2

 if (embtxt2=='' && embcolor2 !='') {
  alert("Second Line is Necessary for Emb");
  myTabs.expandit(2);
  ObjForm.embtxt2.focus();
  ObjForm.embtxt2.value='';
  ObjForm.embtxt3.value='';
  return false;
  }
   
 if (embtxt2=='' && emblocation2 !='') {
  alert("Second Line is Necessary for Emb");
  myTabs.expandit(2);
  ObjForm.embtxt2.focus();
  ObjForm.embtxt2.value='';
  ObjForm.embtxt3.value='';
   return false;
   }
if (embtxt2 != '' && embfont2 =='') {
       alert("Select Font First");
       myTabs.expandit(2);
		ObjForm.embfont2.focus();      
   		return false;
       }
       
       
 if (embtxt2 != '' && embcolor2 =='') {
       alert("Select Color"); 
       myTabs.expandit(2);
       ObjForm.embthreadcolor2.focus();
         return false;
       }
 if (embtxt2 != '' && emblocation2 =='') {
 alert("Select Location");
 myTabs.expandit(2);
     ObjForm.emblocation2.focus();
     return false;
       }

 if (embtxt2=='' && embfont2 !='') {
		alert("Second Line is Necessary for Emb");
		myTabs.expandit(2);
		ObjForm.embtxt2.focus();
  		ObjForm.embtxt2.value='';
  		ObjForm.embtxt3.value='';
  		 return false;
   		}
   


//FOR EMB 3
 if (embtxt3=='' && embcolor3 !='') {
  alert("Third Line is Necessary for Emb");
  myTabs.expandit(2);
  ObjForm.embtxt3.focus();
  return false;
  }
   
 if (embtxt3=='' && emblocation3 !='') {
  alert("Third Line is Necessary for Emb");
  myTabs.expandit(2);
  ObjForm.embtxt3.focus();
  return false;
   }
if (embtxt3 != '' && embfont3 =='') {
       alert("Select Font First");
       myTabs.expandit(2);
		ObjForm.embfont3.focus();      
   		return false;
       }
       
       
 if (embtxt3 != '' && embcolor3 =='') {
       alert("Select Color"); 
       myTabs.expandit(2);
       ObjForm.embthreadcolor3.focus();
         return false;
       }
 if (embtxt3 != '' && emblocation3 =='') {
 alert("Select Location");
 		myTabs.expandit(2);
     ObjForm.emblocation3.focus();
     return false;
       }

 if (embtxt3=='' && embfont3 !='') {
		alert("Third Line is Necessary for Emb");
		myTabs.expandit(2);
		ObjForm.embtxt3.focus();
        return false;
   		}
   		
   
   
		  if (logostyle !='' && logolocation =='' ) {
		  alert("Select Logo Location");
		  myTabs.expandit(3);
		  ObjForm.embLogolocation.focus();
		  return false;
		   }
		   
 
	   
		  if (logolocation !='' && logostyle =='' ) {
		  		  
		  alert("Select Logo Style");
		  myTabs.expandit(3);
		  ObjForm.LogoStyle.focus();
		  return false;
		   }


}

}

function CalcPrice(IsEmb,IsSize)
{
baseprice=parseFloat(document.shop1.price.value);
var myqty=document.shop1.qty.value;
if (myqty>5 && myqty<11)
{
baseprice=baseprice-0.50;
}
if (myqty>10)
{
baseprice=baseprice-1;
}
if (IsSize==1)
{
var sizevalue=document.getElementById('size').value;
var mySplitSizePrice = sizevalue.split(":");
if (mySplitSizePrice[1]!=undefined)
{
sizeprice=parseInt(mySplitSizePrice[1]);
baseprice=baseprice+sizeprice;
}
}


if (IsEmb==1)
{
	var embprice1=document.getElementById('embtxt1').value;
    var embprice2=document.getElementById('embtxt2').value;    
    var embprice3=document.getElementById('embtxt3').value;
    
    if (embprice1!=undefined)
    {
    if (embprice1!='')
    {
   		baseprice=baseprice+3.99;
   	}
    }
    if (embprice2!=undefined)
    {
    if (embprice2!='')
    {
   		baseprice=baseprice+3.99;
   	}
    }   
    if (embprice3!=undefined)
    {
    if (embprice3!='')
    {
   		baseprice=baseprice+3.99;
   	}
    }  
    
	var logoprice= document.getElementById('LogoStyle').value;
    if (logoprice!=undefined)
    {
    if (logoprice!='')
    {
   		baseprice=baseprice+4.99;
   	}
    }	
}    
  //document.getElementById('spanshowprice').innerHTML='$'+Math.round(parseFloat(baseprice));
  var newnumber = Math.round(baseprice*Math.pow(10,2))/Math.pow(10,2);
  
if (myqty == 0 || myqty == '' || myqty > 1000)
{

}  
else
{
	if (isInteger(myqty)== true)
	{
	  var itemtotal=newnumber*myqty
	  var myitemtotal = Math.round(itemtotal*Math.pow(10,2))/Math.pow(10,2);
	  document.getElementById('spanshowprice').innerHTML='$'+myitemtotal;
	  }
  }
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
        return false;
    }
    // All characters are numbers.
    return true;
}


function KeyPress() 
{
//alert(window.event.keyCode)
if (window.event.keyCode == 13){
window.event.keyCode =0;
}
}

function SelectedColor(colored,colorname,issize)
{
document.shop1.color.selectedIndex=colored;
document.getElementById('txtColor').innerHTML=colorname;
if (issize==1)
{
document.getElementById('txtSize').innerHTML='';
document.getElementById('spanMeasure').innerHTML='';
document.getElementById('size').value='0:0';
}
}

function SelectedSize(sizeIndex,SizeName)
{
document.shop1.size.value=sizeIndex;
document.getElementById('txtSize').innerHTML=SizeName;
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }	

var w=1
var h=1

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:-1000px;width:1px;height:1px;border:1px solid #888888;background:#FFFFFF;z-index:1000;"><img id="ttimg" src="images/load.gif" /></div>')

function gettrailobj()
{
	if (document.getElementById) return document.getElementById("trailimageid").style
	else if (document.all) return document.all.trailimageid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('ttimg').src='images/load.gif'
	gettrailobj().visibility="hidden"
	gettrailobj().left=-1000
	gettrailobj().top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{
		w=width
		h=height

		// followmouse()

		gettrailobj().visibility="visible"
		gettrailobj().width=w+"px"
		gettrailobj().height=h+"px"
		document.getElementById('ttimg').src=file
		document.onmousemove=followmouse
	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{

		var xcoord=20
		var ycoord=20

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj().left=xcoord+"px"
		gettrailobj().top=ycoord+"px"

	}

}
function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

}
var thumbnailviewer2={
enableTitle: true, //Should "title" attribute of link be used as description?
enableTransition: true, //Enable fading transition in IE?
hideimgmouseout: false, //Hide enlarged image when mouse moves out of anchor link? (if enlarged image is hyperlinked, always set to false!)


iefilterstring: 'progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)', //IE specific multimedia filter string
iefiltercapable: document.compatMode && window.createPopup? true : false, //Detect browser support for IE filters
preloadedimages:[], //array to preload enlarged images (ones set to display "onmouseover"
targetlinks:[], //array to hold participating links (those with rel="enlargeimage:initType")
alreadyrunflag: false, //flag to indicate whether init() function has been run already come window.onload

loadimage:function(linkobj){
var imagepath=linkobj.getAttribute("href") //Get URL to enlarged image
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
var dest=linkobj.getAttribute("rev").split("::")[1] //Get URL enlarged image should be linked to, if any
var description=(thumbnailviewer2.enableTitle && linkobj.getAttribute("title"))? linkobj.getAttribute("title") : "" //Get title attr
var imageHTML='<img src="'+imagepath+'" style="border-width: 0" />' //Construct HTML for enlarged image
if (typeof dest!="undefined") //Hyperlink the enlarged image?
imageHTML='<a href="'+dest+'">'+imageHTML+'</a>'
if (description!="") //Use title attr of the link as description?
imageHTML+='<br />'+description
if (this.iefiltercapable){ //Is this an IE browser that supports filters?
showcontainer.style.filter=this.iefilterstring
showcontainer.filters[0].Apply()
}
showcontainer.innerHTML=imageHTML
this.featureImage=showcontainer.getElementsByTagName("img")[0] //Reference enlarged image itself
this.featureImage.onload=function(){ //When enlarged image has completely loaded
if (thumbnailviewer2.iefiltercapable) //Is this an IE browser that supports filters?
showcontainer.filters[0].Play()
}
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
if (thumbnailviewer2.iefiltercapable) //Is this an IE browser that supports filters?
showcontainer.filters[0].Stop()
}
},

hideimage:function(linkobj){
var showcontainer=document.getElementById(linkobj.getAttribute("rev").split("::")[0]) //Reference container on page to show enlarged image in
showcontainer.innerHTML=""
},


cleanup:function(){ //Clean up routine on page unload
if (this.featureImage){this.featureImage.onload=null; this.featureImage.onerror=null; this.featureImage=null}
this.showcontainer=null
for (var i=0; i<this.targetlinks.length; i++){
this.targetlinks[i].onclick=null
this.targetlinks[i].onmouseover=null
this.targetlinks[i].onmouseout=null
}
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
},

init:function(){ //Initialize thumbnail viewer script
this.iefiltercapable=(this.iefiltercapable && this.enableTransition) //True or false: IE filters supported and is enabled by user
var pagelinks=document.getElementsByTagName("a")
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && /enlargeimage:/i.test(pagelinks[i].getAttribute("rel"))){ //Begin if statement: Test for rel="enlargeimage"
var initType=pagelinks[i].getAttribute("rel").split("::")[1] //Get display type of enlarged image ("click" or "mouseover")
if (initType=="mouseover"){ //If type is "mouseover", preload the enlarged image for quicker display
this.preloadedimages[this.preloadedimages.length]=new Image()
this.preloadedimages[this.preloadedimages.length-1].src=pagelinks[i].href
pagelinks[i]["onclick"]=function(){ //Cancel default click action
return false
}
}
pagelinks[i]["on"+initType]=function(){ //Load enlarged image based on the specified display type (event)
thumbnailviewer2.loadimage(this) //Load image
return false
}
if (this.hideimgmouseout)
pagelinks[i]["onmouseout"]=function(){
thumbnailviewer2.hideimage(this)
}
this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
} //end if statement
} //END FOR LOOP


} //END init() function

}


if (document.addEventListener) //Take advantage of "DOMContentLoaded" event in select Mozilla/ Opera browsers for faster init
thumbnailviewer2.addEvent(document, function(){thumbnailviewer2.alreadyrunflag=1; thumbnailviewer2.init()}, "DOMContentLoaded") //Initialize script on page load
else if (document.all && document.getElementsByTagName("a").length>0){ //Take advantage of "defer" attr inside SCRIPT tag in IE for instant init
thumbnailviewer2.alreadyrunflag=1
thumbnailviewer2.init()
}
thumbnailviewer2.addEvent(window, function(){if (!thumbnailviewer2.alreadyrunflag) thumbnailviewer2.init()}, "load") //Default init method: window.onload
thumbnailviewer2.addEvent(window, function(){thumbnailviewer2.cleanup()}, "unload")				


//for large view
var thumbnailviewer={
enableTitle: true, //Should "title" attribute of link be used as description?
enableAnimation: true, //Enable fading animation?
definefooter: '<div class="footerbar">CLOSE X</div>', //Define HTML for footer interface
defineLoading: '<img src="images/loading.gif" /> Loading Image...', //Define HTML for "loading" div

/////////////No need to edit beyond here/////////////////////////

scrollbarwidth: 16,
opacitystring: 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1',
targetlinks:[], //Array to hold links with rel="thumbnail"

createthumbBox:function(){
//write out HTML for Image Thumbnail Viewer plus loading div
document.write('<div id="thumbBox" onClick="thumbnailviewer.closeit()"><div id="thumbImage"></div>'+this.definefooter+'</div>')
document.write('<div id="thumbLoading">'+this.defineLoading+'</div>')
this.thumbBox=document.getElementById("thumbBox")
this.thumbImage=document.getElementById("thumbImage") //Reference div that holds the shown image
this.thumbLoading=document.getElementById("thumbLoading") //Reference "loading" div that will be shown while image is fetched
this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
},


centerDiv:function(divobj){ //Centers a div element on the page
var ie=document.all && !window.opera
var dom=document.getElementById
var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
var docwidth=(ie)? this.standardbody.clientWidth : window.innerWidth-this.scrollbarwidth
var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
var objwidth=divobj.offsetWidth //width of div element
var objheight=divobj.offsetHeight //height of div element
var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px" //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
divobj.style.left=docwidth/2-objwidth/2+"px" //Center div element horizontally
divobj.style.top=Math.floor(parseInt(topposition))+"px"
divobj.style.visibility="visible"
},

showthumbBox:function(){ //Show ThumbBox div
this.centerDiv(this.thumbBox)
if (this.enableAnimation){ //If fading animation enabled
this.currentopacity=0.1 //Starting opacity value
this.opacitytimer=setInterval("thumbnailviewer.opacityanimation()", 20)
}
},


loadimage:function(link){ //Load image function that gets attached to each link on the page with rel="thumbnail"
if (this.thumbBox.style.visibility=="visible") //if thumbox is visible on the page already
this.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
var imageHTML='<img src="'+link.getAttribute("href")+'" style="'+this.opacitystring+'" />' //Construct HTML for shown image
if (this.enableTitle && link.getAttribute("title")) //Use title attr of the link as description?
imageHTML+='<br />'+link.getAttribute("title")
this.centerDiv(this.thumbLoading) //Center and display "loading" div while we set up the image to be shown
this.thumbImage.innerHTML=imageHTML //Populate thumbImage div with shown image's HTML (while still hidden)
this.featureImage=this.thumbImage.getElementsByTagName("img")[0] //Reference shown image itself
this.featureImage.onload=function(){ //When target image has completely loaded
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div
thumbnailviewer.showthumbBox() //Display "thumbbox" div to the world!
}
if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload bug: panoramio.com/blog/onload-event/
this.featureImage.src=link.getAttribute("href")
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div, game over
}
},

setimgopacity:function(value){ //Sets the opacity of "thumbimage" div per the passed in value setting (0 to 1 and in between)
var targetobject=this.featureImage
if (targetobject.filters && targetobject.filters[0]){ //IE syntax
if (typeof targetobject.filters[0].opacity=="number") //IE6
targetobject.filters[0].opacity=value*100
else //IE 5.5
targetobject.style.filter="alpha(opacity="+value*100+")"
}
else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
targetobject.style.MozOpacity=value
else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
targetobject.style.opacity=value
else //Non of the above, stop opacity animation
this.stopanimation()
},

opacityanimation:function(){ //Gradually increase opacity function
this.setimgopacity(this.currentopacity)
this.currentopacity+=0.1
if (this.currentopacity>1)
this.stopanimation()
},

stopanimation:function(){
if (typeof this.opacitytimer!="undefined")
clearInterval(this.opacitytimer)
},


closeit:function(){ //Close "thumbbox" div function
this.stopanimation()
this.thumbBox.style.visibility="hidden"
this.thumbImage.innerHTML=""
this.thumbBox.style.left="-2000px"
this.thumbBox.style.top="-2000px"
},

cleanup:function(){ //Clean up routine on page unload
this.thumbLoading=null
if (this.featureImage) this.featureImage.onload=null
this.featureImage=null
this.thumbImage=null
for (var i=0; i<this.targetlinks.length; i++)
this.targetlinks[i].onclick=null
this.thumbBox=null
},

dotask:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
},

init:function(){ //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
if (!this.enableAnimation)
this.opacitystring=""
var pagelinks=document.getElementsByTagName("a")
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="thumbnail"){ //Begin if statement
pagelinks[i].onclick=function(){
thumbnailviewer.stopanimation() //Stop any currently running fade animation on "thumbbox" div before proceeding
thumbnailviewer.loadimage(this) //Load image
return false
}
this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
} //end if statement
} //END FOR LOOP
//Reposition "thumbbox" div when page is resized
this.dotask(window, function(){if (thumbnailviewer.thumbBox.style.visibility=="visible") thumbnailviewer.centerDiv(thumbnailviewer.thumbBox)}, "resize")


} //END init() function

}

thumbnailviewer.createthumbBox() //Output HTML for the image thumbnail viewer
thumbnailviewer.dotask(window, function(){thumbnailviewer.init()}, "load") //Initialize script on page load
thumbnailviewer.dotask(window, function(){thumbnailviewer.cleanup()}, "unload")
									