/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* This copyright notice must stay intact for legal use
* Modified for autowidth and optional starting positions in
* http://www.dynamicdrive.com/forums/showthread.php?t=11839 by jschuer1 8/5/06
***********************************************/
var crossmain="";
var IMGAR=new Array();
var POSE=0;
 //1) Set width of the "neutral" area in the center of the gallery.
var restarea=6;
 //2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed=7;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth=1000;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var startpos=0;
 //5) Set message to show at end of gallery. Enter "" to disable message.
var endofgallerymsg='<div class="left"></div>';
var startofgallerymsg='<div class="right"></div>';
function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to  default height
var winattributes="width="+actualWidth+",height="+actualHeight+",resizable=yes"
window.open(path,"", winattributes)
}

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById, scrollspeed=0, movestate='', actualwidth='', cross_scroll, ns_scroll, statusdiv, loadedyes=0, lefttime, righttime;

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function creatediv(){
statusdiv=document.createElement("div")
statusdiv.setAttribute("id","statusdiv")
document.body.appendChild(statusdiv)
statusdiv=document.getElementById("statusdiv")
//statusdiv.innerHTML=endofgallerymsg


}

function positiondiv(){
var mainobjoffset=getposOffset(crossmain, "left"),
menuheight=parseInt(crossmain.offsetHeight),
mainobjoffsetH=getposOffset(crossmain, "top");
statusdiv.style.left=mainobjoffset+(menuwidth/2)-(statusdiv.offsetWidth/2)+"px";
statusdiv.style.top=menuheight+mainobjoffsetH+"px";
}

function showhidediv(what){
if (endofgallerymsg!="") {
positiondiv();
//statusdiv.style.visibility=what;
}
POSE=what;
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function moveleft(){
if (loadedyes){
movestate="left";
if (iedom&&parseInt(cross_scroll.style.left)>(menuwidth-actualwidth)){
cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px";
showhidediv("hidden");
}
else
showhidediv("visible");
}
lefttime=setTimeout("moveleft()",10);
}

function moveright(){
if (loadedyes){
movestate="right";
if (iedom&&parseInt(cross_scroll.style.left)<0){
cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px";
showhidediv("hidden");
}
else
showhidediv("visible");
}
righttime=setTimeout("moveright()",10);
}

function motionengine(e){
var mainobjoffset=getposOffset(crossmain, "left"),
dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft,
dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop,
curposy=window.event? event.clientX : e.clientX? e.clientX: "";
curposy-=mainobjoffset-dsocx;
var leftbound=(menuwidth-restarea)/2;
var rightbound=(menuwidth+restarea)/2;
if (curposy>rightbound){
scrollspeed=(curposy-rightbound)/((menuwidth-restarea)/2) * maxspeed;
clearTimeout(righttime);
if (movestate!="left") moveleft();if(POSE!='hidden'){}
}
else if (curposy<leftbound){
scrollspeed=(leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed;
clearTimeout(lefttime);
if (movestate!="right") moveright();if(POSE!='hidden'){}







}
else
scrollspeed=0;
}

function contains_ns6(a, b) {
if (b!==null)
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion(e){
if (!window.opera||(window.opera&&e.relatedTarget!==null))
if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
clearTimeout(lefttime);
clearTimeout(righttime);
movestate="";
}
}

function fillup(id){
	MT=id;
if (iedom){
crossmain=document.getElementById? document.getElementById("motioncontainer"+id) : document.all.motioncontainer+id;
if(typeof crossmain.style.maxWidth!=='undefined')
crossmain.style.maxWidth=maxwidth+'px';
menuwidth=crossmain.offsetWidth;
cross_scroll=document.getElementById? document.getElementById("motiongallery"+id) : document.all.motiongallery+id;
actualwidth=document.getElementById? document.getElementById("trueContainer"+id).offsetWidth : document.all['trueContainer'+id].offsetWidth;
if (startpos)
cross_scroll.style.left=(menuwidth-actualwidth)/startpos+'px';
crossmain.onmousemove=function(e){
motionengine(e);
}

crossmain.onmouseout=function(e){
stopmotion(e);
showhidediv("hidden");
}
}
loadedyes=1
if (endofgallerymsg!=""){
creatediv();
positiondiv();
}
if (document.body.filters)
onresize()
}


onresize=function(){
if (typeof motioncontainer!=='undefined'&&motioncontainer.filters){
motioncontainer.style.width="0";
motioncontainer.style.width="";
motioncontainer.style.width=Math.min(motioncontainer.offsetWidth, maxwidth)+'px';
}
menuwidth=crossmain.offsetWidth;
try{cross_scroll.style.left=startpos? (menuwidth-actualwidth)/startpos+'px' : 0;}
catch(er)
{}
}
MT=0;

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

CURENTIMG="";
function openfullwin(id)
{
	CURENTIMG=id;
	document.getElementById('all').style.visibility='visible';
	document.getElementById('popup').style.visibility='visible';
	var left=findPosX(document.getElementById('img_'+id));
	var top=findPosY(document.getElementById('img_'+id));
	document.getElementById('popup').style.top=top-250;
	document.getElementById('popup').style.left=left-250;
	document.getElementById('imgbl').innerHTML='<img src="'+IMGAR[id][3]+'">';
	document.getElementById('statusi').innerHTML=IMGTEXT+' '+IMGAR[id][5]+' '+OFTEXT+' '+IMGAR[id][6];
	
}

function closepopup()
{
	document.getElementById('all').style.visibility='hidden';
	document.getElementById('popup').style.visibility='hidden';
}

function prev()
{
	var newid=IMGAR[CURENTIMG][1];
	CURENTIMG=newid;
	document.getElementById('imgbl').innerHTML='<img src="'+IMGAR[newid][3]+'">';
	document.getElementById('statusi').innerHTML=IMGTEXT+' '+IMGAR[newid][5]+' '+OFTEXT+' '+IMGAR[newid][6];
}
function next()
{
	var newid=IMGAR[CURENTIMG][2];
	CURENTIMG=newid;
	document.getElementById('statusi').innerHTML=IMGTEXT+' '+IMGAR[newid][5]+' '+OFTEXT+' '+IMGAR[newid][6];
	
	document.getElementById('imgbl').innerHTML='<img src="'+IMGAR[newid][3]+'">';
} 




function summ(){
 var type="all";
 if(!(document.all)?true:false){ type="getElementById"; }
 res=0;
for(var i=1;i<=300;i++){
	if(document.getElementById('s'+i))
	{
var name="['s"+i+"']";
if(!(document.all)?true:false){ name="('s"+i+"')"; }
res+=(eval("document."+type+name+".firstChild.nodeValue")-0);
}
}



 name="['sum']";

 if(!(document.all)?true:false){ name="('sum')"; }
 eval("document."+type+name+".innerHTML='"+res+"'");
}
function sumcount(what){
 var id=what.name.substring(1,what.name.length);
 var layer="p"+id;
 var type="all";
 var name="['"+layer+"']";
 if(!(document.all)?true:false){
 type="getElementById";
 name="('"+layer+"')";
 }

 var price=eval("document."+type+name+".firstChild.nodeValue");
 layer="s"+id;
 name="['"+layer+"']";
 if(!(document.all)?true:false){
 name="('"+layer+"')";
 }
 eval("document."+type+name+".innerHTML='"+what.value*price+"'");
}

