$(function() 
		{
			$('.blink').blink();
			$('.themeImg').each(function() 
			{
				var maxWidth = 390;
				var maxHeight = 250;
				var width = $(this).width();
				var height = $(this).height();
				if(width>height && width>maxWidth)
				{
					ratio = maxWidth / width;
					$(this).css("width", maxWidth);
					$(this).css("height", height * ratio);
				}
			});
		
			$('.search_cat').mouseover(function() {$('#search_more').show();});
			$('#search_more').mouseleave(function() {$(this).hide();});
			$('#genderBut').mouseover(function() {$('#genders').show();});
			$('#genders').mouseleave(function() {$(this).hide();});
			$('#resultTop').mouseleave(function() {$(this).fadeOut().html('').fadeIn();});
			$(".setHov").hover(
			  function () {
				$(this).addClass("hover");
			  },
			  function () {
				$(this).removeClass("hover");
			  }
			);
			$('.balloon').bt({
				padding: 3,
				shrinkToFit: true,
				spikeLength: 7,
				spikeGirth: 7,
				cornerRadius: 8,
				fill: 'rgba(0, 0, 0, .8)',
				strokeWidth: 2,
				width: 400,
				strokeStyle: '#DFDFDF',
				positions: ['top','bottom'],
				cssStyles: {color: '#FFF', fontWeight: 'normal', fontSize: '12px', fontFamily: '"Georgia"', textAlign: 'center'}
				});
			$('#menu-more').mouseleave(function() {$(this).fadeOut();})
			$('.greeto').bt({
				trigger: ['click', 'click'],
				ajaxPath: 'show_me.php?what=play&f=1&id='+$('.greeto').attr('name'),
				padding: 3,
				shrinkToFit: true,
				spikeLength: 7,
				spikeGirth: 7,
				cornerRadius: 8,
				fill: 'rgba(0, 0, 0, .8)',
				strokeWidth: 2,
				width: 400,
				strokeStyle: '#DFDFDF',
				positions: ['top','bottom'],
				cssStyles: {color: '#FFF', fontWeight: 'normal', fontSize: '12px', fontFamily: '"Georgia"', textAlign: 'center'}
				});
		});
function enableButton(id)
{
	if($(id).attr('disabled'))
	{
		$(id).removeAttr("disabled");	
	}
	else
	{
		$(id).attr('disabled','disabled');
	}
}
function dobav(show,butons,hid){
var prove = document.getElementById(butons);
document.getElementById(show).style.display ="inline";
document.getElementById(hid).style.display ="none";
document.getElementById(butons).href = "javascript:hidden('"+show+"','"+butons+"','"+hid+"')";
}
function hidden(show,butons,hid) {
document.getElementById(show).style.display ="none";
document.getElementById(butons).href = "javascript:dobav('"+show+"','"+butons+"','"+hid+"')";
}
function prov(pole){
var artist = document.getElementById(pole); 
if(artist.value == ""){
document.getElementById(pole).style.border = "2px solid red";
document.getElementById('submit').disabled  = "true";
}
else if(artist.value == 0){
alert("Изберете категория!");
artist.focus();
return false;
}
else{
document.getElementById(pole).style.border = "2px solid green";
document.getElementById('submit').disabled = "";
}
}
function search(e,type)
{
  var searches = document.getElementById('text').value;
  var searches = searches.replace("&"," ");
	if(type == "mp3" || type == "album" || type == "news" || type == "text") 
		{
			window.location = "search.php?s="+searches+"&btn="+type;
		}
		
	if(type == "video")
		{
			window.open('search.php?s='+searches+"&btn="+type);
		}

		if(searches.length >= 1){
			var KeyID = e.keyCode;
				if(KeyID == 13){
				window.location = "search.php?s="+searches+"&btn=mp3";
				}
		}
}
function search2(e,type)
{
	var searches = document.getElementById('text').value;
	var searches = searches.replace("&"," ");
	window.open("/forum/search.php?search_keywords="+searches+"&search_forum="+type);
		
		if(searches.length >= 1){
			var KeyID = e.keyCode;
				if(KeyID == 13){
				//window.location = "search.php?s="+searches+"&btn=mp3";
				}
		}
}
function check(id,text){
if(document.getElementById(id).value == ""){
alert(text);
return false;
}
}
function winopen(url,ad,wid,hei) 
{
	var tim = Math.floor(Math.random()*11);
	window.open(''+url+'/'+ad, tim,'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=no,width='+wid+',height='+hei+',left=100,top=50');
}

function remove(id,song)	{
if(confirm("Сигурни ли сте, че искате да изтриете "+song+" ?")){
window.location = "?f=delete&id="+id;
}
}

function addemo(newemo,sel,form) 
{
	if(sel == 0)
	{
		var emoid =  document.getElementById(form).value;
		emoid = document.getElementById(form).value += newemo; 
		document.getElementById(form).focus();
	}
	else if(sel == 1)
	{
		var doti = opener.document.getElementById(form).value;
		doti = opener.document.getElementById(form).value += newemo;
	}
}

var xmlHttp 
function GetXmlHttpObject() 
{ 
var xmlHttp=null; 

try 
{ 
// Firefox, Opera 8.0+, Safari 
xmlHttp=new XMLHttpRequest(); 
} 
catch (e) 
{ 
// Internet Explorer 
try 
{ 
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
} 
catch (e) 
{ 
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
} 
return xmlHttp; 
} 


function job(prom,adres,adres2,buton)
{ 
	if(buton)
	{
		var name = document.getElementById(prom).value; 
		if(prom == "chat_box" && name != "")
		{
			document.getElementById(buton).disabled = "disabled";
			document.getElementById(prom).value = "Чата е изпратен!";
		}
	}
	else
	{
		var name="";
	}

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{ 
		alert ("Browser does not support HTTP Request"); 
		return 
	} 

	var url=""+adres+""+adres2+""+name;
	if(!prom)
	{
		xmlHttp.onreadystatechange=stateChangedmail;
	}
	xmlHttp.open("GET",url,true); 
	xmlHttp.send(null); 
}
function stateChangedmail() { 

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 

document.getElementById("msg").innerHTML=xmlHttp.responseText 

} 

} 
function conf(id,text){
if(confirm(""+text)){
window.location = ""+id;
}
}

function faq(id){
	var faq = document.getElementById(id);
	if(faq.style.display == "block"){
		var faq2 = "none";
		document.getElementById('faq_h').title = "Отвори отговора";
	}else{
		var faq2 = "block";
		document.getElementById('faq_h').title = "Затвори отговора";
	}
	faq.style.display = faq2;
}

function addlink(id){
	var ida = document.getElementById(id);
	if(ida.style.display == "block"){
		var ida2 = "none";
	}else{
		var ida2 = "block";
	}
	ida.style.display = ida2;
}
function colors(set,tip,id)
{
	document.getElementById('color_div').style.display  = "inline";
	if(set == "colors")
	{
		var bar = document.getElementById('hido').value;
		document.getElementById(bar).value = tip
		document.getElementById(bar).style.background = "#"+tip;
		document.getElementById(bar).style.color = "#"+tip;
		document.getElementById('color_div').style.display  = "none";
	}
	else if(set == "close")
	{
		document.getElementById('color_div').style.display  = "none";
	}
	else
	{
		document.getElementById('hido').value = id;
	}
}
	function show_me(what,id,page)
	{
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		}
		if(what != "")
		{
			if(what == "add_comments")
			{
				var comments_area = (page == "") ? document.getElementById('comments_area').value : "";
				var addcomments = "&comments="+encodeURIComponent(comments_area);
				var send_to = 'showing';
			}
			else if(what == "add_chat")
			{
				var comments_area = (page == "") ? document.getElementById('chat_box').value : "";
				var addcomments = "&comments="+encodeURIComponent(comments_area);
				
				var send_to =  'showing2';
				document.getElementById('chat_box').value = "";
			}
			else if(what == "song_reiting")
			{
				var addcomments = "";
				var send_to =  'show_reiting';
			}
			else if(what == "show_chat")
			{
				var addcomments = "";
				var send_to =  'show_chat';
			}
			else if(what == "lchat")
			{
				var comments_area = (page == "send") ? document.getElementById('lchat_area').value : '';
				var g_user = document.getElementById('g_user').value;
				var addcomments = "&messages="+encodeURIComponent(comments_area)+"&u="+g_user;
				var send_to = 'lchat_results';
				if(page == "send")
				{
					document.getElementById('lchat_area').value = '';
				}
				document.getElementById('lchat_area').focus();		
			}
			else if(what == "poll")
			{
				var fds = page.split("|"); 
				for(i=1;i<=fds[0];i++)
				{
					var rch = document.getElementById('vot'+fds[i]);
					if(rch.checked == true)
					{
						var ind = id+"|"+fds[i];
					}
				}
				if(ind)
				{
					var id = ind;
				}
				else
				{
					alert('Изберете за кое ще гласувате!');
					return false;
				}
				var send_to =  'showpoll';
			}
			else if(what == "getTop")
			{
				var send_to =  'resultTop';
			}
			else if(what == "favorites")
			{
				var send_to =  'msg';
			}
			else if(what == "play")
			{
				var send_to =  'playPl';
			}
			else if(what == "text")
			{
				var send_to =  'showText';
			}
			else if(what == "profileMenu")
			{
				var send_to =  '';
			}
			else if(what == "search")
			{
				var send_to =  'search_more';
			}
			else if(what == "anns")
			{
				var send_to =  'annsi';
			}
			else if(what == "addfr")
			{
				var send_to =  'frRes';
			}
			else
			{
				var addcomments = "";
				var send_to = 'showing';
			}
			var url = 'show_me.php?what='+what+'&id='+id+'&page='+page+((addcomments) ? addcomments : '');
			xmlHttp.onreadystatechange =  function (){show_me2(send_to)};;
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)
		}
	}
	function show_me2(fshow) 
	{
		if(xmlHttp.readyState < 4 || xmlHttp.readyState != "complete") 
		{ 
			if(fshow != 'lchat_results')
			{
				document.getElementById(fshow).innerHTML= '<div id="ajax_loader">ЗАРЕЖДАНЕ...Моля изчакайте!</div>';
			}
		}		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(fshow).innerHTML=xmlHttp.responseText;
			if(fshow == 'lchat_results')
			{	
				setTimeout("show_me('lchat','lchat','')",5000);	
			}
		}
	} 
	function VandP()
	{
		var div1 = document.getElementById('div1');
		var div2 = document.getElementById('div2');
		if(div1.style.zIndex == 0)
		{
			div1.style.zIndex = 1;
			div2.style.zIndex = 0;
		}
		else
		{
			div1.style.zIndex = 0;
			div2.style.zIndex = 1;
		}
	}
	function setLanguage(lan)
	{
		if(lan == "en" || lan == "bg")
		{
			setCookie('lang', lan, 365);
			window.location.reload();
		}
	}
	function setCookie(name, value, expires, path, domain, secure) 
	{
		//expires in days
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expires);
		document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : "; expires=" + exdate.toUTCString()) +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		((secure == null) ? "" : "; secure");
	}
	function readCookie(name) 
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function ads(type)
	{
		var GD = new Date()
		var fDate = GD.getHours()+'/'+GD.getMinutes()+'/'+GD.getSeconds();
		if(window.innerWidth)
		{
			var Width = window.innerWidth;
		}
		else
		{
			var Width = document.body.clientWidth;
		}
		var ads = document.getElementById('ads_root');
		if(type == "bye")
		{
			ads.style.display = "none";
			setCookie('ADS',fDate);
		}
		else
		{
			ads.style.display = "inline";
			ads.style.left = (Width-750)/2+'px';
		}
	}
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('c 4(a){5(a=="6"){0.1(\'2\').3.7="-d";0.1(\'2\').3.8="e";9("4(\'b\')",f)}g 5(a=="b"){0.1(\'2\').3.7=\'h\';0.1(\'2\').3.8="i";9("4(\'6\')",j)}}',20,20,'document|getElementById|rek_h|style|ads2|if|tem|marginTop|height|setTimeout||bip|function|20px|21px|5000|else|0px|1px|5000'.split('|'),0,{}))
function titaa()
{
	document.getElementById('playSong').innerHTML = document.getElementById('playSong').innerHTML;
}

function PlaySondAndVideo()
{
	var pSv = document.getElementById('playSongVid').value;
	var SRC = document.getElementById('playSongSrc').src;
	var SRC2 = SRC.substr(0,(SRC.length-1));

	if(pSv == 0 ||pSv == "")
	{
		document.getElementById('playSong').innerHTML = '<iframe id="playSongSrc" src="'+SRC+'V" scrolling="no" width="450" frameborder="0" height="300"></iframe><input type="hidden" id="playSongVid" value="1" />';
		document.getElementById('wVid').innerHTML = "Без видео";
	}
	else
	{
		document.getElementById('playSong').innerHTML = '<iframe id="playSongSrc" src="'+SRC2+'" scrolling="no" width="450" frameborder="0" height="65"></iframe><input type="hidden" id="playSongVid" value="0" />';
		document.getElementById('wVid').innerHTML = "С видео";
	}
	
	setTimeout("titaa()",1);
	
	document.getElementById('wVid2').style.display = "inline";
}
