/* Function for change tabs in LISTEN R&R block*/
var status = false;
var statusSL = false;
var validationCloseSearchForm = false; 
var validationCloseSearchFormSL = false; 

var tmpSearchText = "Enter search criteria";

function change_ptabs(menu_selected){
	$('player_td').fade('out');
	var myRequest = new Request({method: 'get', url: './ajax/change_ptabs.php',
		onComplete: function(r) {
				//alert(r);
				$('player_td').set('html', '');
			    $('artist_info').set('html', '');
			    
				$('p_tab1').set('class', 'menu_td');
				$('p_tab2').set('class', 'menu_td');
				$('p_tab3').set('class', 'menu_td');
				//$('p_tab4').set('class', 'menu_td');
				$('p_tab5').set('class', 'menu_td');
				
				if($(menu_selected))
					$(menu_selected).set('class', 'menu_td_act');
				if(r!="-1"){
					validationCloseSearchForm = true;
					validationCloseSearchFormSL = true;
				    if (Browser.Plugins.Flash.version) {
						$('player_td').set('html', r);
					}else{
						//$('player_td').set('html', '<div style="padding-top:50px;"><img src="./images/wait.gif"/></div>');
						$('player_td').set('html', '<div style="height: 126px; border: 1px solid #66CCFF; background-color:#7cbbfe; padding-top: 87px; color: #FFFFFF; text-align:center;">Flash player is not installed. Please, click <a href="http://www.adobe.com/products/flashplayer/" target="_blank">here</a> for install Flash Player.<br><a href="http://www.adobe.com/products/flashplayer/" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" border="0"></a><br></div>');
					}
				}else{
					if(menu_selected == 'p_tab4'){
						$('player_td').set('html', '<div style="height: 126px; border: 1px solid #66CCFF; background-color:#7cbbfe; padding-top: 76px; color: #FFFFFF; text-align:center; font-size: 19px;">Find music according to your preferences</div>');
						validationCloseSearchForm = false;
						showSearchPanel();
					}
					if(menu_selected == 'p_tab5'){
						$('player_td').set('html', '<div style="height: 126px; border: 1px solid #66CCFF; background-color:#7cbbfe; padding-top: 76px; color: #FFFFFF; text-align:center; font-size: 19px;">Find music according to your preferences</div>');
						validationCloseSearchFormSL = false;
						showSearchPanelSL();
					}
				}
				$('player_td').fade('in');
			},
		onFailure: function() {
			}
	}).send("page="+menu_selected);
	if(status){
		status = false;
	}
	if(statusSL){
		$('searchPanelSL').fade('out');
		status = false;
		statusSL = false;
	}
}

/* Function for change artist information in LISTEN R&R block
*  called from player	
*/
function change_artict_info(track_id){
	$('artist_info').fade('out');
	var myRequest = new Request({method: 'get', url: './ajax/change_artict_info.php',
		onComplete: function(r) {
				//alert(r);
				$('artist_info').set('html', '');
			
				$('artist_info').set('html', r);
				$('artist_info').fade('in');
			},
		onFailure: function() {
//				alert("Try later...");
			}
	}).send("track_id="+track_id);
}

/*
* Raiting pager
*/	
function filter_rating(menu_selected, submenu_selected){
	$('rating_block').fade('out');
	var myRequest = new Request({method: 'get', url: './ajax/rating.php',
		onComplete: function(r) {
				$('rating_block').set('html', '');
			
				$('f').set('class', 'menu_td');
				$('a').set('class', 'menu_td');
				//$('m').set('class', 'menu_td');
				$('p').set('class', 'menu_td');
				$('v').set('class', 'menu_td');
				//$('e').set('class', 'menu_td');
				//$('b').set('class', 'menu_td');
			
				$(menu_selected).set('class', 'menu_td_act');
		
				$('rating_block').set('html', r);
				$('rating_block').fade('in');
			},
		onFailure: function() {
//				alert("Try later...");
			}
	}).send("page="+menu_selected+"&subpage="+submenu_selected);
}

/*
* News Block pager
*/	
function filter_newsblock(menu_selected){
	$('music_news_block').fade('out');
	var myRequest = new Request({method: 'get', url: './ajax/news_block.php',
		onComplete: function(r) {
				$('music_news_block').set('html', '');
			
				$('n_r').set('class', 'menu_td');
				//$('n_f').set('class', 'menu_td');
				//$('n_b').set('class', 'menu_td');
				
				$(menu_selected).set('class', 'menu_td_act');
		
				$('music_news_block').set('html', r);
				$('music_news_block').fade('in');
			},
		onFailure: function() {
//				alert("Try later...");
			}
	}).send("page="+menu_selected);
}

/*
* ARENA PLAYER Block pager
*/	

function arena_tabs(menu_selected){
	var file_path = '';

	$('ap_c').set('class', 'menu_td');
	//$('ap_pt').set('class', 'menu_td');
	$('ap_p').set('class', 'menu_td');
	//$('ap_i').set('class', 'menu_td');			
	$(menu_selected).set('class', 'menu_td_act');

	switch(menu_selected){
		case 'ap_c':
			file_path = './arena_player/video_competitions.xml';
		break;
		case 'ap_pt':
			file_path = './arena_player/video_power.xml';
		break;
		case 'ap_p':
			file_path = './arena_player/video_panelists.xml';
		break;
		case 'ap_i':
			file_path = '../arena_news.php';
		break;
		default:
			file_path = './arena_player/video_competitions.xml';
		break;
	}
	
	var flashvars = {};
	flashvars.xmlfile = file_path;
	flashvars.autoplay = "off";
	var params = {};
	params.wmode="opaque";
	var attributes = {};

	swfobject.embedSWF("./arena_player/videoplayer.swf", "FlashDiv", "620", "350", "9.0.0", "./arena_player/js/expressInstall.swf", flashvars, params, attributes);
}
	
window.addEvent('domready', function() {
		change_ptabs('p_tab1');
		filter_rating('f','rating');
		filter_newsblock('n_r');
		arena_tabs('ap_c');
		charts_change("Reklama");
});


window.addEvent('domready', function() {
//	$('virus_bi').fade('out');
//	$('virus_bi').makeDraggable();
//	$('virus_bi_closer').addEvent('click', function() {
//		virus_hide_bi_div();
//	});
	
	//video
	$('video_div').fade('out');
	$('video_div').makeDraggable();
	$('video_div_closer').addEvent('click', function() {
		taras_hide_video_div();
	});
});
// END virus_bi (div emerging on profile).

// BEGIN taras:
function taras_show_video_div() {
	virus_hide_bi_div();
	var width = 330;
	var height = 300;
	var size		= window.getSize();
	var scroll_pos	= window.getScroll();
	var left = ((size.x - width) / 2) + scroll_pos.x;
	var top = ((size.y - height) / 2) + scroll_pos.y;
	var a= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="300" id="fp" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="fp.swf?video=./video/{/literal}{$educ_video}{literal}.flv&image=./video/{/literal}{$educ_video}{literal}.gif&title=" />'+
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#184564" />'+
	'<embed src="fp.swf?video=./video/{/literal}{$educ_video}{literal}.flv&image=./video/{/literal}{$educ_video}{literal}.gif&title=" quality="high" bgcolor="#ffffff" width="320" height="260" name="fp" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
'</object>';
	
	$('video_player_container').setStyle('display', 'block');
	$('video_player_container').set('html', a);
	
	$('video_div').setStyle('left', left+'px');
	$('video_div').setStyle('top', top+'px');
	$('video_div').setStyle('width', width+'px');
	$('video_div').setStyle('height', height+'px');
	$('video_div').setStyle('display', 'block');
	$('video_div').fade(0.9); // 'out' | 0.7
}

function taras_hide_video_div() {
	$('video_div').fade('out');
	$('video_player_container').set('html', '');
}
// END taras.

//CHANGE CHART LIST
/*
$('chart_id').addEvent('change', function() {
	//charts_change(this.value);
 });
*/

function charts_change(chart_id){
    var chart_id = Number(chart_id);
	$('charts_table').fade('out');
    var myRequest = new Request.JSON({url: './ajax/charts_refresh.php',
	onComplete: function(r) {
		$('charts_table').set('html', ''); 
		var tr = '';	
		var i = 0;
		r.each(function(item) {
		if(i % 2 == 0)
			tr+= '<tr>';
		else
			tr+= '<tr>';
			tr+= '<td valign="top" width="5%" >&nbsp;&nbsp;' + item.item_position + '.&nbsp;</td>';
			
			if(chart_id>=0){
				tr_width = '40';
			}else{
				tr_width = '95';
			}
						
			tr+= '<td valign="top" width="'+tr_width+'%">' + item.item_name + '</td>';
			if(chart_id>=0){
				tr+= '<td valign="top" width="55%">' + item.item_song + '</td>';
			}
			tr+= '</tr>';
			i++;
		});
			$('charts_table').set('html', tr);
			$('charts_table').fade('in');
		},
		onFailure: function() {
//			alert("Try later...");
		}
	}).get({'chart_id': chart_id});
}
 
//ADD TRACK TO DEFAULT PLAYER (called from AC Player)
function addToDefUserPlaylist(id, action){
	var sum = id;
	var action_str = '';
	switch(action){
		case 0:action_str = "add";break;
		case 1:action_str = "remove";break;
	}

	var myRequest = new Request({method: 'get', url: './ajax/add_to_player.php',
		onComplete: function(r) {
			if (r == 1) {
			}
		},
		onFailure: function() {
					}
	});
	myRequest.send('audio_id='+id+'&action='+action_str);
}

function MM_findObj(n, d) { //v4.01
 var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
   d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
 if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

window.addEvent('domready', function () {
	status = false;
	$('search_text_sl').value = tmpSearchText;
	
	$('search_form_sl').addEvent('submit', function(e) {
		e.stop();
		$('player_td').set('html', '<div style="height: 126px; background-color:#FFFFFF; padding-top: 50px; color: #FFFFFF; text-align:center; font-size: 19px;"><img src="./images/wait.gif"></div>');
		this.set('send', {onComplete: function(response) {
			menu_selected = 'p_tab5';
		    $('player_td').set('html', '');
		    $('artist_info').set('html', '');
		    
		    $('p_tab1').set('class', 'menu_td');
			$('p_tab2').set('class', 'menu_td');
			$('p_tab3').set('class', 'menu_td');
			$('p_tab5').set('class', 'menu_td');
		    
		    if($(menu_selected))
				$(menu_selected).set('class', 'menu_td_act');
				
			if(response!="-1"){
				validationCloseSearchFormSL = true;
				if (Browser.Plugins.Flash.version) {
					$('player_td').set('html', response);
				}else{
					$('player_td').set('html', '<div style="height: 126px; border: 1px solid #66CCFF; background-color:#7cbbfe; padding-top: 76px; color: #FFFFFF; text-align:center;">Flash player is not installed. Please, click <a href="http://www.adobe.com/products/flashplayer/" target="_blank">here</a> for install Flash Player.<br><a href="http://www.adobe.com/products/flashplayer/" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" border="0"></a><br></div>');
				}
			}else{
				validationCloseSearchFormSL = false;
				var sufix = '';
				var sText = $('search_text_sl').value;
				/*if(sText!=""){
					 sufix = 'for <br>"<b>'+sText.substring(0,14);
					 if(sText.length()>14)
					 	sufix += '...';
					 sufix += '</b>"';
				} */ 
				//alert("There are currently no artists that match your search. Please try again.");
				$('player_td').set('html', '<div style="height: 126px; border: 1px solid #66CCFF; background-color:#7cbbfe; padding-top: 76px; color: #FFFFFF; text-align:center;">There are currently no artists that match your search. Please try again.</div></div>');
				//$('player_td').set('html', '');
			}
			$('player_td').fade('in');
			if(statusSL && response!="-1"){
				$('searchPanelSL').fade('out');
				statusSL = false;
			}
		}});
		this.send();
	});
});


function showSearchPanel(){
	if(!status){
		$('searchPanelSL').fade('out');
		statusSL = false;
		status = true;
	}
	else{
		if(validationCloseSearchForm){
			status = false;
		}
	}
}

function showSearchPanelSL(){
	if(!statusSL){
		$('searchPanelSL').setStyle('display', 'block');
		$('searchPanelSL').fade('in');
		status = false;
		statusSL = true;
	}
	else{
		if(validationCloseSearchFormSL){
			$('searchPanelSL').fade('out');
			statusSL = false;
		}
	}
}

function clickLink(str){
	$('search_text_sl').value = str;
}

function onEnterSearchLine(){
	if($('search_text_sl').value == tmpSearchText){
		$('search_text_sl').value = "";
	}else if($('search_text_sl').value == ""){
		$('search_text_sl').value == tmpSearchText;
	}
	
}

function onExitSearchLine(){
	if($('search_text_sl').value == ""){
		$('search_text_sl').value = tmpSearchText;
	}
	
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}