var isBackend = false;
var AnalysisCurrentIndex=0;

//document.write('<script type="text/javascript" src="' + (isBackend?'../':'') + 'lib/js/frontend/swfobject.js"></script>');
//document.write('<script type="text/javascript" src="' + (isBackend?'../':'') + 'lib/js/frontend/jsGallery.js"></script>');

var currentFontSize = 11;
function incrementDecrementFont(step, object)
{		
	if ((currentFontSize+step) <= 9 || (currentFontSize+step) >= 15) 
	{	
		return false;
	}
	else
	{			
		currentFontSize += step;
		document.getElementById(object).style.fontSize = currentFontSize + 'px';		
	}	
}

function popup_dialog(url,winWidth,winHeight,sb) 
{
	winTop = (screen.height - winHeight) / 2;
	winLeft = (screen.width - winWidth) / 2;
	window.open(url,"","width=" + winWidth + ",height=" + winHeight + ",top=" + winTop  + ",left=" + winLeft  + ",resizable=no,scrollbars=" + sb + ",toolbar=no");
}

function changeTab(sender, target)
{	
	initArticlesTab();
	sender.className = "active_tab";
	$(target).show();
}

function initArticlesTab()
{
	document.getElementById('tabArticles').className = "";
	document.getElementById('tabVideos').className = "";
	document.getElementById('tabPictures').className = "";
	$('tabNewsContent').hide();
	$('tabVideosContent').hide();
	$('tabPicturesContent').hide();
}

function sendFriend(type, id, name, email, rec_email, url, submit_url)
{
	$('label_' + name).removeClassName('red_text');
	$('label_' + email).removeClassName('red_text');
	$('label_' + rec_email).removeClassName('red_text');
	hasErr = false;
	if(!$(name).value)
	{
		hasErr = true;
		$('label_' + name).addClassName('red_text');
	}
	if(!$(email).value)
	{
		hasErr = true;
		$('label_' + email).addClassName('red_text');
	}
	if(!$(rec_email).value)
	{
		hasErr = true;
		$('label_' + rec_email).addClassName('red_text');
	}
	
	if(!hasErr && url && submit_url && type && id)
	{
		new Ajax.Request(submit_url,
  		{
		    method:'post',
		    parameters: {type: type, id: id, from: $(email).value, name: $(name).value, to: $(rec_email).value, url: url},
			onSuccess: function(transport){
			  var response = transport.responseText || "no response text";
			  if(response.indexOf('on line <b>')==-1)
			  {
			  	hideLightbox();
			  }
			  else
			  {
			  	
			  }
			},
			onFailure: function(){
				
			}
		});
	}
}

/**
 * JavaScript validation for date list boxes.
 */
function dateClientValidate(sender, parameter)
{
	fromday = document.getElementById('ctl0_Content_FromDay');
	frommonth = document.getElementById('ctl0_Content_FromMonth');
	fromyear = document.getElementById('ctl0_Content_FromYear');
	today = document.getElementById('ctl0_Content_ToDay');
	tomonth = document.getElementById('ctl0_Content_ToMonth');
	toyear = document.getElementById('ctl0_Content_ToYear');
	error = document.getElementById('ctl0_Content_ErrorDate');
	
	if (((today.value == '-' || tomonth.value == '-' || toyear.value == '-') && 
		(today.value != '-' || tomonth.value != '-' || toyear.value != '-')) || 
		((fromday.value == '-' || frommonth.value == '-' || fromyear.value == '-') && 
		(fromday.value != '-' || frommonth.value != '-' || fromyear.value != '-')))
	{
		error.style.display = '';
		return false;
	}
	else
	{ 
		error.style.display = 'none';
		return true;
	}
}

function initAnalysis()
{
	setAnalysisData(AnalysisCurrentIndex);
}

function analysisNext()
{
	if (AnalysisCurrentIndex>=2)
		AnalysisCurrentIndex = 0;
	else
		AnalysisCurrentIndex++;
		
	setAnalysisData(AnalysisCurrentIndex);
	
	return false;
}

function analysisPravious()
{
	if (AnalysisCurrentIndex<=0)
		AnalysisCurrentIndex = 2;
	else
		AnalysisCurrentIndex--;
	setAnalysisData(AnalysisCurrentIndex);
	
	return false;
}

function setAnalysisData(CurrentIndex)
{
	var a = $$('#analysis_'+CurrentIndex+' a');	
	var url = a[0].href;
	
	$('AnalysisDot0').className = "";
	$('AnalysisDot1').className = "";
	$('AnalysisDot2').className = "";
	
	$('AnalysisDot'+CurrentIndex).className = "active_tab";
	
	var span = $$('#analysis_'+CurrentIndex+' span');
	var date = span[0].innerHTML;
	var title = span[1].innerHTML;
	var img = span[2].innerHTML;
	var numVideos = parseInt(span[3].innerHTML);
	
	
	$('analysisMainImage').src = img;
	$('analysisMainTitle').innerHTML = title;
	$('analysisMainTitle').href = url;
	$('analysisMainDate').innerHTML = date;
	$('analysisMainUrl').href = url;
	
	if (numVideos==0) 
		$('analysisMainHasVideo').style.display='none';
	else
		$('analysisMainHasVideo').style.display='';
}

function analysisDot(number)
{
	AnalysisCurrentIndex = number;
	setAnalysisData(AnalysisCurrentIndex);
	return false;
}

function changeTabSP(sender, target)
{	
	document.getElementById('standingTab').className = "";
	document.getElementById('programmeTab').className = "";	
	$('programme').hide();
	$('standing').hide();
	
	sender.className = "active_tab";
	$(target).show();
}

var pe = null;
var pe_active_index = 0;
function startPE()
{
	pe = new PeriodicalExecuter(function(pe) {
		if(pe_active_index==4) pe_active_index = 0;
		else pe_active_index++;
		
		tabs_menu_home.setActiveTab(pe_active_index);
		$$('#leading_holder div.top_news_cnt').invoke('hide');
		$$('#leading_holder div.top_news_cnt')[pe_active_index].show();
	}, 5);
}

function stopPE()
{
	pe.stop();
}

var galleryCurrentIndex=0;

function setGallery(index)
{
	$('gallery0').hide();
	$('gallery1').hide();
	$('gallery2').hide();
	$('gallery3').hide();
	$('gallery4').hide();
	$('gallery5').hide();
	
	$('galleryTab0').className="";
	$('galleryTab1').className="";
	$('galleryTab2').className="";
	
	$('galleryTab'+index).className="active_tab";
	
	index = index*2;
	
	var next = index + 1;
	
	$('gallery'+index).show();
	$('gallery'+next).show();
}

function galleryNext()
{
	if (galleryCurrentIndex>=2)
		galleryCurrentIndex = 0;
	else
		galleryCurrentIndex++;
		
	setGallery(galleryCurrentIndex);
}

function galleryPrevious()
{
	if (galleryCurrentIndex<=0)
		galleryCurrentIndex = 2;
	else
		galleryCurrentIndex--;
		
	setGallery(galleryCurrentIndex);
}


var videoCurrentIndex=0;

function setVideo(index)
{
	$('video0').hide();
	$('video1').hide();
	$('video2').hide();
	$('video3').hide();
	$('video4').hide();
	$('video5').hide();
	
	$('videoTab0').className="";
	$('videoTab1').className="";
	$('videoTab2').className="";
	
	$('videoTab'+index).className="active_tab";
	
	index = index*2;
	
	var next = index + 1;
	
	$('video'+index).show();
	$('video'+next).show();
}

function videoNext()
{
	if (videoCurrentIndex>=2)
		videoCurrentIndex = 0;
	else
		videoCurrentIndex++;
		
	setVideo(videoCurrentIndex);
}

function videoPrevious()
{
	if (videoCurrentIndex<=0)
		videoCurrentIndex = 2;
	else
		videoCurrentIndex--;
		
	setVideo(videoCurrentIndex);
}

var isNotProccessAjax=true;

/**
 * Javascript functionality to show that ajax request is being processed
 */

/**
 * Shows loading gif when an ajax is eing processed
 */
function displayLoading(e){
 	var mouseX = Event.pointerX(e),
    		mouseY = Event.pointerY(e); 
    $("loading").setStyle({left: mouseX + 10 + 'px', top: mouseY + 16 + 'px', visibility: 'visible'})
}

/**
 * Sets the onload event of a starting ajax execution
 */
function setLoadEvent() {
	isNotProccessAjax=false;
    document.onmousemove = displayLoading;
}

/**
 * Sets the end event of an ajax request
 */
function setCompleteEvent() {
	document.onmousemove = function(){}
	$("loading").setStyle({visibility: 'hidden'})
	isNotProccessAjax=true;
}
/**
 * End of js functionality for the ajax requests
 */