// Contains Copyrighted Materials by (c) ISPRODUCTIONS 2008

var iFrstImg = 1;
var imgPerPage = 5;
// defined in image template:: var _1stActPos = $$ImageNumSelected$$;
if (typeof _1stActPos == 'undefined') _1stActPos=1;
var slider;
var bIsScrollCreated = false;
var panelH = 130;
var arDistO = new Array(), arDist = new Array();
arDistO[0] = 0;
arDist[0] = 0;
 var bAnyNav = false;
 var igNavArrW = 80;
 var iObjH = 700;
 var gcMinTxtWidth = 250;
 var gcMinTopTblWidth = 875;
 var gcMinFrameWidth = gcMinTopTblWidth - 2*30 - 2*5 -4 - igNavArrW; //730;
 var gcImgBox = 580;


function ChangeImage(ind){
   // var oldImg = _1stActPos
   // var iImgToMove = (2*_1stActPos-1+dir )/2
   
    //** if user has select the active image - no need to reload it
   if ( ind && (ind==iCurImg) ) return; 
   iCurImg = ind;

   if (arIL)
        if (arIL.length>0) {
             DoTheJob(arIL[ind].mlink, 'mainimage',true);
        }
}

function MoveImage(dir){

    var old1stActPos = _1stActPos;
    var left = GS('content', 'left');

    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(left) - 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 - left;     //left = GS('content', 'left');

    var anim = new YAHOO.util.Motion('content', { points: { by: [c_offset, 0] } }, 1);
    anim.animate();
    //** 04.03.09 anim.onComplete.subscribe(checkConstraints) ;
    anim.onComplete.subscribe(checkStatus) ;
    
}
/* moved to Gallery && Image templates
var f = window.onload; 
if (typeof f == 'function'){
    window.onload = function() {
        f();
        init();
    }
}else window.onload = init;
*/
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;

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 iIMG_THUMB_WIDTH = 130;
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;
        iImgWSum += arWs[ind-1] ;
    }
    else {
        arWs[ind-1] = 0;    //t1.offsetWidth;
        arHs[ind-1] = 0;
        iImgWSum += iIMG_THUMB_WIDTH+ 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;
                GE('frame').style.height = panelH + 'px';
            }
            arDistO[a] = iImgWSum;
            if (GE('content')) GE('content').style.width = iImgWSum + 'px';
            a++;
        }
        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);    
       }

    if (typeof initLightbox != "undefined") PrepareInitLightbox();
}


function SetNavigation(){

    SetNewFrameWidth();
    SetDistLimit();
    
    if (typeof iCurImg != 'undefined') _1stActPos = iCurImg;
     
     //*** center the content if there is no need of Previous/Next arrows
     if (GS('content','width') < GS('frame','width')) {
        GE('content').style.left = (GS('frame','width') - GS('content','width'))/2  + 'px';
        bAnyNav = false;
     }else {
        GE('content').style.left = '0px';
       // checkConstraints();
        bAnyNav = true;
        if (_1stActPos!=1) MoveImage(0); else checkConstraints();
    }
     
     //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=e=new Date();
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);
}
function StartMoveStrip(id){

   if (id == 'iprev') {
        par=-1; 
        Limit = 0; }
   else {
        par=1;
        Limit = arDist[arDist.length-1]; }
  
   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);
    }
    else {
      checkConstraints(); 
    }
    clearInterval(iMSind);
    
    this.className = this.id;

}

function MoveOne(dir){

    var stopCond, changePosCond, changeEl;
 
    if (dir>0){ //*** next
          stopCond = ((Limit + GS('content', 'left')) <= 0 )
          changePosCond = ((arDist[_1stActPos] + GS('content', 'left')) <= 0 )  
//        changePosCond = ((arDist[_1stActPos+1] + GS('content', 'left')) <= 0 )  
          changeEl = changeActivePos(1, dir);
    }      
    else { //*** prev
        stopCond = ((Limit - GS('content', 'left')) <= 0 )
        changePosCond = ((arDist[_1stActPos-1] + GS('content', 'left')) >= 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.left = GS('content', 'left')-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', 'left'))< gSlideStep) curSlideStep = Math.abs(Limit-dir*GS('content', 'left'));
    else curSlideStep = gSlideStep;
    
}

function changeActivePos(step, dir){
    var _new1stActPos = _1stActPos+step;
    
 /*   if (dir*(_new1stActPos-Limit) >=0) {//dissappear arrow
        if (dir<0) ShowHideE('iprev', 'none'); else ShowHideE('inext', 'none');
    }
    
    // if strip has just left the first position in continuous 'next' sliding OR
    // the last position in continuous 'prev' sliding THEN
    //
    if (_new1stActPos != arDist[arDist.length-1]*(1-dir)/2) 
        if (dir>0) ShowHideE('iprev', 'block'); else ShowHideE('inext', 'block');
*/        
    return _new1stActPos;
}

var nl = '\n';
function SetDistLimit(){
   var slideLimit = GS('content','width') - GS('frame','width');

   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  SetNewFrameWidth(){
    //*** get the width of the box in which appeares the big image. This width depends on the width of the image
    //*** igNavArrW is left for the navigation arrows
    // set that width to the block that contains the thumbnails

  //  newW = (newW<gcMinFrameWidth? gcMinFrameWidth : newW) 
    
    if (exists('boxImg') && exists('boxText')){
        var iBoxImg = GE('boxImg').offsetWidth;
        var sBoxText = GE('boxText').offsetWidth;
      
        if (gcImgBox < iBoxImg){
            if (GE('tblTop')){
                GE('tblTop').style.width = gcMinTopTblWidth +(iBoxImg - gcImgBox )+'px';}
            GE('dvBxTxt').style.width = gcMinTxtWidth+'px';
       }else {
            GE('dvBxTxt').style.width = gcMinTxtWidth + (gcImgBox - iBoxImg)+'px';
            GE('tblTop').style.width = gcMinTopTblWidth+'px'
            }
        
    }else
        GE('tblTop').style.width = gcMinTopTblWidth+'px'
        
    var newW = GE('tbl_MI').offsetWidth - igNavArrW;
    newW = (newW<gcMinFrameWidth? gcMinFrameWidth : newW);
     GE('frame').style.width = newW + 'px';

    var newH = GE('tbl_MI').offsetHeight;
    GE('mainimage').style.height = newH + 'px';
}

 function doNext(){
    SetNewFrameWidth();
    SetDistLimit();

     if (GS('content','width') < GS('frame','width')) {
        GE('content').style.left = (GS('frame','width') - GS('content','width'))/2  + 'px';
        bAnyNav = false;
        checkConstraints();
    }else {
           //stef 03.03.2009
           //** if passed from image that was wide enough not to use navigation arrows to narrow one - 
           //** set the images container at the beginning of the box that shows them
            if (!bAnyNav){
                GE('content').style.left = '0px';
                left = 0;
                _1stActPos = 0;
            }// end stef 03.03.09
            
            bAnyNav = true;
        
            var p, new1st, ind;
            var left = GS('content', 'left')

            ind = iCurImg
            new1st = ind > (arDist.length-1)? arDist.length-1 : ind;
        
//            if (Math.abs(left)-arDistO[new1st-1] > 0) {//change - first visible in strip
 //       wlog('ind='+ind+', left='+Math.abs(left)+', _1stActPos='+_1stActPos+'<br>arDist[ind-1]='+arDist[new1st-1]+'/'+arDistO[ind-1])
            if (Math.abs(left)-arDistO[ind-1] > 0) {//change - first visible in strip
                  _1stActPos =  new1st;
                  MoveImage(0);
            }else {
                if (ind >= (arDist.length-1)) p = arDistO[ind];   //GS('content','width'); 
                else p = arDist[ind]; 
                
                if (p -Math.abs(left) > GS('frame','width')){ //change - last visible in strip
                    var c_offset = -(p -Math.abs(left)-GS('frame','width'));
                   
                    var anim = new YAHOO.util.Motion('content', { points: { by: [c_offset, 0] } }, 1);
                    anim.animate();
                    anim.onComplete.subscribe(checkStatus)
                    
                }else checkStatus();
            }
            
         
          
     }
    
    if (typeof initLightbox != "undefined") PrepareInitLightbox();
    
 }
    
function checkConstraints(){
    if (!bAnyNav){ //***if previousle there have been some navigation arrows but we dont need it
        ShowHideE('iprev', 'hidden');
        ShowHideE('inext', 'hidden');
        return;
    }
    if (_1stActPos<=1 && GS('content','left')==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');
}

function checkStatus(){
    //*** check which should be the _1stActPos index
   var left=Math.abs(GS('content','left'));
 
   for (a=_1stActPos; a<arDist.length; a++){
        if (arDist[a]<=left) _1stActPos=a+1;    //a;
        else break;
   };

    checkConstraints();
}
function fn_MoveForward(p){
    var left = GS('content', 'left')
    if (p -Math.abs(left) > GS('frame','width')){ //change - last visible in strip
        var c_offset = -(p -Math.abs(left)-GS('frame','width'));
        
        var anim = new YAHOO.util.Motion('content', { points: { by: [c_offset, 0] } }, 1);
        anim.animate();
        anim.onComplete.subscribe(checkStatus);
    }
}

function PrepareInitLightbox(){
    //innerbackground
    initLightbox();
    SetAppColors();
}
function SetAppColors(){
   var sTBgr;
   //*** image background
   sTBgr = getClassProperty('innerbackground', 'background-color', 'td');
   if (sTBgr) {
        GE('outerImageContainer').style.backgroundColor = sTBgr;
        GE('artistLogoContainer').style.backgroundColor = sTBgr;
        GE('imageContainer').style.backgroundColor = sTBgr;
        GE('imageDataContainerLB').style.backgroundColor = sTBgr;
   }
   //*** border
   sTBgr = getClassProperty('imagebordercolor', 'background-color', 'td');
   if (sTBgr){
        GE('imageDataContainerLB').style.borderColor = sTBgr;
        GE('imageContainer').style.borderColor = sTBgr;
        GE('imageDetails').style.borderColor = sTBgr;
   }
   //*** background
   if (document.body) {
       sTBgr = YAHOO.util.Dom.getStyle(document.body, 'background-color');
       if (sTBgr) GE('overlay').style.backgroundColor = sTBgr;
       sTBgr = YAHOO.util.Dom.getStyle(document.body, 'color');
       if (sTBgr) {
            GE('artistLogoContainer').style.color = sTBgr;
            GE('caption').style.color = sTBgr;
       }
   }
    
   
}
//***
function checkEffect(){
    var z = YAHOO.util.Dom.getElementsByClassName('effects_th_1', 'img');
    if (z.length>0) imageborder += 1;
}

/****** common 1  **/
function ShowLoading(target){

    oMI = document.getElementById(target);
    if (oMI){
        var objILoading = document.createElement("div");
	    objILoading.setAttribute('id','imgLoading');
	    oMI.appendChild(objILoading);
	    
	    var oL2 = document.createElement("div");
	    oL2.className = 'iL2';
	    objILoading.appendChild(oL2);
	    
	    oL2.innerHTML = "<img src='CommonFiles/ajax-loader.gif' />"
   }
 }
 
 ///////////////////////////////////////////////////////////////////
function DoTheJob(obj,target, doAfter){
    var href, par='';

    if (obj) {

        ShowLoading(target);
        
        var href = obj;

        postGetData(href, par, target, doAfter);
       
    }
    
}
function postGetData(dataSource, data, divID, doAfterFinish)
{ 
    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, true);
            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);
                            
                            obj.innerHTML = cnt;

                         //  setTimeout('doNext('+doAfterFinish+')', 100);
                           YAHOO.util.Event.on('kartinka', 'load', doNext);
                           
                   /*   
                     for (a=0 ; a< obj.innerHTML.length; a=a+2000)
                         alert(obj.innerHTML.substr(a, 2000))
                   */   
                    }
                }
            XMLHttpRequestObject.send(data);
       }
        catch (e) {
            window.open(dataSource)
       }
    }
 }  
 
function updateScripts( html, loadScripts){

        if(!loadScripts) return;
        
        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(_parseScripts, 20);
       

}
function getClassProperty(sClass, sProperty, sETag){
      if (!sETag) sETag = 'div'
      var z = YAHOO.util.Dom.getElementsByClassName(sClass, sETag)
      z = z[0]
      z = YAHOO.util.Dom.getStyle(z, sProperty)
    
      return z;
}


/** Common Functions 2**/
function GE(id) {
    return document.getElementById(id)
}
function GS(id,style_property){
    return parseInt(YAHOO.util.Dom.getStyle(id, style_property) );
}
function myRemoveNode(obj){
  if (obj)   
      if (obj.removeNode)
                obj.removeNode(true);
       else { 
            var parent = obj.parentNode;
            parent.removeChild(obj);
        } 
}

function exists(id){
    if (GE(id)!=null) return true; else return false;
}

function togDisp(e,ind){
    stopB(e);
    var elems = getObjectsByClassName('moreButton');
    for(var i=0;i<elems.length;i++){
        var obj=elems[i];
       //  var dp="none";
       var dp = 'hidden';

       if (obj.id == (ind+'More')){
           if(obj.style.visibility == 'visible') dp='hidden'; else { dp = 'visible'; }
           //  if(obj.style.display=='block') dp='none'; else dp = 'block';
        }
          obj.style.visibility = dp;
//        obj.style.display=dp;
    }
    return false;
}
function stopB(e){
    if(!e) e=window.event;
    e.cancelBubble=true;
}
 // returns an array of id-s
function getElementsByClassName(className, parent){
    var oParent;
    var arr = new Array();
    if (parent) oParent = GE(parent); else oParent=document;
    var elems = oParent.getElementsByTagName("div");
    for(var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        var id = elem.getAttribute("id");
        var cls = elem.className
        if(cls == className){
            arr[arr.length] = id;
        }
    }
    return arr;
}

//returns an array of objects
function getObjectsByClassName(className, parent){
    var oParent;
    var arr = new Array();
    if (parent) oParent = GE(parent); else oParent=document;
    var elems = oParent.getElementsByTagName("div");
    for(var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        var cls = elem.className
        if(cls == className){
            arr[arr.length] = elem;
        }
    }
    return arr;
}

function ShowHideE(eID, state){
    if (GE(eID))
        GE(eID).style.visibility = state;
}
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 alertProps(obj){
    var s='';
    for (a in obj)
        s += a+'='+obj[a]+'\t';
     
     for (a=0 ; a< s.length; a=a+2000)
           alert(s.substr(a, 2000))
}
/************************* end of common function *******************************/
    var o_gbbox, o_assetbox;
    var aWDims = {gbbox: 785, assetbox: 865, idetbox: 785}
    var aHDims = 560;

    YAHOO.namespace("example.container");
    
    YAHOO.example.container.oname = '';
    
    function initZ(sfile, oname) {

        var oBox = eval('YAHOO.example.container.'+oname);
        YAHOO.example.container.oname = oname;

        if (!oBox) {
            oBox = new YAHOO.widget.Panel(oname,  
                                                { width: eval('aWDims.'+ oname)+'px',
                                                  height: aHDims+'px',
                                                  fixedcenter: false, 
                                                  close: true, 
                                                  draggable: false, 
                                                  zindex:4,
                                                  modal: true,
                                                  visible: false
                                                } 
                                            );
           init_more( oBox, oname );
           
           eval ('o_'+ oname + '= oBox');
           var callback = DefCallback(oname);
        //*** Connect to data source and load the data
           var conn = YAHOO.util.Connect.asyncRequest("GET", sfile+'&ajx=1', callback);
      }

        //*** Show the Panel
        oBox.show();
    }
    
    function init_more(oContainer, oname){

       oContainer.setBody('<div id="lingvi_'+oname+'" ><div id="ic_load"><img src="CommonFiles/ajax-loader.gif" /></div></div>');
       oContainer.renderEvent.subscribe(function(){this.header.style.display='none'});
       oContainer.render(document.body);
       oContainer.center();
    }
    
    YAHOO.namespace("example.container1");
    
    YAHOO.example.container1.oname = '';
    var oBox;
    function loadStackSlide(SID, W, H, type) {
        
        oname='ft';
        
         oBox = eval('YAHOO.example.container1.'+oname);
        YAHOO.example.container1.oname = oname;

        if (!oBox) {
            oBox = new YAHOO.widget.Panel(oname,  
                                                { width: W+'px',
                                                  height: H+'px',
                                                  fixedcenter: false, 
                                                  close: true, 
                                                  draggable: false, 
                                                  zindex:4,
                                                  modal: true,
                                                  visible: false
                                                } 
                                            );
           LSS( oBox, SID, W, H, type);
       }

        //*** Show the Panel
        oBox.show();
        
    }
    
 function LSS(oContainer, iSource, iW, iH, iType){

       if (iType == 1) //** stack viewer
       code = AC_FL_RunContent(
	        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0',
	        'width', iW,
	        'height', iH,
	        'src', 'SlideShow',
	        'quality', 'autohigh',
	        'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
	        'align', 'top',
	        'play', 'false',
	        'loop', 'true',
	        'scale', 'noscale',
	        'wmode', 'transparent',
	        'bgcolor', '',
	        'devicefont', 'false',
	        'id', 'SlideShow',
	        'name', 'SlideShow',
	        'menu', 'false',
	        'allowFullScreen', 'false',
	        'allowScriptAccess','sameDomain',
	        'movie', 'SlideShow', 
'flashvars','folderId='+iSource+'&isSlideshow=0&sKey='+sSKey+'&customerId='+sArtistID+'&cKey='+sSKey+'&isFA=1&fileFrom='+sAppurl+'fl5s.asp&path='+sAppurl+'fl5.asp&isPreview=0&toShowCloseButton=1&closeFunctName=CloseStackView&paramForCloseFinction=oBox',
	        'salign', 'lt'
	        ); 
    else  //** video
       code = s=AC_FL_RunContent(
			"src", "FLVPlayer",
			"width", iW,
			"height", iH,
			"align", "middle",
			"id", "FLVPlayer",
			"quality", "high",
			"bgcolor", "#869ca7",
			"wmode", "transparent",
			"name", "FLVPlayer",
			"flashvars",'source='+encodeURIComponent(iSource)+'&bgcolor=0x000000&closeFunctName=CloseStackView&paramForCloseFinction=oBox',
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer",
			"scaleContent", "false",
			"allowFullScreen", "true"
	        );

       oContainer.setBody(code);
       oContainer.render(document.body);
       oContainer.center();
       
    }
    
   
   function CloseStackView(o){
        var obj = eval(o);
        obj.setBody('');
        obj.hide();
    }
    
   function getC(obj) {
      var getstr = '';    //= "?";
      for (a=0; a<obj.elements.length; a++){
        getstr += obj.elements[a].name + "=" + encodeURIComponent(obj.elements[a].value) + "&";
        }
       
      //var callback = DefCallback('gbbox');
      var callback = DefCallback(YAHOO.example.container.oname);
      var conn = YAHOO.util.Connect.asyncRequest("POST", submitURL, callback, getstr);
     
   }
   
  function makePOSTRequest(url, parameters) {
       var callback = DefCallback(YAHOO.example.container.oname);
       var conn = YAHOO.util.Connect.asyncRequest("POST", url, callback, parameters);
   }
   
function ShowHideInfoBlock(code){
    var oname = (this.id)? this.id.replace('closeB_','') : code;
     oname = eval ('o_'+ oname );
    if (oname) oname.hide();
}


function DefCallback(oname){
    var callback = {
            success : function(o) {
               var rst = o.responseText;
               
          /*      for (a=1111 ; a< rst.length; a=a+2000)
                         alert(rst.substr(a, 2000))
           */              
               updateScripts(rst, true);
               document.getElementById("lingvi_"+oname).innerHTML = rst;
               
               YAHOO.util.Event.on("closeB_gbbox", "click", ShowHideInfoBlock);
               YAHOO.util.Event.on("closeB_assetbox", "click", ShowHideInfoBlock);
               YAHOO.util.Event.on("closeB_idetbox", "click", ShowHideInfoBlock);
            },
            failure : function(o) {
                document.getElementById("lingvi_"+oname).innerHTML = "CONNECTION FAILED!";
                //YAHOO.example.container.wait.hide();
            }
        }
    return callback;
}

function SetMarginTop(){
    var scrH = YAHOO.util.Dom.getViewportHeight();
    if (document.body) document.body.style.paddingTop = (scrH-iObjH)>0? (scrH-iObjH)/3 : 0 + 'px'; 
}
   

function GoL(link){
    if (link.length > 0) document.location.href = link;
}

function GetImagePage(z){
    // do nothing
    // do nothing - this function is refdefined in toledoNew_common.js
}
function ShowImgDetails(imgID){
    // do nothing - this function is refdefined in toledoNew_common.js
}
function changeClass(){

}


/******************** assets menu movement ********************/
var gItemsCurPage = 1;
//** the total number of the assets
var gItemsNUM = 1;
//** global variable that shows he acceptable asset items per 'page'
var gc_ItemsPerPage = 3;

function MoveAsset(dir){
    //** hide the current active items page
    var startP = (gItemsCurPage-1)*gc_ItemsPerPage + 1;
    for(a = startP; a<startP+gc_ItemsPerPage; a++){
        el = GE('c'+a);
        if (el) 
            YAHOO.util.Dom.replaceClass(el, 'ast_col_show', 'ast_col_hide');
    }
    //** set movement arrows visibility
    if (dir>0 && startP==1) YAHOO.util.Dom.setStyle(GE('prevasset'),'display','block');
    if (dir<0 && a-1>gItemsNUM) YAHOO.util.Dom.setStyle(GE('nextasset'),'display','block');

    //** set new active items page
    gItemsCurPage = gItemsCurPage+dir;
    startP = (gItemsCurPage-1)*gc_ItemsPerPage + 1;
    for(a = startP; a<startP+gc_ItemsPerPage; a++){
        el = GE('c'+a);
        if (el) 
            YAHOO.util.Dom.replaceClass(el, 'ast_col_hide', 'ast_col_show');
    }
    //** set movement arrows visibility
    if (dir>0 && a>gItemsNUM) YAHOO.util.Dom.setStyle(GE('nextasset'),'display','none');
    if (dir<0 && startP==1) YAHOO.util.Dom.setStyle(GE('prevasset'),'display','none');
}

function SetHideAssets(){
    var i=gc_ItemsPerPage+1;
    while (GE('c'+i)){
        YAHOO.util.Dom.replaceClass(GE('c'+i), 'ast_col_show', 'ast_col_hide');
        i++;
    }
    //** get in global variable the number of the assets
    gItemsNUM = i-1;
    //** show 'next' arrow if more assets than the visible on one page
    if (gItemsNUM > gc_ItemsPerPage)  YAHOO.util.Dom.setStyle(GE('nextasset'),'display','block');

}