function openPicture(id)
{
//var idr = parseInt(id.rel);
document.location.href = 'http://www.vsemayki.ru/product/' + id + '?ref=4751';
}


function SmoothGallery(idOfContainer, gw, gh, itemsArray, ps ){


function construct_(idOfContainer, gw, gh, itemsArray, ps ){


var restarea=6;

var maxspeed=7;

var maxwidthOfWindow=1000;

var startpos=0;

var endofgallerymsg='<span style="font-size: 11px;">End of Gallery</span>';

var galleryWidth = gw;

var galleryHeight = gh;

this.pictSizes = arguments[4];

this.menuwidth = 0;
this.actualwidth='';
this.scrollspeed=0;
this.oldscrollspeed=0;

this.myIdOfContainer = idOfContainer;
this.myIdOfGallery = idOfContainer+"_mygallery";
this.myIdOfGalleryContainer = idOfContainer+"_trueContainer";

//// CORE ////////////

var automaticScroll = 0;
var moveTopFunction = this;

var iedom=document.all||document.getElementById,
scrollspeed=0,
movestate='',
ns_scroll,
statusdiv,
loadedyes=0;

this.lefttime = 0;
this.righttime = 0;

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=moveTopFunction.getposOffset(moveTopFunction.crossmain, "left"),
menuheight=parseInt(moveTopFunction.crossmain.offsetHeight),
mainobjoffsetH=moveTopFunction.getposOffset(moveTopFunction.crossmain, "top");
statusdiv.style.left=mainobjoffset+(moveTopFunction.menuwidth/2)-(statusdiv.offsetWidth/2)+"px";
statusdiv.style.top=menuheight+mainobjoffsetH+"px";
}

function showhidediv(what){
if (endofgallerymsg!="") {
positiondiv();
statusdiv.style.visibility=what;
}
}

this.getposOffset = function(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;
}


this.moveleft = function(){
if (loadedyes){
movestate="left";

moveTopFunction.actualwidth=document.getElementById? document.getElementById(moveTopFunction.myIdOfGalleryContainer).offsetWidth : document.all[moveTopFunction.myIdOfGalleryContainer].offsetWidth;

if (iedom&&parseInt(moveTopFunction.cross_scroll.style.left)>(moveTopFunction.menuwidth-moveTopFunction.actualwidth)){
moveTopFunction.cross_scroll.style.left=parseInt(moveTopFunction.cross_scroll.style.left)-moveTopFunction.scrollspeed+"px";
//showhidediv("hidden");
}
else{

   if( automaticScroll == 1){
       moveTopFunction.scrollspeed = 1;
       clearTimeout(moveTopFunction.lefttime);
       clearTimeout(moveTopFunction.righttime);
       moveTopFunction.righttime=setTimeout(function(){ moveTopFunction.moveright();},2000);
       return;
   }
}
}
moveTopFunction.lefttime=setTimeout(function(){ moveTopFunction.moveleft();},10);
}

this.moveright = function(){
if (loadedyes){
movestate="right";
if (iedom&&parseInt(moveTopFunction.cross_scroll.style.left)<0){
moveTopFunction.cross_scroll.style.left=parseInt(moveTopFunction.cross_scroll.style.left)+moveTopFunction.scrollspeed+"px";
//showhidediv("hidden");
}
else{

   if( automaticScroll == 1){
       moveTopFunction.scrollspeed = 1;
       clearTimeout(moveTopFunction.lefttime);
       clearTimeout(moveTopFunction.righttime);
       moveTopFunction.lefttime=setTimeout(function(){ moveTopFunction.moveleft();},2000);
       return;
   }
}
}
moveTopFunction.righttime=setTimeout(function(){ moveTopFunction.moveright();},10);
}

this.motionengine = function(e){

moveTopFunction.scrollspeed=0;

}

function startsmoothscroll(){
    moveTopFunction.scrollspeed = 1;
    automaticScroll = 1;
    moveTopFunction.moveright();
}

function galleryGoRight(){
    clearTimeout(moveTopFunction.lefttime);
    clearTimeout(moveTopFunction.righttime);

    moveTopFunction.scrollspeed = 5;
    automaticScroll = 1;
    moveTopFunction.moveright();
}

function galleryGoLeft(){
    clearTimeout(moveTopFunction.lefttime);
    clearTimeout(moveTopFunction.righttime);

    moveTopFunction.scrollspeed = 5;
    automaticScroll = 1;
    moveTopFunction.moveleft();
}

function contains_ns6(a, b) {
if (b!==null)
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

this.stopmotion = function(e){
if (!window.opera||(window.opera&&e.relatedTarget!==null))
if ((window.event&&!moveTopFunction.crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
moveTopFunction.scrollspeed = 3;
}
}

this.myCreateGalleryContent = function(){
   var retVal = "<table style='position:relative;' border='0' cellpadding='4' cellspacing='4'><tr>";
   for( i=0;i<itemsArray.length;i++){ //
       var linkString = "<a href=\"javascript:openPicture(" + itemsArray[i] + ");\"><img src=\"http://www.vsemayki.ru/catalog_img/"+itemsArray[i]+"/main.jpg\" border=1 /></a>";
       if( typeof moveTopFunction.pictSizes !=='undefined' ){
           linkString = "<a href=\"javascript:openPicture(" + itemsArray[i] + ");\"><img src=\"http://www.vsemayki.ru/catalog_img/"+
                itemsArray[i]+"/main.jpg\" border=1 width='"+
                moveTopFunction.pictSizes.width+"' height='"+
                moveTopFunction.pictSizes.height+"' /></a>";
       }
       retVal += "<td valign='top' style='white-space: normal;'>"+linkString+"</td>";
   }

   retVal += "</tr></table>";
   return retVal;
}

this.crossmain = {};
this.cross_scroll = {};

this.fillup = function(){

if (iedom){

moveTopFunction.crossmain=document.getElementById? document.getElementById(moveTopFunction.myIdOfContainer) : document.all[moveTopFunction.myIdOfContainer];

moveTopFunction.crossmain.innerHTML = "<div id=\""+moveTopFunction.myIdOfGallery+"\" style=\"position:absolute;left:0;top:0;white-space: nowrap;\"><div id=\""+moveTopFunction.myIdOfGalleryContainer+"\"></div></div>";
moveTopFunction.crossmain.style.height = galleryHeight+"px";
moveTopFunction.crossmain.style.width = galleryWidth+"px";

var cc =document.getElementById? document.getElementById(moveTopFunction.myIdOfGalleryContainer) : document.all[moveTopFunction.myIdOfGalleryContainer];
cc.innerHTML = moveTopFunction.myCreateGalleryContent();

if(typeof moveTopFunction.crossmain.style.maxwidthOfWindow!=='undefined')
moveTopFunction.crossmain.style.maxwidthOfWindow=maxwidthOfWindow+'px';
moveTopFunction.menuwidth=moveTopFunction.crossmain.offsetWidth;
moveTopFunction.cross_scroll=document.getElementById? document.getElementById(moveTopFunction.myIdOfGallery) : document.all[moveTopFunction.myIdOfGallery];
moveTopFunction.actualwidth=document.getElementById? document.getElementById(moveTopFunction.myIdOfGalleryContainer).offsetWidth : document.all[moveTopFunction.myIdOfGalleryContainer].offsetWidth;
if (startpos)
moveTopFunction.cross_scroll.style.left=(moveTopFunction.menuwidth-moveTopFunction.actualwidth)/startpos+'px';
moveTopFunction.crossmain.onmousemove=function(e){
moveTopFunction.motionengine(e);
}

moveTopFunction.crossmain.onmouseout=function(e){
moveTopFunction.stopmotion(e);
showhidediv("hidden");
}
}
loadedyes=1
if (endofgallerymsg!=""){
creatediv();
positiondiv();
}
if (document.body.filters)
onresize()

moveTopFunction.cross_scroll.style.left="0px";
moveTopFunction.cross_scroll.style.top="0px";
moveTopFunction.crossmain.style.height = galleryHeight+"px";
moveTopFunction.crossmain.style.width = galleryWidth+"px";
moveTopFunction.menuwidth=moveTopFunction.crossmain.offsetWidth;

startsmoothscroll();
}


function onresize(){
if (typeof moveTopFunction.crossmain!=='undefined'&&moveTopFunction.crossmain.filters){
moveTopFunction.crossmain.style.width="0";
moveTopFunction.crossmain.style.width="";
moveTopFunction.crossmain.style.width=Math.min(moveTopFunction.crossmain.offsetWidth, maxwidthOfWindow)+'px';
}
moveTopFunction.menuwidth=moveTopFunction.crossmain.offsetWidth;
moveTopFunction.cross_scroll.style.left=startpos? (moveTopFunction.menuwidth-moveTopFunction.actualwidth)/startpos+'px' : 0;
}

this.left = function(){
    galleryGoLeft();
}
this.right = function(){
    galleryGoRight();
}

}

return new construct_(idOfContainer, gw, gh, itemsArray, ps );

}