

var oCont,sContHTML,sActive;
sContHTML = "";
sActive = "";

function readSimpleCookie(name)
{  
	var nameEQ = name + "=";
//	if (window.opener)
//		var ca = window.opener.document.cookie.split(';');
//	else
		var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++)
	{	
	    var c = unescape(ca[i]);
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function SetSimpleCookie (name,value,days) {
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else expires = "";

//  if (window.opener)
//	window.opener.document.cookie = name + "=" + escape (value) + expires + "; path=";
//  else
	document.cookie = name + "=" + escape (value) + expires + "; path=";
}

function ThCenter(){       
    if (document.getElementById){
		var imgWidth,imgHeight,imgW_hider,imgH_hider
		
		flag = true;
		for(i=1;flag;i++){
			flag = false;
			oImgHider		= document.getElementById("th_"+i)
			oImgContainer	= document.getElementById("itw_"+i)

			if(oImgHider && oImgContainer){
				flag = true;
				imgW_hider = oImgHider.offsetWidth
				imgH_hider = oImgHider.offsetHeight
				
				imgWidth = oImgContainer.getElementsByTagName("img")[0].width;
				imgHeight = oImgContainer.getElementsByTagName("img")[0].height;

				iOffsetX = (imgW_hider - imgWidth)/2;
				iOffsetY = (imgH_hider - imgHeight)/2;

				if(oImgContainer.style){
					oImgContainer = oImgContainer.style
					oImgContainer.top = iOffsetY + 'px';
					oImgContainer.left = iOffsetX +'px';
				}
			}
		}
	}
}		
       
function SetThPanelHeight(){
   var oDvCont, arA, iImgH;
   oDvCont = document.getElementById("mainimage"); 
   if (oDvCont){
        arA = oDvCont.getElementsByTagName('img')
        if (arA) {
            iImgH = parseInt(arA[0].height);
            if (iImgH > 425) {
                document.getElementById('thumbcontainer').style.height = iImgH+'px';  
                document.getElementById('frame').style.height = (iImgH-70)+'px'; // 2x25+2x10=70 -> the up & down arrows   
            }    
        }   
   }
}
function ChangeThPanelHeight(){
   var oDvCont, arA, iImgH;
   oDvCont = document.getElementById("dvIMyCont"); 
   if (oDvCont){
        arA = oDvCont.getElementsByTagName('img')
        if (arA) {
            iImgH = parseInt(arA[0].height);
            if (iImgH > 425) {
                document.getElementById('thumbcontainer').style.height = iImgH+'px';  
                document.getElementById('frame').style.height = (iImgH-70)+'px'; // 2x25+2x10=70 -> the up & down arrows   
            }    
            else {
                document.getElementById('thumbcontainer').style.height = 425+'px';  
                document.getElementById('frame').style.height = (425-70)+'px';
            }
            
            //** update the thumbs scroller
            SetDistLimit();
            SetNavigDisplay();
        }   
   }
}

function SetThumbnailPanelWidth() {
       var w=0,n;
       var pattern = "Artists/";
       var panelid = "thumbcontainer";
       var divObj = document.getElementById(panelid)
       
       for (i=0; i<divObj.getElementsByTagName("img").length; i++){
            
            n =divObj.getElementsByTagName("img")[i].src;
            if (n.indexOf(pattern)>0 ) {
                w = divObj.getElementsByTagName("img")[i].width > w ? divObj.getElementsByTagName("img")[i].width : w;
            }
       }
       
       if ( coWid != (w+50)){
           document.getElementById(panelid).style.width = w+50+'px'; 
       }
}
//** stef-15.11.2010:: not used anymore
/*
function postGetData(dataSource, data, divID, bIsAdditFuncsExec)
{
    var XMLHttpRequestObject;
    if (window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest()
    }else if (window.ActiveXObject){
        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP")
        }

    if(XMLHttpRequestObject) {
        var obj = document.getElementById(divID);
        try{
            XMLHttpRequestObject.open("POST", dataSource);
            XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            XMLHttpRequestObject.onreadystatechange = function()
                {   
                    if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
                            var cnt = XMLHttpRequestObject.responseText;
                         
                            updateScripts(cnt, true);
                       // alert(cnt.substr(cnt.indexOf('iEf_'),70))  
                  //     for (a=0 ; a< cnt.length; a=a+2000)
                  //       alert(cnt.substr(a, 2000))
                         
                             obj.innerHTML = cnt;
                         
                        if (bIsAdditFuncsExec) {
                            ShowInfoDivs();

                            setTimeout('if (typeof initLightbox != "undefined") initLightbox();', 20);
                          
                            setTimeout('if (typeof DisplayEff == "function") {DisplayEff();}', 25);
                        }
                        
                       // setTimeout('if (GE("contImgLoad")) GE("contImgLoad").innerHTML = "";', 25);
                       setTimeout("HideLoading()", 25);
                    
                    }
                }
            XMLHttpRequestObject.send(data);
       }
        catch (e) {
            window.open(dataSource)
       }
    }
}
*/
function updateScripts( html, loadScripts){

        if(!loadScripts) return;
        
        var _parseOLDScripts = function(){
            var oCS = document.getElementById("custScript");
            if (oCS)
                if (oCS.removeNode) 
                    oCS.removeNode(true);
                else
                    oCS.innerHTML = '';
             
            var oCS = document.getElementById("custScript0");
            if (oCS)
                if (oCS.removeNode) 
                    oCS.removeNode(true);
                else
                    oCS.innerHTML = '';
         }
          
        var _parseScripts = function(){
            var docHead = document.getElementsByTagName("head")[0];
         
            var re = /(?:<style.*(?:src=[\"\'](.*)[\"\']).*>.*<\/style>)|(?:<style.*>([\S\s]*?)<\/style>)/ig; // assumes HTML well formed and then loop through it.
            var match;
            while(match = re.exec(html)){
                 var s0 = document.createElement("style");
                 if (match[1])
                    s0.src = match[1];
                 else if (match[2]){
                    s0.setAttribute("type", "text/css");
                    if(s0.styleSheet){// IE
                        s0.styleSheet.cssText = match[2];
                    } else {// w3c
                        var cssText = document.createTextNode(match[2]);
                        s0.appendChild(cssText);
                    }
                    }
                 else
                      continue;
                 docHead.appendChild(s0);
            }   
             
             
            var re = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/img; 
            var sRe = /(?:<script.*?>)/i;
            var srcRe = /\ssrc=([\'\"])(.*?)\1/i;   
            
            var match, sTagMatch, srcMatch;
          
            while(match = re.exec(html)){
                sTagMatch = match[0].match(sRe);
                if (sTagMatch) {
                    srcMatch = sTagMatch[0].match(srcRe);
                    if(srcMatch && srcMatch[2]){
                       var s = document.createElement("script");
                       s.src = srcMatch[2];
                       docHead.appendChild(s);
                    }else if(match[1] && match[1].length > 0){
                               var s = document.createElement("script");
                               s.type = 'text/javascript';
                               if(navigator.userAgent.indexOf("Safari")!=-1){//code being in a variable is important - this is Safari hack ;)
                                    window.my_code = match[1]; 
                                    s.innerHTML = 'eval(window.my_code)';
                               }
                               s.text = match[1];
                               
                               docHead.appendChild(s);
                    }                     
                }
            }
            
        }
        
        // set timeout to give DOM opportunity to catch up
        setTimeout(_parseOLDScripts, 15);
        setTimeout(_parseScripts, 20);
       

}

function ShowLoading(target){
  HideLoading();
  if (imgLoadingFile) {
        oMI = document.getElementById(target);
        if (oMI){
            var objILoading = document.createElement("div");
		    objILoading.setAttribute('id','imgLoading');
		    oMI.appendChild(objILoading);
    	
		    var objLoadingImage = document.createElement("img");
		    objLoadingImage.setAttribute('src', imgLoadingFile);
		    objILoading.appendChild(objLoadingImage);
        }
    }
 }
function HideLoading(){
    if (GE('imgLoading')) myRemoveNode(GE('imgLoading'));
} 

function DoTheJob(link,target){
    var par='z';
    
    if (link){
        ShowLoading('contImgLoad');
            
        // get & set the template content
        //**stef-15.11.2010:: setTimeout('postGetData("'+link+'", "'+par+'", "'+ target+'", true)',20);
        
        var callback = fn_callback(link);
        var conn = YAHOO.util.Connect.asyncRequest("POST", link, callback); 
    }
}

var arIFields = new Array('MyCont', 'Name','Desc','Price', 'Copy','Prev','Next', 'mgDesc', 'mgInfo');
function fn_callback(target){
    
    var callback = {
            success : function(o) {
                var rst = o.responseText;

                var otemp = document.createElement("div");
                otemp.innerHTML = rst;

                for (i=0; i< arIFields.length; i++){
                    SetDataFromTo(otemp, 'dvI'+arIFields[i]);
                    
                    if (arIFields[i] == 'MyCont'){
                        var v = GE('dvIMyCont').getElementsByTagName("img")
                        var aN=0;
                        var Lim = v.length;
                        if (Lim>0)
                            YAHOO.util.Event.on(v, 'load', function(){
                                      aN++;
                                      if (aN==Lim) ChangeThPanelHeight();
                                    }, 
                              '', true);
                    
                    }
                }
               
                          
                setTimeout('if (typeof initLightbox != "undefined") initLightbox();', 20);
                setTimeout('if (typeof DisplayEff == "function") {DisplayEff();}', 25);
                setTimeout("HideLoading()", 25);
                
                
                // initializing
                sContHTML = ""
                sActive = ""
                oCont=null;  
             
            },
            failure : function(o) {alert('fal')}
       }
    return callback;
}

function SetDataFromTo(oSrc, tgt_F){

        if (oSrc && YAHOO.util.Dom.get(tgt_F)){
            var arO, i;
            arO = oSrc.getElementsByTagName('div');
          
           for (i=0; i< arO.length; i++){
                if (arO[i].getAttribute('id') == tgt_F) 
                    {
                        var p = arO[i].innerHTML;
                        
                        YAHOO.util.Dom.get(tgt_F).innerHTML = p;
                         
                         return;
                     }
                
           }

        }
          
    }

function ShowInfoDivs(){
    var o, o1;
    var arFields = new Array('Name','Desc','Price', 'Copy','Prev','Next', 'mgDesc', 'mgInfo');
    for (a=0; a< arFields.length; a++ ){
       o = GE('dvI'+arFields[a]);
       o1 = GE('tmp_dvI'+arFields[a]);
       if (o)
           if (o1) {
                o.innerHTML = o1.innerHTML;
                o1.innerHTML = '';
                o.style.display = "block";
          }else {
               o.style.display = "none"; 
          }
    }
    // initializing
    sContHTML = ""
    sActive = ""
    oCont=null;
    
}

/*** common functions  ****/
function GE(id){
    return document.getElementById(id);
}
function GS(id,style_property){
    return parseInt(YAHOO.util.Dom.getStyle(id, style_property) );
}
function ShowEL(id){
   GE(id).style.display = "block";
}
function HideEL(id){
    GE(id).style.display = "none";
}
function FillEL(from, to){
    from = GE(from);
    to = GE(to);
    if (from && to) to.innerHTML = from.innerHTML;
}
function ShowHideE(eID, state){
    if (GE(eID))
        GE(eID).style.visibility = state;
}
function myRemoveNode(obj){
  if (obj)   
      if (obj.removeNode)
                obj.removeNode(true);
       else { 
            var parent = obj.parentNode;
            parent.removeChild(obj);
        } 
}

/**** end common functions block ***/

function MyAction(sObj1,w1,h1){
    var o;
	if(!oCont) {
		//oCont = MM_findObj('mainimage') --> stef 15/11/2010
		oCont = MM_findObj('dvIMyCont');
		if(oCont) sContHTML = oCont.innerHTML
	}
	
	if(sActive==sObj1) { 
	//	close
	    
		if(oCont) {
		    oCont.innerHTML = sContHTML
            if (typeof initLightbox != "undefined") initLightbox();
        }
		sActive=""
	}
	else{
	//show
		//o = MM_findObj(sObj1);//alert(sObj1+' : '+o)
		o = GE(sObj1);
		t=""
		if(o) {
			t = o.innerHTML
			t = "<div class=\"imgDescrCSS\" style=\"width:"+w1+"px;height:"+h1+"px\" name=\"t\">"+t+"</div>"
		}
        
		if(oCont) oCont.innerHTML = t;

		sActive=sObj1;
	}
}

 function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

var wait=false;
if(navigator.userAgent.toLowerCase().indexOf("opera")+1) wait=true; // if opera -> wait the onload event
function SetMarginTop(){
    var iObjH = 580;
    var oC = document.getElementById('cholder');
    if (oC) {
        var scrH = screen.height;
        if ((iObjH+200) < scrH)
            oC.style.marginTop = (scrH-iObjH-200)/3 + 'px';
     }
    
}

function IsDef(fName){
    return (eval('typeof '+fName) =='undefined')? false : true;
}

/********  thumbails scrolling ***********/

var iCount=0;
var gcImagesC = 0; //number of images
var ImagesCount = 0;
var igImgLoadInt;
var isFirstInst=false;
var MM_p=new Array();
var iImgWSum = 0;
var initCntW;
var isVisblScroll = false;
var panelH = 130;
var arDistO = new Array(), arDist = new Array();
arDistO[0] = 0;
arDist[0] = 0;
if (typeof _1stActPos == 'undefined') _1stActPos=1;


function MM_preloadImages() { 
    var d=document; 
    var r = GE('content');
    var a = r.getElementsByTagName('img')
    
    var i,j=MM_p.length

    gcImagesC = a.length;
    
    for(i=0; i<a.length; i++){
        MM_p[j]=new Image; 
        MM_p[j++].src=a[i].src; 
        
    }

    checkEffect();
    igImgLoadInt = setTimeout('setIBox()', 100);
}

function setIBox(){
    var a=1,oo;
    
    iImgWSumOLD = iImgWSum;
    iImgWSum = 0;
    ImagesCount = 0;

    while (GE('th'+a)){
        oo = MM_p[a-1];
        var iH = GetDims(oo,a);
        if (panelH<iH) {
            panelH = iH;
          //  GE('frame').style.height = panelH + 'px';
        }
        
        arDistO[a] = iImgWSum;
       // if (GE('content') ) GE('content').style.width = iImgWSum + 'px';
       // if (GS('content','width') < GS('frame','width')) 
        //    GE('content').style.left = (GS('frame','width') - GS('content','width'))/2  + 'px';
               
        a++;
        ImagesCount++;
    }

    clearTimeout(igImgLoadInt);
    // check if clearTimeout is required and no need to put another
    if (gcImagesC>-1){
        igImgLoadInt = setTimeout('setIBox()', 100);
    }
  
}

var padding = 5;
var imageborder = 1;
var cellspacing = 10;
var iIMG_THUMB_WIDTH = 130;
var iIMG_THUMB_HEIGHT = 70;
var arWs = new Array();
var arHs = new Array();

function GetDims(oImg, ind){
    //iImgSum carries the sum of the widths of the images
    
    var t1 = oImg;  //GE('th'+ind)
    if (t1) {
        arWs[ind-1] = t1.width+ 2*padding+ 2*imageborder;     //t1.offsetWidth;
        arHs[ind-1] = t1.height+ 2*padding+ 2*imageborder+ cellspacing;
        //iImgWSum += arWs[ind-1] ;
        iImgWSum += arHs[ind-1] ;
    }
    else {
        arWs[ind-1] = 0;    //t1.offsetWidth;
        arHs[ind-1] = 0;
        //iImgWSum += iIMG_THUMB_WIDTH+ 2*padding;
        
        //*** stef check THIS case *****************
        iImgWSum += iIMG_THUMB_HEIGHT+ 2*padding;
    }
    //return the height of the image
    return arHs[ind-1];
}
function init() {
    var a=1;
    //*** if function has been called when setIBox() has just finished
    if (gcImagesC == ImagesCount) {
        clearTimeout(igImgLoadInt);
        iImgWSum = 0;
        while (GE('th'+a)){
            oo = MM_p[a-1];
            var iH = GetDims(oo,a);
            if (panelH<iH) {
                panelH = iH;
            }
            arDistO[a] = iImgWSum;
            a++;
        }
        
        if (typeof iCurImg != 'undefined') _1stActPos = iCurImg;
        SetNavigation();
    }
    //**** if the function init() has been called while setIBox() is executing, then
    //***  call it one last time and set flag (gcImagesC = -1) to stop
    else {
    
        gcImagesC = -1;
        igImgLoadInt = setTimeout('setIBox()', 100);
        setTimeout('SetNavigation()', 115);    
       }
       
    //*** No Lightbox in Sofia 1 HTML
    //if (typeof initLightbox != "undefined") PrepareInitLightbox();
   
    //** cut the top margin of the first thumbnail in the column
    var pp = document.getElementById('shown1');
    if (pp){
        pp.style.marginTop = '0px';
    }
 /* --- STEF -- do we need this?   
    //** set the text color of the <a> of the image the same as the background of the template body. This way when new image is loaded by ajax the alt text will not be visible while the image is loading and is not visible.
    gsDocBodyBg = $('.DocBody').css('background-color');
    SetImageALTColor();
 ----- */   
    
     //** added on 14.10.2010
     
     //** with jQuery::  var pp = jQuery.css( GE('content'), 'width', false ); // =offsetWidth
     //** WITHOUT jQuery
     var pp = GE('content').offsetWidth;
     pp -= 2*10; // 10 - margin
     GE('iprev').style.width = pp + 'px';
     GE('inext').style.width = pp + 'px'; //** ends here
     
     
}

function SetNavigation(){

    SetDistLimit();
    
    SetNavigDisplay();

    SetNavigEvents();
}

function SetNavigDisplay(){
   //moved to init()--> if (typeof iCurImg != 'undefined') _1stActPos = iCurImg;
     //*** check if there is need of Previous/Next arrows or do nothing
    //** using jQuery:: if (parseInt( jQuery.css( GE('content'), 'height', false )) < GS('frame','height')) {
    //** without jQuery:
    //----------- if (GE('content').offsetHeight < GS('frame','height')) {
    var sContainer_id;
    if (GE('imagepage')) sContainer_id='thumbcontainer'; else sContainer_id='MyCont';

    if (GE('content').offsetHeight <= GS(sContainer_id,'height')) {
        bAnyNav = false;
        //** if there is no need of scroll arrows
        GE('iprev').style.display = 'none';
        GE('inext').style.display = 'none';
        
        GE('content').style.top = '0px';

        GE('frame').style.height = GS(sContainer_id,'height')+'px';
        
    }
    else {
       // GE('content').style.top = '0px';
        bAnyNav = true;
        GE('iprev').style.display = 'block';
        GE('inext').style.display = 'block';

        if (_1stActPos!=1) MoveImage(0); else checkConstraints();
        
    }

}

function SetNavigEvents(){
     //set events for prev/next buttons clicked
    YAHOO.util.Event.on('iprev', 'mousedown', MoveStrip, true);
    YAHOO.util.Event.on('inext', 'mousedown', MoveStrip, true);
    YAHOO.util.Event.on('iprev', 'mouseup', StopMoveStrip, true);
    YAHOO.util.Event.on('inext', 'mouseup', StopMoveStrip, true);
}

var iMSind, iSMSind;
var s=new Date();
var e=s;
var Limit;
var gSlideStep = 3;
var curSlideStep = gSlideStep;


function MoveStrip(){
    s = new Date()
    //this.className = this.id+'_hover';
    //*** wait 400ms before start continuously sliding
   // iSMSind = setTimeout('StartMoveStrip("'+this.id+'")',400);
    StartMoveStrip(this.id)
}
function StartMoveStrip(id){

   if (id == 'iprev') {
        par=-1; 
        Limit = 0; }
   else {
        par=1;
        Limit = arDist[arDist.length-1]; }
 
 //**  no continuosly move  for a start
 //**  iMSind = setInterval('MoveOne('+par+')',1);
}

function StopMoveStrip(){
    var par;
    
    e = new Date()
    //*** if the mouse button has been released within 400ms - then this is just single mose click
    //*** else - continuously click = sliding
    if (Math.ceil(e.getTime()-s.getTime()) < 400) {
        //*** if single click - stop the execution of the sliding function, only one position is needed
       // clearTimeout(iSMSind);
        if (this.id == 'iprev') par=-1; else par = 1;
        //** MoveImage(par);
        MoveImageSet(par);
    }
    else {
      checkConstraints(); 
    }
    //clearInterval(iMSind);
    
    //this.className = this.id;

}

function MoveOne(dir){

    var stopCond, changePosCond, changeEl;
 
    if (dir>0){ //*** next
          stopCond = ((Limit + GS('content', 'top')) <= 0 )
          changePosCond = ((arDist[_1stActPos] + GS('content', 'top')) <= 0 )  
          changeEl = changeActivePos(1, dir);
    }      
    else { //*** prev
        stopCond = ((Limit - GS('content', 'top')) <= 0 )
        changePosCond = ((arDist[_1stActPos-1] + GS('content', 'top')) >= 0 )  
        changeEl = changeActivePos(-1, dir);
   }
   
   //*** if 'Next' sliding..  
   if (dir>0) if (changePosCond) _1stActPos = changeEl;
  
   if ( stopCond ) { 
        clearInterval(iMSind);
        checkConstraints();
        return;
    }
    
     //*** if 'Prev' sliding..  
    if (dir<0) if (changePosCond) _1stActPos = changeEl;
    
    GE('content').style.top = GS('content', 'top')-dir*curSlideStep + 'px';
    //*** if after the latest movement has left less pixels than the fixed step (gSlideStep)
    //*** set the movement to take value the pixels that has left
    if (Math.abs(Limit-dir*GS('content', 'top'))< gSlideStep) curSlideStep = Math.abs(Limit-dir*GS('content', 'top'));
    else curSlideStep = gSlideStep;
    
}

function MoveImage(dir){

    var old1stActPos = _1stActPos;
    var top = GS('content', 'top');

    var mv = 0;
    if (dir>=0) {//next
        _1stActPos = _1stActPos + dir;
        mv = arDist[_1stActPos-1]; 
        if (_1stActPos>arDist.length-1)
             mv = arDist[arDist.length-1] ;
    }else {//prev
        if( (Math.abs(top) - arDist[_1stActPos-1]) > 0){//*** image is visible partially i.e the _1stActPos does not change
             mv = arDist[_1stActPos-1]; 
       }else  {
            _1stActPos = _1stActPos + dir;
            mv = arDist[_1stActPos-1]; 
        }   
    }

    var c_offset = - mv - top;     //left = GS('content', 'left');

    var anim = new YAHOO.util.Motion('content', { points: { by: [0, c_offset] } }, 1);
    anim.animate();
    //** 04.03.09 anim.onComplete.subscribe(checkConstraints) ;
    anim.onComplete.subscribe(checkStatus) ;
    
}

function MoveImageSet(dir){

    var old1stActPos = _1stActPos;
    var top = GS('content', 'top');
    var moveStep = GS('frame', 'height');

    var mv = arDist[_1stActPos-1]+ dir*moveStep;

    if (dir>=0) {//next
        
        for (a=_1stActPos-1; a<arDist.length; a+=dir){  
           _1stActPos = a;
           if (arDist[a]>=mv){       
                _1stActPos = a-dir;
                break;
           }
        }
                     
    }else {//prev
    
       for (a=0; a<arDist.length; a++){  
           _1stActPos = a;
           if (arDist[a]>=mv) break;
        }  
    }
    
    mv = arDist[_1stActPos];
        
    var c_offset = - mv - top;     
    //alert(c_offset)
    //c_offset = -dir*GS('frame', 'height');

    var anim = new YAHOO.util.Motion('content', { points: { by: [0, c_offset] } }, 1);
    anim.animate();
    anim.onComplete.subscribe(checkStatus) ;
    
}
function changeActivePos(step, dir){
    var _new1stActPos = _1stActPos+step;
    return _new1stActPos;
}

var nl = '\n';
function SetDistLimit(){
   //** with jQuery::  var p = jQuery.css( GE('content'), 'height', false );
   //** WITHOUT jQuery
   var p = GE('content').offsetHeight;
   var slideLimit = p - GS('frame','height');
   
   arDist = new Array();
   arDist[0]=0;
   for (a=1; a<arDistO.length; a++){
        if (arDistO[a]<slideLimit) {
            arDist[a]= arDistO[a];
        }        
        else {
            arDist[a]= slideLimit;
            break;
         }
   }
}

function checkConstraints(){
/* this will be changed ****
    if (!bAnyNav){ //***if previously there have been some navigation arrows but we dont need it
        ShowHideE('iprev', 'hidden');
        ShowHideE('inext', 'hidden');
        return;
    }
    if (_1stActPos<=1 && GS('content','top')==0) ShowHideE('iprev', 'hidden'); else  ShowHideE('iprev', 'visible');
    if (_1stActPos>arDist.length) _1stActPos = arDist.length;
    if (_1stActPos == arDist.length ) ShowHideE('inext', 'hidden'); else  ShowHideE('inext', 'visible');
    
  *****/
   if (GE("assetpage")){
       if (_1stActPos<=1 && GS('content','top')==0) ShowHideE('iprev', 'hidden'); else  ShowHideE('iprev', 'visible');
       if (_1stActPos>arDist.length) _1stActPos = arDist.length;
       if (_1stActPos == arDist.length ) ShowHideE('inext', 'hidden'); else  ShowHideE('inext', 'visible');
   }
   else {
   /** with jQuery
       if (_1stActPos<=1 && GS('content','top')==0)  $('#iprev').removeClass("iup"); else  $('#iprev').addClass("iup");
       if (_1stActPos>arDist.length) _1stActPos = arDist.length;
       if (_1stActPos == arDist.length ) $('#inext').removeClass("idown"); else  $('#inext').addClass("idown");
      ***/
   /** WITHOUT jQuery **/
       if (_1stActPos<=1 && GS('content','top')==0)  YAHOO.util.Dom.removeClass(GE('iprev'), 'iup'); else  YAHOO.util.Dom.addClass(GE('iprev'), 'iup');
       if (_1stActPos>arDist.length) _1stActPos = arDist.length;
       if (_1stActPos == arDist.length ) YAHOO.util.Dom.removeClass(GE('inext'), 'idown'); else  YAHOO.util.Dom.addClass(GE('inext'), 'idown');   
   
   }
   
}

function checkStatus(){
    //*** check which should be the _1stActPos index
   var left=Math.abs(GS('content','top'));
 
   for (a=_1stActPos; a<arDist.length; a++){
        if (arDist[a]<=left) _1stActPos=a+1;    //a;
        else break;
   };

    checkConstraints();
}


function wlog( content,flAddNew){
    var  id="logger";
    var dv = GE(id);
    
    if (!dv){
        dv = document.createElement('div');
        dv.setAttribute('id',id);
	    document.body.appendChild(dv);
    }
     
    if (flAddNew)
        dv.innerHTML =content+ "<br>"
    else
        dv.innerHTML =  dv.innerHTML +content+"<br>"
   
        
}

function SetImageALTColor(){
    //** set the text color of the <a> of the image the same as the background of the template body. This way when new image is loaded by ajax the alt text will not be visible while the image is loading and is not visible.
    //$('#MyCont a').css('color', gsDocBodyBg);
    // create version without jQuery
    alert('SetImageALTColor function not defined')

}
function checkEffect(){
    var z = YAHOO.util.Dom.getElementsByClassName('effects_th_1', 'img');
    if (z.length>0) imageborder += 1;
}

function initA() {

     var iFr_h = parseInt( $('#frame').css('height'));
     var iCo_h = parseInt( jQuery.css( GE('content'), 'height', false ));
     var iMyCo_h = parseInt( $('#MyCont').css('height'));
     var iMI_h;
     if (GE('mainimage')){
        iMI_h = GE('mainimage').getElementsByTagName("img")[0].height;
        if ( iMI_h > iMyCo_h) {
            $('#MyCont').css('height', iMI_h+'px');
            $('#frame').css('height', (iMI_h - iMyCo_h + iFr_h)+'px');
        }
     }
     //  alert(iMyCo_h+nl+'content: '+iCo_h+'\n frame: '+ iFr_h)
     if (iCo_h <= iMyCo_h) {
     //** if there is no need of scroll arrows
        $('#iprev').css('display', 'none');
        $('#inext').css('display', 'none');
        
        $('#frame').css('height', iMyCo_h+'px');
     
     }
     else {
        var a=0;
        while(++a){
            arDistO[a] = arDistO[a-1] + (iFr_h-10);
            if (arDistO[a]>iCo_h) {
                arDistO[a] = iCo_h;
                break;
            }
        }

        SetNavigation();
   
     }
}



function OnloadFunc(){
    StartGalleryScroll();        //  +  scrollToActive();
    SetThumbnailPanelWidth();
    SetThPanelHeight();
    
    init();

   // ShowInfoFields();
    if (typeof initLightbox != "undefined") initLightbox();
    if (typeof DisplayEff == "function") {DisplayEff();}
}


