// Contains Copyrighted Materials by (c) ISPRODUCTIONS 2008

// defined in image template:: var _1stActPos = $$ImageNumSelected$$;
if (typeof _1stActPos == 'undefined') _1stActPos=1;
var arDistO = new Array(), arDist = new Array();
    arDistO[0] = 0;
    arDist[0] = 0;
 var bAnyNav = false;
 var gThumbsPerPage = 8;
 var gvar_CurThumbsPage=1;
 
 var gImageThumbs_visInStrip = 7;


function ChangeImage(ind){
   //*** close price box if open
   CloseP();
   
    //** 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);
        }
}

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) ;
    
}

/************* init functions ********/
function init_FP(){
    initScrollbars();
}

function init_PFList(){
    
    var i = 1;
    var pgsCounter = 1;
    var oPGS = GE('pgs');
    
    var arHOs = YAHOO.util.Dom.getElementsByClassName("imgCont", null, YAHOO.util.Dom.get('CTN'));
    if (arHOs.length > gThumbsPerPage){ //*** paging needed
        var i = 1;
        while( i<=arHOs.length ){
           // if (i % gThumbsPerPage == 1){
                var o = null;
                o = document.createElement('div');
                o.className = 'pgsItem p_inact';
                o.setAttribute('id', 'pgsi_'+pgsCounter)
                o.innerHTML = pgsCounter++;
                oPGS.appendChild(o);
                
                // add onclick event
                YAHOO.util.Event.addListener(o, 'click', ChangeGListPage, {z: pgsCounter-1}, true);
            //}
            i += gThumbsPerPage;
        }
    }
    else {
        setCNTwidth(arHOs.length); }
    
    YAHOO.util.Dom.replaceClass(GE('pgsi_1'), 'p_inact', 'p_act');
    
}

function init_PF(){
    initScrollbars();
}

function init_IP(){
    init_PF();
    setStackPos();
    if ( isDef(initLightbox) ) PrepareInitLightbox();
    
}

function init_A(){
    initScrollbars();
    if (arAst.length>2 && isDef(_1stAsset)) makePOSTRequestSet(_1stAsset+'&ajx=1', 'txtcnt', 'txtwrap');
        
}

var arrL = ['Your name', 'Address', 'City', 'Zip', 'Phone', 'Email', 'Comments'],
    arrIDs = ['fGuestName', 'fAddress', 'fCity', 'fZip', 'fPhone', 'fEmail', 'fComments'];

function SetGBValues(i){
    if(GE(arrIDs[i]).value == '') GE(arrIDs[i]).value = arrL[i];
}
function init_GB(){
    
    for (i=0; i<arrIDs.length; i++){
       YAHOO.util.Event.onAvailable(arrIDs[i], SetGBValues, i);
    }
    
}

 var f = window.onload; 
    if (typeof f == 'function'){
        window.onload = function() {
            f();
            OnloadFunc();
        }
    }else window.onload = OnloadFunc;
    
    function init_func(abrev){
         switch(abrev){
            case 'fp': init_FP();break;
            case 'pf': init_PF();break;
            case 'pf_list': init_PFList();break;
            case 'ip': init_IP();break;
            case 'a': init_A(); break;
            case 'gb': init_GB();
        
            
        }

        SetHideAssets();
    }

/******** end init functions **********/

var iImgWSum = 0;
var scrollGroup;

function MM_preloadImages() { 
    var scrollImg;
    var p, gW, gH, pW, pH ;
    if (arImgs.length == 0) return;
    
    gThumb_Margin = parseInt( getClassProperty('imgthumb','margin-right','div') );    //(GS('th1', 'padding-right'));
    gH = parseInt(getClassProperty('imgthumb','width','div'));
    gW = parseInt(getClassProperty('imgthumb','width','div'));
     g2 = GE('th1').offsetWidth;
     gW = (gW>g2? gW : g2);

    YAHOO.util.Dom.setStyle(GE('frame'), 'width', gImageThumbs_visInStrip*(gW+gThumb_Margin)+'px');

    scrollGroup = new YAHOO.util.ImageLoader.group(window, 'thumb_scroll', 1);
    for (i=1; i<arImgs.length; i++){
        var p = ParseIURL(arImgs[i], i, gW);

        //** if the image has no shown width and height properties in the <IMG tag
        if (! (p.W || p.H)){
            var p_tmp;
            p_tmp = new Image();
            p_tmp.src = p.Src;
            //p_tmp.onload = pTMP( i, p, gW, gH, p_tmp)
            
            /**/
            var args = new Array();
            args[i] = {i:i, p:p, gW:gW, gH:gH, img:p_tmp};
            //args[i].i_tmp.onload = function(){  
                    ImgLoad(args[i],0);  
            //         };
            
        }
        else {
            scrollImg = preloadImages_next(i, p, gW, gH);  //scrollImg = preloadImages_next(scrollGroup, i, p, gW, gH);
        }
        
        if (p.css && p.css=='effects_th_1'){ arWs[i-1] += 2*2; } //** effects_th_1 adds 2px border
    }
    YAHOO.util.Event.addListener(window, 'load', SetNavigation);
}
function pTMP(i, p, gW, gH, p_tmp){
    p.W = p_tmp.width;
    p.H = p_tmp.height;
    scrollImg = preloadImages_next( i, p, gW, gH);  //scrollImg = preloadImages_next(scrollGroup, i, p, gW, gH);
}
function ImgLoad(oIm,n)
{
    if ((oIm.img.width && oIm.img.height) || (n >1000) ) {
        pTMP(oIm.i, oIm.p, oIm.gW, oIm.gH, oIm.img);
        return;
        }
    
    setTimeout(function(){ImgLoad(oIm,n+5);}, 100);
} 
//function preloadImages_next(scrollGroup, i, p, gW, gH){
function preloadImages_next(i, p, gW, gH){

        scrollImg = scrollGroup.registerSrcImage('scrollImg'+i, p.Src, p.W, p.H);
        if (p.css) GE(scrollImg.domId).className = p.css;
        if (p.mOvr) YAHOO.util.Event.addListener(scrollImg.domId, 'mouseover', function(){ eval(p.mOvr+'(this)') });
        if (p.mOut) YAHOO.util.Event.addListener(scrollImg.domId, 'mouseout', function(){ eval(p.mOut+'(this)') });

        //** set the thumbnail to appear centered
        GE('ts'+i).style.left = (gW-p.W)/2+'px';
        GE('ts'+i).style.top = (gH-p.H)/2+'px';
       // wlog(gW+'-'+p.W + ' /// '+ gH+'-'+p.H)
        
        
        scrollImg.setVisible = true;
        
        return scrollImg;
}

 function ParseDims(dim, source){
    var re, tmp;

    re = new RegExp(dim+'="\\d{1,3}"', "ig")     //** re =  /width="\d{1,3}"/ig;
    tmp = re.exec(source);
    if(tmp) 
    { 
        re = new RegExp("\\d{1,3}", "ig")             //** re = /\d{1,3}/ig;
        tmp = re.exec(tmp);
    }
    else
    {
        re = new RegExp(dim+'="\\d{1,3}px"', "ig")     //** re =  /width="\d{1,3}px"/ig;
        tmp = re.exec(source);
        re = new RegExp("\\d{1,3}px", "ig")             //** re = /\d{1,3}/ig;
        tmp = re.exec(tmp);
        if(tmp) tmp = parseInt(tmp);
    }
     
     return tmp;
 }
     
function ParseIURL(istring, i, gW){
    var res;
    // l = Artists/2285/ImCache/118_50_842008123216PM_2182005121350AM_Calaveras.jpg" width="118" height="50"  [class="effects_th_1"  onmouseover="high(this)" onmouseout="low(this)"]  z="
    // OR
    // l = Artists/2285/ImCache/118_50_842008123216PM_2182005121350AM_Calaveras.jpg" width="118px" height="50px"  [class="effects_th_1"  onmouseover="high(this)" onmouseout="low(this)"]  z="
    var re, reU, reW, reH, reCs;
    
   //** get url
     re = new RegExp("[\\w\\W]*\\.jpg", "ig");     //** re = /[\w\W]*\.jpg/ig;
     reU = re.exec(istring);
   
    //** get width
     reW = ParseDims('width', istring);
     arWs[i-1] = gW+ gThumb_Margin //+ 2*imageborder;   
     
    //** get height
    reH = ParseDims('height', istring);
 
    //** get class name, if any
     re = new RegExp('class="[\\w]*"', "ig")     
     reCs = re.exec(istring);
     if (reCs){
        re = new RegExp("[^class=\"][\\w]*", "ig")              
        reCs = re.exec(reCs);
     }
     
     //get image events, if any
     re = new RegExp('onmouseover="[\\w\(\)]*"', "ig")     
     reMv = re.exec(istring);
     if (reMv){
        re = new RegExp("[^onmouseover=\"][\\w]*[^\(\)]", "ig")              
        reMv = re.exec(reMv);
     }
     
     re = new RegExp('onmouseout="[\\w\(\)]*"', "ig")     
     reMt = re.exec(istring);
     if (reMt){
        re = new RegExp("[^onmouseout=\"][\\w]*[^\(\)]", "ig")              
        reMt = re.exec(reMt);
     }
     
     
     iImgWSum += parseInt(arWs[i-1]);
     arDistO[i] = iImgWSum;
     if (GE('content') ) GE('content').style.width = iImgWSum + 'px';

     res = {Src:reU, W:reW, H:reH, css:reCs, mOvr:reMv, mOut:reMt}
     
    return res;
}



var gThumb_Margin = 5;
var imageborder = 1
var arWs = new Array();


function SetNavigation(){


    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 {
        ShowHideE('slide_prev_Ho', 'visible');
        ShowHideE('slide_next_Ho', 'visible');
        
        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.addListener('slide_prev', 'mousedown', MoveStrip);
    YAHOO.util.Event.addListener('slide_next', 'mousedown', MoveStrip);
    YAHOO.util.Event.addListener('slide_prev', 'mouseup', StopMoveStrip);
    YAHOO.util.Event.addListener('slide_next', 'mouseup', StopMoveStrip);
    
}

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 == 'slide_prev') {
        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 == 'slide_prev') 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 )  
          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('slide_prev_Ho', 'none'); else ShowHideE('slide_next_Ho', '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('slide_prev_Ho', 'block'); else ShowHideE('slide_next_Ho', '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 checkConstraints(){
    if (!bAnyNav){ //***if previousle there have been some navigation arrows but we dont need it
     //   ShowHideE('slide_prev_Ho', 'hidden');
     //   ShowHideE('slide_next_Ho', 'hidden');
        return;
    }
  //  if (_1stActPos<=1 && GS('content','left')==0) ShowHideE('slide_prev_Ho', 'hidden'); else  ShowHideE('slide_prev_Ho', 'visible');
    if (_1stActPos>arDist.length) _1stActPos = arDist.length;
  //  if (_1stActPos == arDist.length ) ShowHideE('slide_next_Ho', 'hidden'); else  ShowHideE('slide_next_Ho', '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 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
   /* imagebordercolor REMOVED
   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;
       }
   }
    
   
}

/****** 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' />"
   }
 }
 
 ///////////////////////////////////////////////////////////////////
var arIFields = ['ImgPanel', 'ipIN', 'ipPr', 'txtwrap'];
function DoTheJob(sfile,doAfter){
    var href, par='';

    if (sfile) {

       ShowLoading('ImgPanel');
        
        var callback = GetImagePage();
        var conn = YAHOO.util.Connect.asyncRequest("POST", sfile, callback, 'z=1');
    }
   
}

function GetImagePage(){
     var p = {
        success : function(o) {
           var rst = o.responseText;
           
           var otemp = document.createElement("div");
           otemp.innerHTML = rst;
            for (i=0; i< arIFields.length; i++){
               SetDataFromTo(otemp, arIFields[i]);
           }
               if (typeof initLightbox != "undefined") PrepareInitLightbox();

        },
        failure : function(o) { }
     }
     return p;
};
        
        
   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) 
                    {
                         YAHOO.util.Dom.get(tgt_F).innerHTML = arO[i].innerHTML;
                        
                         if ( tgt_F == 'txtwrap' ){
                                var oRP, oLP;
                                if (arO[i].innerHTML.trim() != '') { //has_text_info
                                    oRP = YAHOO.util.Dom.getElementsByClassName('rightPanel', 'div')
                                    YAHOO.util.Dom.removeClass(oRP, 'rightP_H');
                                    oLP = YAHOO.util.Dom.getElementsByClassName('leftPanel', 'div')
                                    YAHOO.util.Dom.removeClass(oLP, 'leftP_H');
                                    
                                }
                                else{ // no-text-info
                                    oRP = YAHOO.util.Dom.getElementsByClassName('rightPanel', 'div')
                                    YAHOO.util.Dom.addClass(oRP, 'rightP_H');
                                    oLP = YAHOO.util.Dom.getElementsByClassName('leftPanel', 'div')
                                    YAHOO.util.Dom.addClass(oLP, 'leftP_H');

                                }
                                
                                
                                iMarker = 0;
                                initScrollbars(GE('txtwrap'));
                                
                         }
                         else if (tgt_F == 'ImgPanel'){ //** set the position of the Stack/Video button if necessary
                            
                            YAHOO.util.Event.on('kartinka', 'load', setStackPos);
                         }
                         
                         return;
                     }
                
           }

        }
    }

function setStackPos(){
     var a = YAHOO.util.Dom.getElementsByClassName('stackB', 'div');
    if (a.length<1)
        a = YAHOO.util.Dom.getElementsByClassName('videoB', 'div');
    if (a.length>0)  {
    
        var wImg, hImg, wBox, hBox;
        hImg = parseInt(YAHOO.util.Dom.getStyle(GE('kartinka'), 'height'));
        wImg = parseInt(YAHOO.util.Dom.getStyle(GE('kartinka'), 'width'));
        hBox = parseInt(YAHOO.util.Dom.getStyle(GE('ImgPanel'), 'height'));
        wBox = parseInt(YAHOO.util.Dom.getStyle(GE('ImgPanel'), 'width'));


        var el = a[0];
        if (hImg > hBox) {YAHOO.util.Dom.setStyle(el, 'bottom', (hImg-hBox)/2+'px')}
        if (wImg > wBox) {YAHOO.util.Dom.setStyle(el, 'right', (wImg-wBox)/2+'px')}
    }
}


 
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)
      z1 = z[0]
      z2 = YAHOO.util.Dom.getStyle(z1, sProperty)
    
      return z2;
}


/** 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 isDef(var_ble){
    return (typeof var_ble == 'undefined'? false : 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>"
   
    //dv.style.display = "none"    ;
}
function alertProps(obj,mode){
    var s='';
    for (a in obj)
        s += a+'='+obj[a]+(mode? '\n':'\t');
     
     for (a=0 ; a< s.length; a=a+2000)
           alert(s.substr(a, 2000))
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/************************* end of common function *******************************/

   
    YAHOO.namespace("example.container1");
    
    YAHOO.example.container1.oname = '';
    var oBox;
    function loadStackSlide(SID, W, H, type) {
    
        oname='stack';
        
        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:10,
                                                  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 = 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"
	        );

        //code += '<font size="20">Abra cadabra Sim Saladim</font>'

       oContainer.setBody(code);
       oContainer.render(document.body);
       
      CenterIt(oContainer, iW, iH);    //  oContainer.center();
       
    }
    
 function CenterIt(obj, W, H){

    mTop = -H/2 
    mLeft = -W/2 
    GE('stack_c').style.marginTop = mTop+'px';
    GE('stack_c').style.marginLeft = mLeft+'px';
 }
   
   function CloseStackView(o){
        var obj = eval(o);
        obj.setBody('');
        obj.hide();
    }




function makePOSTRequestSet(url, target, parent) {
       var callback = {
            success : function(o) {
                var rst = o.responseText;
                GE(target).innerHTML = rst;

                if (parent) initScrollbarSingle(GE(parent));
            },
            failure : function(o) {
            }
        };
       var conn = YAHOO.util.Connect.asyncRequest("POST", url, callback, 'z=1');
}




function initScrollbarSingle(parent){
	if (!parent) parent = document;
    var scrollElements = getElements("scrollable", "DIV", parent, "class");
    if (scrollElements .length > 0){
        VSA_scrollAreas[iMarker] = new ScrollArea(iMarker, scrollElements[0]);
        iMarker++;
    }
}

function GoL(link){
    if (link.length > 0) document.location.href = link;
}



function ChangeGListPage(){
    //*** if the selected page is the current one - no action is made
    if (this.z == gvar_CurThumbsPage) return;
    
    var newP = this.z-1;
    var oldP = gvar_CurThumbsPage-1;
    //*** collect in this variable the numbar of the thumbnails in the new page
    var cnt=0;
    //** change the current thumbs page;
    for(i=1; i<=gThumbsPerPage; i++){
        YAHOO.util.Dom.setStyle(GE('ho'+(oldP*gThumbsPerPage + i)),'display','none');
        YAHOO.util.Dom.setStyle(GE('ho'+(newP*gThumbsPerPage + i)),'display','block');
        if (GE('ho'+(newP*gThumbsPerPage + i))) cnt++;
    }
    
    setCNTwidth(cnt);
    
    YAHOO.util.Dom.replaceClass(GE('pgsi_'+this.z), 'p_inact', 'p_act');
    YAHOO.util.Dom.replaceClass(GE('pgsi_'+gvar_CurThumbsPage), 'p_act', 'p_inact');
    //*** set the new active thumbnails page variable
    gvar_CurThumbsPage = this.z;
}

function setCNTwidth(cnt){
    var Lim = gThumbsPerPage/2;
    
    if (cnt%Lim != 0 && cnt<Lim){
       // YAHOO.util.Dom.setStyle(GE('CNT'),'width', cnt*222+'px');
       //GE('CTN').style.width = cnt*GS('ho1','width')+'px';
       GE('CTN').style.width = cnt* parseInt(getClassProperty('imgCont','width'))+'px';
   }else {
       GE('CTN').style.width = 'auto'; 
       // YAHOO.util.Dom.setStyle(GE('CNT'),'width','auto');
    }
}


function SetHideAssets(){
    //alert(GE('menuline').offsetWidth)
   
    var arEls = ['hm','pf', 'cl', 'wc'],
        arEls2 = ['ms_pf', 'ms_cl', 'ms_wc'], m_sum =0;
    for(a=0; a< arEls.length; a++){
        if (GE(arEls[a])) {
            m_sum += GE(arEls[a]).offsetWidth;
            }
    }
    for(a=0; a< arEls2.length; a++){
        if (GE(arEls2[a])) {
            m_sum += GS(arEls2[a], 'margin-left') + GS(arEls2[a], 'margin-right') + GS(arEls2[a], 'width');
            }
    }
    //*** set width of 'menuline' = the width of the menus visible
    GE('menuline').style.width = m_sum + 'px';
   
    var CoWidth = parseInt(getClassProperty('mline_holder', 'width'));
    var gW_MoreLbl =  parseInt(getClassProperty('yuimenubar', 'width'))
    gW_MoreLbl +=31;
    
    var iW_Limit = CoWidth - m_sum - gW_MoreLbl;
    var tmp = GE('tmpl_cell')
    var i, t_W ;
    
    //** start fom index=1. this way the 1st asset will not enter in the menu list
    //** the length of arAst is always >= 1 because we always have Guestbook link..
    //** then if arAst.length=2 there is only 1 asset and we have to show its link..
    //** else if there are more that 1 asset - the 1st one will stay hidden because ..
    //** its content appears at the right side of the asset page
    i=1;
    if (arAst.length < 3)  {
        i = 0;
   }else arAst[0] = null; 

    for ( ; i<arAst.length; i++){
        var x, y, z,p;
        x = document.createElement('div');
        x.className = "itemB hid";
        
        y0 = document.createElement('div');
        y0.className = "menu_separator0";
        y0.setAttribute('id', 'ms'+i);
                    
        y = document.createElement('div');
        y.className = "menu_separator";

        y0.appendChild(y);        
            
        z = document.createElement('div');
        z.className = "TopMenu";
        z.setAttribute('id', 'tm'+i);
        z.innerHTML = '<a href="#" >'+arAst[i].text+'</a>';
        p = document.createElement('div');
        p.className = "clear";
        
        
        x.appendChild(y0);
        x.appendChild(z);
        x.appendChild(p);
        GE('menuline').appendChild(x);
    
        t_W = GS('ms'+i, 'margin-left') + GS('ms'+i, 'margin-right') + GS('ms'+i, 'width') + z.offsetWidth;
        
        if (t_W <= iW_Limit){ // add it
            //** 1. add onclick event
            if (arAst[i].onclick) YAHOO.util.Event.addListener('tm'+i, 'click', G_Asset, {fn: arAst[i].onclick.fn}, true);
            //** 2. make visible
            YAHOO.util.Dom.removeClass(x, 'hid');
            //** 3.remove item from arAst
            arAst[i] = null;
            //** 4. update iW_Limit variable;
            iW_Limit -= t_W;
            //** change the width of 'menuline' adding the width of this element
            m_sum += t_W;

       }else{
            //** 1. remove element from document
            myRemoveNode(x);
            //** 2. stop cicle;
            GoMoreMenu();
            //** change the width of 'menuline' adding the width of the MORE menu
            m_sum += gW_MoreLbl;
            GE('menuline').style.width = m_sum + 'px';
            break;
       }

    }


     GE('menuline').style.width = m_sum+5 + 'px';


}
 
 function G_Asset(){
     this.fn();
 }
 
function GoAsL(url){
    if (url.indexOf('http://') == 0) 
        window.open(url);
    else
        GoL(url);
 }

function GetA(url) {

    if (url.indexOf('http://') == 0) 
        window.open(url);
    else
        makePOSTRequestSet(url+'&ajx=1', 'asset_text', 'assetcontent') ;
}
    
/******  assets menu,   ******/
function GoMoreMenu(){
        
        var y = document.createElement('div');
        y.className = "menu_separator ms_r";
        var y0 = document.createElement('div');
        y0.className = "menu_separator0_m";
        y0.appendChild(y);
        
         GE('menuline').appendChild(y0);
        
        var r = GE('m_menubar');
        GE('menuline').appendChild(r);
        r.style.dislay = "block";

        /*
             Initialize and render the MenuBar when its elements are ready 
             to be scripted.
        */
        YAHOO.util.Event.onContentReady("m_menubar", function () {

            /*
				Instantiate a MenuBar:  The first argument passed to the constructor
				is the id for the Menu element to be created, the second is an 
				object literal of configuration properties.
            */

            var oMenuBar = new YAHOO.widget.MenuBar("m_menubar", { 
                                                        autosubmenudisplay: true, 
                                                        hidedelay: 750, 
                                                        lazyload: true });

            /*
                 Define an array of object literals, each containing 
                 the data necessary to create a submenu.
            */
            
            
            
            
            var aSubmenuData = [
                {
                    id: "more", 
                    itemdata: arAst
                }            
            ];


            /*
                 Subscribe to the "beforerender" event, adding a submenu 
                 to each of the items in the MenuBar instance.
            */

            oMenuBar.subscribe("beforeRender", function () {

				var nSubmenus = aSubmenuData.length,
					i;


                if (this.getRoot() == this) {
                    
					for (i = 0; i < nSubmenus; i++) {
					    
					    this.getItem(i).cfg.setProperty("submenu", aSubmenuData[i]);
                    	
					}

                }

            });

/*
            oMenuBar.clickEvent.subscribe(function(ev, args) {
                //The key here is srcElement, it's a link back to the original option element
                var opt = args[1].srcElement;
                alert('You clicked: ' + opt.innerHTML + ' (' + opt.value + ')');
            });
/**/
            /*
                 Call the "render" method with no arguments since the 
                 markup for this MenuBar instance is already exists in 
                 the page.
            */

            oMenuBar.render();      
            
           /* v = YAHOO.util.Dom.getElementsByClassName('first-of-type', 'ul');  
            if (v.length>0) {
                v[0].style.width = 15+ parseInt(getClassProperty('yuimenubar', 'width')) + parseInt(YAHOO.util.Dom.getStyle(GE('menuline'), 'right')) + 
                    (parseInt(getClassProperty('innerbackground', 'width')) - parseInt(getClassProperty('header', 'width')) )
            */
       
       
        });
            
}


/** PF_list **/
function SetThumbDims(){
    var w, h;
    
    for (i=1; i< arThs.length; i++){
        h = parseInt(ParseDims('height', arThs[i]));
        w = parseInt(ParseDims('width', arThs[i]));
        if (h>w) {
            YAHOO.util.Dom.replaceClass(GE('bx'+i), 'bW', 'bH');
            //** set the thumbnail centered according to the box with the new width
            GE('rd'+i).style.left = (parseInt(getClassProperty('bH', 'width'))-w)/2 + 'px';
       }
    }
}


/** guestbook **/
function on_focus(sName_F,sVal_F){
    var o=document.getElementById(sName_F)
    if(o){
        var sVal_L = o.value
        if(sVal_L==sVal_F){
            o.value = ""
        }
    }
}

function on_blur(sName_F,sVal_F){
    var o=document.getElementById(sName_F)
    if(o){
        var sVal_L = o.value.trim();
        if(sVal_L=="") {
            o.value = sVal_F
        }
    }	    
}

 function sform(){
    //*** if some of the fields has not been filled - set the blank values
    for (i=0; i<arrIDs.length; i++){
        if (GE(arrIDs[i]).value == arrL[i]) GE(arrIDs[i]).value='';
    }

   if ( submitfrm_T() ){
       var frm = document.forms['form1'];
       if (frm) 
            if (submitfrm_T()){}
                frm.submit();
    }
}
function submitfrm_T(){	
	usa_code = "242";
	frm = document.form1;
	ccountry = getElementValue(frm.country);
	var arElements = new Array("GuestName","Email","comments","matchcode");    
	var arErrMes = new Array("Your name","Email","Comments","Verification code"); 
	
	for (i=0;i< arElements.length;i++) {
	    sItemErrMes = arErrMes[i];
	    if (!vs_non_blank_T(frm[arElements[i]]))
                    return false;
    }                    
    
    // check for valid e-mail
    sItemErrMes = "Email";
    if (!validation.validEmail(frm.Email))
        return false;
    return true;
   
    
}
function vs_non_blank_T(item) {
	var strErrorMsg = display_name(item) + "  must have a non-blank value";
	item.value=item.value.Trim();
	//wlog(item.value.length+"=="+0+' || '+item.value+" == "+display_name(item))
	if (item.value.length==0 || item.value == display_name(item)) {
		//item.focus();
		alert(strErrorMsg);
		return false;
	}
	return true;
}


function GetPricing(url){
      ShowLoading('priceinfo');
      YAHOO.util.Dom.setStyle(GE('pricecontent'), 'display', 'block');
      makePOSTRequestSet(url+'&ajx=1', 'priceinfo', 'i_txt') ;
}

/** close pricing box */
function CloseP(){
    GE('pricecontent').style.display = 'none';
}



