

var videoclips_page=1; // for videoclips_prev();
//var videoclips_max_pages=4; // for videoclips_prev();
//var newsLineId="#jq_newsline"; // newsLineToogler();
var newsLineItemActive=1; // newsLineToogler();
//var newsLineMaxItems; // newsLineToogler();
//var newsTooglerTimer; // newsLineToogler();
var newsLineTooglerPlayerSwitcher=true; // newsLineToogler();

//newsLine[1]="Test news string num 1";
//newsLine[2]="test 2";
//newsLine[3]="test 3";

function page_reload_icon()
{
	$('#j_refresh').css({cursor:"pointer"});
	$('#j_refresh').click(function()
	{
		window.location.reload();
	});
}


function show_hide(id)
{
	plus="img/title_plus.gif";
	minus="img/title_minus.gif";
    
       
	if(!$('#' + id).hasClass('hidden'))
	{   
	    $('#'+id).removeClass('show');
		$('#'+id).addClass('hidden');
		pic=id+'p';
		document.getElementById(pic).src=plus;
		
	}
	else
	{
	    $('#' + id).removeClass("hidden");
		$('#'+id).addClass('show');
			
			pic=id+'p';
			document.getElementById(pic).src=minus;
			
	}
}
function Show(obj)
{
	$(obj).show();
}

function Hide(obj)
{
	$(obj).hide();
}
function videoclips_prev(vpered)
{

	var per_page=4;
	
	for(i=1;i<5;++i)
	{
		obj="#bl"+(4* (videoclips_page-1) +i);
		Hide(obj);
	}
	
	if(vpered)
		videoclips_page++;
	else
		videoclips_page--;

	if(!videoclips_page)
		videoclips_page=videoclips_max_pages;
		
	if(videoclips_page>videoclips_max_pages)
		videoclips_page=1;
		
	for(i=1;i<5;++i)
		{
			obj="#bl"+(4* (videoclips_page-1) +i);
			Show(obj);
		}	

}

function PicWhenTextSizeChng(command)
{
    var isSmallActive=Host+"/img/text_small.gif";
    var isSmall=Host+"/img/material/small_text_not_active.gif";
    var isBigActive=Host + "/img/material/big_text_active.gif";
    var isBig=Host + "/img/text_big.gif";
    
    var smallId="smallTextButton";
    var bigId="bigTextButton";
    
    var smallObj=document.getElementById(smallId);
    var bigObj=document.getElementById(bigId);

    switch(command)
    {
        case 'doBigText':
            smallObj.src=isSmall;
            bigObj.src=isBigActive;
            break;
        
        case 'doSmallText':
            smallObj.src=isSmallActive;
            bigObj.src=isBig;
            break;
    
        default:
            smallObj.src=isSmallActive;
            bigObj.src=isBig;
            
        
    }    

}

function bigText()
{
	id="#content_text";
	$(id).css({fontSize:"16px",fontWeight:"normal"});
	PicWhenTextSizeChng('doBigText');
}

function smallText()
{
	id="#content_text";
	$(id).css({fontSize:"13px",fontWeight:"normal"});
	PicWhenTextSizeChng('doSmallText');
}

function newsLineToogler()
{
	id_old=newsLineId + newsLineItemActive;
	newsLineItemActive++;
	id_new=newsLineId + newsLineItemActive;

	if(newsLineItemActive>newsLineMaxItems)
		{
			newsLineItemActive=1;
			id_old=newsLineId + newsLineMaxItems;
			id_new=newsLineId + '1';
		}
		
	Hide(id_old);
	Show(id_new);
	
}


function cursor()
{
	$('#rbnext').css({cursor:"pointer"});
	$('#rbprev').css({cursor:"pointer"});
	$('#rbpause').css({cursor:"pointer"});
}




function todaySlider(last_id,new_id,max_id)
{
  if(max_id > 5)
    max_id=5;  
    
  if(new_id == 'todayPos'+max_id)
       new_id='todayPos1';
  if(new_id == 'todayPos0')
    {   max_id--;
        new_id ='todayPos'+max_id;
    }
  $('#'+ last_id).addClass('hidden');
  $('#'+ new_id).removeClass('hidden');
 
}



function goHome()
{
    $('.logo_head').css({cursor:"pointer"});
    $('.logo_head').click(function()
    {
        document.location.href=Host;
    
    });
    
     $('.logo_text').css({cursor:"pointer"});
    $('.logo_text').click(function()
    {
        document.location.href=Host;
    
    });

}

function topdayNews(id,thumb_id)
{
    var maxElements=3;
    var baseId="js_top";
    var new_id=baseId+id;
    var thumb='Top_thumb';
    
    
    for(i=1;i<=3;++i)
    {
            if(!$(('#' + baseId) + i).hasClass('hidden'))
            {
                $(('#' + baseId) + i).addClass('hidden');
            }
            
             if($('#' + thumb + i).hasClass('redBrdIn'))
            {
                $('#' + thumb + i).removeClass('redBrdIn');
            }
    }
    
    
   
    $('#' + thumb_id).addClass('redBrdIn');
    $('#' + new_id).removeClass('hidden');
    
   
}

function Poll(command)
{
    var question_id='pollQuestion';
    var answer_id='pollAnswer';
    var answer2_id='pollAnswer2';
    
    var title_id='poll_title';
    var title2_id='poll_title2';
    
    switch(command)
    {
        case 'result':
        if(!$('#'+question_id).hasClass('hidden'))
        {
            $('#'+question_id).addClass('hidden');
        }

        if(!$('#'+answer2_id).hasClass('hidden'))
        {
            $('#'+answer2_id).addClass('hidden');
            $('#'+title2_id).addClass('hidden');
        }

        $('#'+answer_id).removeClass('hidden');
        $('#'+title_id).removeClass('hidden');
        break;

        case 'result2':
          if(!$('#'+question_id).hasClass('hidden'))
          {
              $('#'+question_id).addClass('hidden');
          }

          if(!$('#'+answer_id).hasClass('hidden'))
          {
              $('#'+answer_id).addClass('hidden');
              $('#'+title_id).addClass('hidden');
          }

          $('#'+answer2_id).removeClass('hidden');
          $('#'+title2_id).removeClass('hidden');
        break;
        
        case 'show':
          if(!$('#'+answer_id).hasClass('hidden'))
              $('#'+answer_id).addClass('hidden');
          if(!$('#'+answer2_id).hasClass('hidden'))
              $('#'+answer2_id).addClass('hidden');
               
          if($('#'+question_id).hasClass('hidden'))
              $('#'+question_id).removeClass('hidden');
        break;
    }
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


function chkPoll(id)
{
    var cookieId=getCookie("poll");
     if(cookieId == id)
     {
           Poll('result');
        
     }
     else
     {
     
        Poll('show');
     }
}

function PutCookie(name,value)
{

    var cookieId=getCookie("poll");
     if(cookieId == value)
     {
          alert("Error. Voiting twise");
          document.location.href=Host;
        
     }
     document.cookie=""+name+"="+value+"; path=/; expires=Mon, 01-Jan-2020 00:00:00 GMT";
     document.cookie=""+name+"="+value+"; path=/; expires=Mon, 01-Jan-2020 00:00:00 GMT";
     
}

function locate()
{
    if(document.location.href == Host)
    {
        document.location.href=Host;
    
    }

}

// running line
var material,makeLine_html,len,charPos=0,waiteTime=20,charsPerStep=1; //RunningLine
var makeLine_html = document.getElementById("jq_newsline1"); //RunningLine
var lineBigTimer=null; //big timer for newsLine
var tmpStr=new String();

function initLine(pos)
{
        tmpStr='';
        tmpStr+=newsLine[pos];
        material=tmpStr;
        len=tmpStr.length;
//        len = newsLine[pos].length;
        document.getElementById('Line_cursor').style.display="inline";
        makeLine();
}

function clearText()
{
    charPos=0;
    makeLine_html.innerHTML="";
    
    if(document.getElementById('Line_cursor'))
        document.getElementById('Line_cursor').style.display="none";

}

function makeLine()
{
        makeLine_html.innerHTML += material.substr(charPos,charsPerStep);
        charPos+=charsPerStep;

        if(charPos<len)
              
                setTimeout("makeLine()",waiteTime);
        else
                document.getElementById('Line_cursor').style.display="none";
      
}

var timer_i=0;

function lineTimer()
{
   clearText();
    if(timer_i+1 > newsLineCountMax)
        timer_i=0;

    makeLine_html.href=Host+"/cat/material/id/" + newsLineArtId[timer_i+1] + ".html";
    initLine(++timer_i);

}

//running line

//line buttons
var playing=true;
function afterPausePlayLines()
{
    lineBigTimer=setInterval('lineTimer()',10000);

}
    
function newsLineButtons()
{
    var baseURL=Host+"/img/";
    var prevIcon=baseURL + "rbprev.gif";
    var pauseIcon=baseURL + "rbpause.gif";
    var nextIcon=baseURL + "rnext.gif";
    var playIcon=baseURL + "layout/rbplay.gif";
    
    var pausePlayId="rbpause";
    var pausePlayObj= document.getElementById(pausePlayId);
    
	$('#rbnext').click(function()
	{
//	    clearInterval(lineBigTimer);
//	    lineBigTimer=setInterval('lineTimer()',10000);
        lineTimer();

		
	});

	$('#rbprev').click(function()
	{
		timer_i-=2;
		
		
		if(timer_i<0)
		    timer_i = newsLineCountMax-1;
		    
		lineTimer();
	});
	
	$("#rbpause").click(function()
	{
        if(playing)
		{
		        playing=!playing;
		        clearInterval(lineBigTimer);
		        pausePlayObj.src=playIcon;
		}
		else
		{
		        playing=!playing;
//		        lineTimer();
		        afterPausePlayLines();
		        pausePlayObj.src=pauseIcon;
		}
	});
}

//line buttons


locate();
goHome();

cursor(); // puts neded cursor style
page_reload_icon(); // refresh page if clicked refresh


if(makeLine_html)
    {
        lineTimer();

        lineBigTimer=setInterval('lineTimer()',10000);
        newsLineButtons();
   }
   
function initVars()
{
    videoclips_max_pages/=4;
    videoclips_max_pages=Math.ceil(videoclips_max_pages);
   
}
initVars();

//if(videoclips_max_pages == 1 || videoclips_max_pages == 0  )
//    {
//        
//    }

//alert(newsLineArtId[2]);

//newsLineTooglerTimer=setInterval('newsLineToogler()',5000); // slide show of news in line
//newsLineButtons(); // control buttons for slideshow of newsline
if(poll_id != undefined)
    chkPoll(poll_id);

