// JavaScript Document
function geBi(item){
	return document.getElementById(item);
}
function inVis(item){
	geBi(item).style.display='none';
}
function viS(item){
	geBi(item).style.display='block';
}
function aniB(item){
	item.style.backgroundPosition='left bottom';
}
function deaniB(item){
	item.style.backgroundPosition='left top';
}
function deaniBa(item){
	item.style.cursor='pointer';
	item.style.backgroundPosition='left -44px';
}
function deOp(item){
	item.style.opacity='1';
	item.style.filter='alpha(opacity=100, style=0)';
}
function opaciTy(item,val){
	item.style.opacity=val/10;
	item.style.filter='alpha(opacity='+val*10+', style=0)';
}
function isIE(){
	if (navigator.userAgent.match(/MSIE 6/i) != null) return 1;
	else if (navigator.userAgent.match(/MSIE 7/i) != null) return 2;
	else return 0;
}
function evnT(elm,str,flag){
	var evnt='onclick';
	if(flag==1){ evnt='onmouseover'; }
	else if(flag==2){ evnt='onmouseout'; }
	if(isIE()==0){ elm.setAttribute(evnt,str); }
	else{ eval('elm.'+evnt+'= function (){ '+str+' };'); }
}
function Elemnt(name, attrs, style, text) {
    var e = document.createElement(name);
    if (attrs) {
        for (key in attrs) {
            if (key == 'class') {
                e.className = attrs[key];
            } else if (key == 'id') {
                e.id = attrs[key];
            } else {
                e.setAttribute(key, attrs[key]);
            }
        }
    }
    if (style) {
        for (key in style) {
            e.style[key] = style[key];
        }
    }
    if (text) {
        e.appendChild(document.createTextNode(text));
    }
    return e;
}
// Gallery -->
function  getPageSize(){
	var xScroll,yScroll,yScrPos,xScrPos;
	yScrPos=0;
	xScrPos=0;
	if (document.body && typeof document.body.scrollTop != 'undefined') {
		yScrPos+= document.body.scrollTop;
		xScrPos+= document.body.scrollLeft;
		if(document.body.parentNode && typeof document.body.parentNode.scrollTop!= 'undefined'){
			yScrPos+= document.body.parentNode.scrollTop;
			xScrPos+= document.body.parentNode.scrollLeft;
		}
	}else if (typeof window.pageXOffset != 'undefined'){
			yScrPos+= window.pageYOffset;
			xScrPos+= window.pageXOffset;
	}
	if(window.innerHeight && window.scrollMaxY){
		xScroll=document.width;
		yScroll=window.innerHeight+window.scrollMaxY;
	}else if(document.body.scrollHeight>document.body.offsetHeight){ // all but Explorer Mac
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}else if(document.documentElement && document.documentElement.scrollHeight>document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll=document.documentElement.scrollWidth;
		yScroll=document.documentElement.scrollHeight;
	}else{ // Explorer Mac...would also work in Mozilla and Safari
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if(self.innerHeight){ // all except Explorer
		windowWidth=self.innerWidth;
		windowHeight=self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}else if(document.body){ // other Explorers
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}else{
		pageHeight=yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll<windowWidth){
		pageWidth=windowWidth;
	}else{
		pageWidth=xScroll;
	}
	return [pageWidth,pageHeight,windowWidth,windowHeight,xScrPos,yScrPos];
}

function popUp(item, width, height){
	height=400;
        if(width<800) width=800;
        width=width+60;
        height=height+260;
	var strf="'location=no,width="+width+",height="+height+"resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,status=yes'";
	var url="popup_win.html?"+item.getAttribute('href');
	var nname= (item.firstChild.getAttribute('alt')) ? item.firstChild.getAttribute('alt'):'Фотогалерея';
	var popupWin=window.open(url, nname, strf); 
	popupWin.focus(); 
}
function scrR(){
	var slidr=geBi('gallery_slider');
	var lastim=slidr.lastChild.firstChild;
	var nodes=slidr.childNodes;
	var last_im;
	var i=0;
	for(i;i<nodes.length;i++){
		if(nodes[i].firstChild.className=='last_im'){
			last_im=nodes[i].firstChild;
		}
	}
	if(lastim.className!='last_im'){
		slidr.style.marginLeft=(slidr.style.marginLeft.replace('px','')*1-191)+'px';
		last_im.parentNode.nextSibling.firstChild.className='last_im';
		last_im.className='';
	}
	if(lastim==last_im.parentNode.nextSibling.firstChild){
		geBi('gallery_btn_right').firstChild.style.display='none';
	}
	geBi('gallery_btn_left').firstChild.style.display='block';
}
function scrL(){
	var slidr=geBi('gallery_slider');
	var frstim=slidr.firstChild.firstChild;
	var nodes=slidr.childNodes;
	var last_im;
	var i=0;
	for(i;i<nodes.length;i++){
		if(nodes[i].firstChild.className=='last_im'){
			last_im=nodes[i].firstChild;
		}
	}
	if(slidr.style.marginLeft!='0' || slidr.style.marginLeft!='0px'){
		slidr.style.marginLeft=(slidr.style.marginLeft.replace('px','')*1+191)+'px';
		last_im.parentNode.previousSibling.firstChild.className='last_im';
		last_im.className='';
	}
	if(slidr.style.marginLeft=='0' || slidr.style.marginLeft=='0px'){
			geBi('gallery_btn_left').firstChild.style.display='none';
	}
	geBi('gallery_btn_right').firstChild.style.display='block';
}
// var tmer=0;
function aniScr(nowpos,lr){
	tmer++;
	var elm=geBi('gallery_slider');
	nowpos=parseInt(nowpos);
	var shag=1;
	var elmst= lr==1 ? elm.style.marginRight : elm.style.marginLeft ;
	var timeout=50;
	if(tmer<=191){
		setTimeout("aniScr("+nowpos+","+lr+");", 1);
		geBi('gallery_slider').style.marginLeft=tmer+nowpos+'px';
	}
	else{
		tmer=0;
		alert(geBi('gallery_slider').style.marginLeft);
	}
}
		
function iniScr(flag){
	var slider=geBi('gallery_slider');
	var num=(!flag)?4:3;
	if(slider.childNodes.length>=num) slider.childNodes[num-1].firstChild.className="last_im";
	if(slider.childNodes.length>num){
		geBi('gallery_btn_right').firstChild.style.display='block';
	}
}
// Player -->
var now=0;
var mov=0;
function loadMv(movie, img){
	var player=document.URL.indexOf('/index.html')!=-1 ? '/video/player.swf' : '/video/player_obj.swf';
	var height=document.URL.search(/buy|rent/g)!=-1 ? '400' : '406';
	var so=new SWFObject(player, "movie_v", "573", height, "8", "#ffffff");
	so.addParam("wmode","transparent");
	if(img){ so.addVariable("img",img); }
	so.addVariable("file",movie);
	so.write("player");
}
function iniT(btn){
	if(movie.length>1){
		var plnk=geBi(btn).firstChild;
		var nnode=plnk.cloneNode(true);
		var nlnk=document.createElement('a');
		nlnk.setAttribute('href','#');
		var strng = (btn=='back_btn') ? 'now=neXt(); return false;' : 'now=neXt(1); return false;';
		evnT(nlnk,strng);
		if(isIE==2){ eval('nlnk.onmouseout = function(){ geBi("player").focus(); };'); }
		nlnk.appendChild(nnode,nlnk.firstChild);
		plnk.parentNode.insertBefore(nlnk, plnk.parentNode.firstChild);
		plnk.parentNode.removeChild(plnk);
	}
}
function viD(lnk, num, img){
	var tmp='video_lnk_'+now;
	geBi(tmp).className='';
	lnk.parentNode.parentNode.className='active';
	var nnode=lnk.firstChild.cloneNode(true);
	lnk.parentNode.insertBefore(nnode, lnk.parentNode.firstChild);
	lnk.parentNode.removeChild(lnk);
	if(num!=now){
		var plnk=geBi(tmp).firstChild.firstChild;
		nnode=plnk.cloneNode(true);
		nlnk=Elemnt('a',{'href':'#'});
		evnT(nlnk,'now=viD(this,'+now+'); return false;');
		nlnk.appendChild(nnode,nlnk.firstChild);
		plnk.parentNode.insertBefore(nlnk, plnk.parentNode.firstChild);
		plnk.parentNode.removeChild(plnk);
	}
	(img) ? loadMv(mov[num],img) : loadMv(mov[num]);
	return num;
}
function neXt(flag){
	var nn = (flag) ? now+1 : now-1;
	nn = (nn>(mov.length-1)) ? 0 : nn;
	nn = (nn<0) ? mov.length-1 : nn;
	tmp='video_lnk_'+nn;
	var lnk=geBi(tmp).firstChild.firstChild;
	var num=viD(lnk, nn);
	return num;
}
function crPlayer(){
	var cont=geBi('player_obj_');
	cont.id='player_obj';
	var rp=Elemnt('div',{'id':'right_player'});
	rp.appendChild(Elemnt('div',{'id':'right_top_player'},'','презентации:'));
	rp.appendChild(Elemnt('div',{'id':'right_cen_player'}));
	rp.appendChild(Elemnt('div',{'id':'right_bot_player'}));
	cont.appendChild(rp);
	var ul=document.createElement('ul');
	for(var i=0;i<movie.length;i++){
		var txt=movie[i].split('##')[1];
		var a=Elemnt('a',{'href':'#'},'',txt);
		evnT(a,'now=viD(this,'+i+'); return false;');
		var p=document.createElement('p');
		p.appendChild(a);
		var li=document.createElement('li');
		li.id='video_lnk_'+i;
		li.appendChild(p);
		ul.appendChild(li);
	}
	geBi('right_cen_player').appendChild(ul);
	cont.appendChild(Elemnt('div',{'id':'player'}));
	var left=Elemnt('div',{'id':'back_btn'});
	var img_l=Elemnt('img',{'src':'/images/clear.gif','width':'44','height':'34','alt':'Предыдущий клип'});
	left.appendChild(img_l);
	var right=Elemnt('div',{'id':'fwd_btn'});
	right.appendChild(Elemnt('img',{'src':'/images/clear.gif','width':'44','height':'34','alt':'Следующий клип'}));
	var div=document.createElement('div');
	div.appendChild(left);
	div.appendChild(right);
	cont.appendChild(div);
	var mo=[];
	for(var i in movie){
		mo.push(movie[i].split("##")[0]);
	}
	return mo;
}
function iPlayer(){
	mov=crPlayer();
	var img=(img) ? img : '/video/31.jpg';
	now=viD(geBi('video_lnk_0').firstChild.firstChild,0,img);
	iniT('back_btn');
	iniT('fwd_btn');
}