// JavaScript Document

/*==========================================================================================*/

/* Initial All Groups */

function InitialAllGroups()
{
	for(i=1; i<=images.length-1; i++)
	{
		InitialValue(i);
	}
}
/*==========================================================================================*/

/* Initial start value next-prev */

function InitialValue(newsGroup)
{
	document.getElementById('newsImage'+newsGroup).style.background = 'url('+images[newsGroup][currentImages[newsGroup]]+') center center no-repeat';
	
	if(images[newsGroup].length==0)
	{
		document.getElementById("unlink_nextPic"+newsGroup).style.display="block";
		document.getElementById("unlink_prevPic"+newsGroup).style.display="block";
	}
	if(currentImages[newsGroup]==(images[newsGroup].length-1))
	{
		document.getElementById("unlink_nextPic"+newsGroup).style.display="block";
		document.getElementById("unlink_prevPic"+newsGroup).style.display="block";
	}
	if(currentImages[newsGroup]<(images[newsGroup].length-1)) 
	{
		document.getElementById("link_nextPic"+newsGroup).style.display="block";
		document.getElementById("unlink_prevPic"+newsGroup).style.display="block";
	}
}
/*==========================================================================================*/

/* Next picture */

function showNext(newsGroup)
{
	if(currentImages[newsGroup]<images[newsGroup].length-1)
	{
		currentImages[newsGroup]++;
		document.getElementById('newsImage'+newsGroup).style.background = 'url('+images[newsGroup][currentImages[newsGroup]]+') center center no-repeat'; 
	
		if(currentImages[newsGroup]==(images[newsGroup].length-1))
		{
			document.getElementById("link_nextPic"+newsGroup).style.display="none";
			document.getElementById("unlink_nextPic"+newsGroup).style.display="block";
			document.getElementById("link_prevPic"+newsGroup).style.display="block";
		}
		else if(currentImages[newsGroup]>1)
		{
			document.getElementById("unlink_prevPic"+newsGroup).style.display="none";
			document.getElementById("link_prevPic"+newsGroup).style.display="block";
		}
	}
}   
/*==========================================================================================*/

/* Prev picture */

function showPrevious(newsGroup)
{
	if(currentImages[newsGroup]>1)
	{
		currentImages[newsGroup]--;
		document.getElementById('newsImage'+newsGroup).style.background = 'url('+images[newsGroup][currentImages[newsGroup]]+') center center no-repeat'; 
		
		if(currentImages[newsGroup]==1)
		{
			document.getElementById("link_nextPic"+newsGroup).style.display="block";
			document.getElementById("unlink_nextPic"+newsGroup).style.display="none";
			document.getElementById("link_prevPic"+newsGroup).style.display="none";
			document.getElementById("unlink_prevPic"+newsGroup).style.display="block";
			
		}
		else if(currentImages[newsGroup]<images[newsGroup].length-1)
		{
			document.getElementById("link_prevPic"+newsGroup).style.display="block";
			document.getElementById("link_nextPic"+newsGroup).style.display="block";
			document.getElementById("unlink_nextPic"+newsGroup).style.display="none";
		}
	}
}
/*==========================================================================================*/

/* ViewHideBigMap */

function ShowBlock(id)
{
	document.getElementById(id).style.display = 'block'; 
}

function HideBlock(id)
{
	document.getElementById(id).style.display = 'none';
}
/*==========================================================================================*/

/* ViewBigImgPresenter */

function VieBigImg(id)
{
	document.getElementById('BigImg').style.background = 'url(images/bigimgNiki_'+id+'.jpg) center center no-repeat'; 
}
/*==========================================================================================*/

/* SetCurrentPart */

function SetCurrentPart(id)
{
	curr_part = id;
	
	if(curr_part==1)
	{
		document.getElementById('CurrentPart1').style.background = 'url(images/backgrCurrPart.jpg) top left no-repeat'; 
		document.getElementById('CurrentPart2').style.background = 'url(images/backgrCurrPart_off.jpg) top left no-repeat';
		document.getElementById('CurrentPartInfo1').style.background = 'url(images/currPartInfo.gif) center center no-repeat';
		document.getElementById('CurrentPartInfo2').style.background = 'url(images/currPartInfo.gif) 0px -10px no-repeat'; 
	}
	else
	{
		document.getElementById('CurrentPart1').style.background = 'url(images/backgrCurrPart_off.jpg) top left no-repeat';
		document.getElementById('CurrentPart2').style.background = 'url(images/backgrCurrPart.jpg) top left no-repeat';
		document.getElementById('CurrentPartInfo1').style.background = 'url(images/currPartInfo.gif) 0px -10px no-repeat'; 
		document.getElementById('CurrentPartInfo2').style.background = 'url(images/currPartInfo.gif) center center no-repeat';
	}
}
/*==========================================================================================*/

function show_photo( PHOTO_NR ) {

	document.getElementById( 'bigPhotoHolder' ).style.background = 'url('+photos[PHOTO_NR]+') center center no-repeat'; 
}

function show_calendar( go_date ) {
//   $("select").hide();
   if ( !go_date ) {

	   go_date = selected_day ;
   }

   $.ajax({
		   type: "POST",
		   url: "/news_calendar.pcgi",
		   data: "show_date=" + go_date+'&participant='+part_page+'&p='+player_id+'&qtype='+qtype+'&t='+page_type,
		   async: false,
		   dataType: "text",
		   success: function(text){

						$('#newsCalCnt').empty();
						$('#newsCalCnt').html( text );
						$('#newsCalCnt').show();
				}
		   }
		);
}

function hide_calendar() {
//$("select").show();
$('#newsCalCnt').hide();
}
		

			
function play_video( VIDEO_ID , SRC ) {

	$( '#video_id' ).attr( 'value' , VIDEO_ID );
	if ( SRC == 1 ) {
	
		$( '#videoFilterForm' ).attr( 'action' , 'video.pcgi' );
	} else if ( SRC == 2 ) {
	
		$( '#videoFilterForm' ).attr( 'action' , 'part_video.pcgi' );
	}
	$( '#videoFilterForm' ).submit();
}

function show_comments( VIDEO_ID , CP , SEND ) {

   var post_data = "video_id=" + VIDEO_ID+'&cp='+CP ;
   if ( SEND != null && SEND > 0  ) {
   
	   post_data += "&commText="+$('#message').val();
   }
   $.ajax({
		   type: "POST",
		   url: "/video_comments.pcgi",
		   data: post_data,
		   async: false,
		   dataType: "html",
		   success: function(text){

						$('#AllComm').empty();
						document.getElementById( 'AllComm' ).innerHTML=text;
						$('#AllComm').show();
				}
		   }
		);
}
var current_photo = 0 ;
function show_big_photo( photo_nr ) {
	current_photo = photo_nr ;
	document.getElementById( 'bigPhoto' ).style.background = 'url('+photos[photo_nr]+') center center no-repeat'; 
	$('#ImgFamily').show();
		
	if (top.location.href.indexOf("part_profile") > 0) {
		initIframe(4);
	}	
}

function hide_big_photo() {

	document.getElementById( 'bigPhoto' ).style.background = 'url() center center no-repeat'; 
	$('#ImgFamily').hide();
	
	if (top.location.href.indexOf("part_profile") > 0) {
		initIframe(4);
	}	

	
	if ( player_gallery == 1 ) {

		//initIframe(4);
	}
}

function next_big_photo() {
	
	$('#prev_big_photo').show();
	$('#next_big_photo').show();

	if ( current_photo + 1 <= photos.length - 1 ) {
		current_photo++ ;
		document.getElementById( 'bigPhoto' ).style.background = 'url('+ photos[current_photo]+') center center no-repeat';
		if ( current_photo == photos.length - 1 && !$('#paging_next_link').attr( 'href' ) ) {

			$('#next_big_photo').hide();
		}
	} else if ( $('#paging_next_link').attr( 'href' ) )  {

		document.location.href= $('#paging_next_link').attr( 'href' ) + '&showBig=1' ;
	}
}


function prev_big_photo() {

	$('#prev_big_photo').show();
	$('#next_big_photo').show();
	
	if ( current_photo - 1 > 0 ) {
		
		current_photo-- ;
		document.getElementById( 'bigPhoto' ).style.background = 'url('+ photos[current_photo]+') center center no-repeat';
		if ( current_photo == 1 && ! $('#paging_prev_link').attr( 'href' ) ) {
			
			$('#prev_big_photo').hide();
		}
	} else if ( $('#paging_prev_link').attr( 'href' ) ) {

		document.location.href= $('#paging_prev_link').attr( 'href' ) + '&showBig=24' ;
	}

	if ( player_gallery == 1 ) {

		//initIframe(4);
	}
}


function popUpChat(wVideo, multicast) {
	window.open('chat.pcgi','chatPopup','resizable=yes,width=770,height=560');
}

// forum 
function mass_action($a) {
	
	document.getElementById('mass_action').value = $a;
	document.getElementById('forumFrm').submit();
}
// forum 
function replaceSelection(o, tag) {
	// ie
	var content = '';
	if (document.selection) {
		o.focus();
		sel = document.selection.createRange();
		var seltext = sel.text;
		if ('url' == tag) {
			var url = prompt('Въведете адреса на връзката: ', 'http://');
			if (!url || url == 'http://')
				return;
			if (seltext.length) {
				url = '='+url;
			} else {
				seltext = url;
				url = '';	
			}
			content = '[url'+url+']'+seltext+'[/url]';
		} else {
			content = '['+tag+']'+seltext+'[/'+tag+']';
		}
		if (content)	
			sel.text = content;
		o.focus();
	}
	//mozilla/netscape
	else if ((o.selectionStart || o.selectionStart == '0')) {
		var startPos = o.selectionStart;
		var endPos = o.selectionEnd;
		var cursor = startPos;
		var prev = '';
		var sel = o.value.substring(startPos, endPos);
		if ('url' == tag) {
			var url = prompt('Въведете адреса на връзката: ', 'http://');
			if (!url || url == 'http://')
				return;
			if (sel) {
				url = '='+url;
			} else {
				sel = url;
				url = '';	
			}
			prev = '[url'+url+']';
			content = prev+sel+'[/url]';
		} else {
			prev = '['+tag+']';
			content = prev+sel+'[/'+tag+']';
		}
		if (content)
			o.value = o.value.substring(0, startPos) + content + o.value.substring(endPos, o.value.length);
		if (sel)
			cursor = cursor + content.length;
		else
			cursor = cursor + prev.length;
		o.selectionStart = cursor;
		o.selectionEnd = cursor;
		o.focus();	
	} else {
		o.value += '['+tag+'][/'+tag+']';
		o.focus();
	}
}

function startVideo( ST ) {

	window.onunload=null;
	$('#st').val(ST);
	$('#st_form').submit();
}

function popUpLive(ST) {

	document.getElementById( 'NaJivoPlayer' ).innerHTML = '<div></div>';
	window.open('pop_stream.pcgi?p_st='+ST,'live_popup','resizable=yes,width=700,height=500');
}

function popUpChatLive(ST) {

	document.getElementById( 'NaJivoPlayer' ).innerHTML = '<div></div>';
	window.open('pop_stream_chat.pcgi?p_st='+ST,'live_popup','resizable=yes,width=1000,height=580');
}

function calc_symbols_left() {

	$('#symbols_left').html( 1000 -  $('#forum4Message').val().length );
}


function go_to_player( P_ID ) {

	document.location.href="part_info.pcgi?p="+P_ID;
}

function anketa_show_results( AC ) {

	$('#show_results').val(AC);
	$('#FrmA').submit();
}
