/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* This copyright notice must stay intact for legal use
* Modified for autowidth and optional starting positions in
* http://www.dynamicdrive.com/forums/showthread.php?t=11839 by jschuer1 8/5/06
***********************************************/

 //1) Set width of the "neutral" area in the center of the gallery.
var restarea=4;
 //2) Set top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var maxspeed=15;
 //3) Set to maximum width for gallery - must be less than the actual length of the image train.
var maxwidth=1500;
 //4) Set to 1 for left start, 0 for right, 2 for center.
var startpos=0;
 //5) Set message to show at end of gallery. Enter "" to disable message.
var endofgallerymsg='<span style="font-size: 11px;"></span>';

//// ÌÎÈ ÏÅÐÅÌÅÍÍÛÅ ////
var PUBLIC_DATE = '';
var IDVIDEO;
var i = 1;
var content = null
var myScrollmode = 'movies'
var actualwidth
var menuwidth
var arrLine
var full_content;

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

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

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

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

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

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

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


function moveleft()
{
         if (loadedyes)
         {
           movestate="left";

           if( parseInt(cross_scroll.style.left) < ( menuwidth-actualwidth + 300 ) )
           {
             if( i == 1 )
             {
               addMenu();
               i = 0
             }
             if( content )
             {
               i = 1          ;
               content = null ;
             }
           }
           
           
           if(iedom&&parseInt(cross_scroll.style.left)>(menuwidth-actualwidth))
           {
             cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px";
             showhidediv("hidden");
           }
           else
               showhidediv("visible");
         }

         lefttime=setTimeout("moveleft()",10);
}

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

         righttime=setTimeout("moveright()",10);
}

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

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

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

function fillup(sellectorMode)
{
         
         myScrollmode = sellectorMode
         startMenu()
         
         if(iedom)
         {
           crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer;
           
           if(typeof crossmain.style.maxWidth!=='undefined')
             crossmain.style.maxWidth=maxwidth+'px';
           
           menuwidth=crossmain.offsetWidth;
           cross_scroll=document.getElementById? document.getElementById("motiongallery") : document.all.motiongallery;
           actualwidth=5000
           
           cross_scroll.style.left=0+'px';

           crossmain.onmousemove=function(e)
           {
                     motionengine(e);
           }

           crossmain.onmouseout=function(e)
           {
                     stopmotion(e);
                     showhidediv("hidden");
           }

         }

         loadedyes=1
         if(endofgallerymsg!="")
         {
           creatediv();
           positiondiv();
         }


}




function addMenu()
{

         var req = new JsHttpRequest();
         req.onreadystatechange = function() 
         {
             if (req.readyState == 4) 
             {

                 if( IDVIDEO != req.responseJS.IDVIDEO )
                 {                 
                   arrLine   = req.responseText;
                   full_content += arrLine;
                   document.getElementById("trueContainer").innerHTML = '<table cellspacing="0" cellpadding="3" style="margin-top:5px"><tr>'+full_content+'</tr></table>';                   
                   content   = req.responseText;                   
                   IDVIDEO   = req.responseJS.IDVIDEO;
                   actualwidth=document.getElementById("trueContainer").offsetWidth;
                 }
             }
         }

         req.open('GET', 'http://www.sostav.ua/multimedia/news_video/videoJSON.php?ID='+IDVIDEO, true);
         req.send( null );

}

function startMenu()
{
         document.all.trueContainer.innerHTML = '<center><img src="/design/newspage/loading.gif" border="0"></center>'
         
         myScrollmode = 'prints';
         
         var req = new JsHttpRequest();
         req.onreadystatechange = function() 
         {
             if (req.readyState == 4) 
             {
                 arrLine   = req.responseText;
                 document.getElementById("trueContainer").innerHTML = '<table cellspacing="0" cellpadding="3" style="margin-top:5px"><tr>'+arrLine+'</tr></table>';
                 content   = req.responseText;
                 full_content = content;
                 IDVIDEO   = req.responseJS.IDVIDEO;
                 actualwidth=document.getElementById("trueContainer").offsetWidth;
             }
         }

         req.open('GET', 'http://www.sostav.ua/multimedia/news_video/videoJSON.php', true);
         req.send( null );

}


function setVideo(path, player, ID)
{
         
         var req = new JsHttpRequest();
         req.onreadystatechange = function() 
         {
             if (req.readyState == 4) 
             {
                 var urlNews     = ((req.responseJS.LINK)?(req.responseJS.LINK):(''))             ;
                 var news        = ((req.responseJS.NEWSTITLE)?(req.responseJS.NEWSTITLE):(''))   ;
                 var title_video = ((req.responseJS.VIDEOTITLE)?(req.responseJS.VIDEOTITLE):('')) ;
                 var title_descr = ((req.responseJS.SMALLTEXT)?(req.responseJS.SMALLTEXT):(''))   ;

                 if( player == 'mpg' )
                   document.getElementById('video').innerHTML = '<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" width="400" height="400">'+
                                                                '<param name="src" value="http://www.sostav.ua/multimedia/video'+path+'" />'+
                                                                '<param name="url" value="http://www.sostav.ua/multimedia/video'+path+'" />'+
                                                                '<param name="width" value="400" />'+
                                                                '<param name="height" value="400" />'+
                                                                '<embed type="application/x-mplayer2" src="http://www.sostav.ua/multimedia/video'+path+'" width="400" height="400"></embed>'+
                                                                '</object>'; 
                 else
                     if( player == 'mov' )
                     document.getElementById('video').innerHTML =  '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" width="400" height="400">'+
                                                                   '<param name="cache" value="true" />'+
                                                                   '<param name="scale" value="aspect" />'+
                                                                   '<param name="src" value="http://www.sostav.ua/multimedia/video'+path+'" />'+
                                                                   '<param name="bgcolor" value="#000000" />'+
                                                                   '<param name="width" value="400" />'+
                                                                   '<param name="height" value="400" />'+
                                                                   '<embed type="video/quicktime" cache="true" scale="aspect" src="http://www.sostav.ua/multimedia/video'+path+'" bgcolor="#000000" width="400" height="400"></embed>'+
                                                                   '</object>';

                 

                 var add = ((news)?('<a href="/news/'+urlNews+'" style="font-family:verdana; color:white; font-weight:bold; font-size:12px;" target="_blank">×èòàòü äàëåå</a>'):(''));
                 
                 document.getElementById('news').innerHTML = '<p style="font-family:verdana; color:white; font-weight:bold; font-size:18px">'+news+'</p><i style="color:white">'+title_descr+'</i> '+add;

                 document.getElementById('title_video').innerHTML = title_video;

                 document.getElementById('download_link').href = 'http://www.sostav.ua/multimedia/video'+path;

                 document.getElementById('left_download_link').src = '/design/left_download_link.gif';

                 document.getElementById('right_download_link').src = '/design/right_download_link.gif';
             }
         }

         req.open('GET', 'http://www.sostav.ua/multimedia/news_video/videoJSON.php?ID='+ID+'&activator=changeVideoObject', true);
         req.send( null );
        
}
