    var musopened = new Array();
	var sidetabopened = new Array();
	var fName = "";

	function music_tabs(item){
		var tabs = new Array(1,2,3,4,6,7,9);
    	for(i = 0; i < tabs.length; i++) {
			try{
	    		document.getElementById('ms'+tabs[i]).className = 'ds';
	    		document.getElementById('msc'+tabs[i]).style.display = 'none';
			}catch(e){
				alert(tabs[i] + ',' + i+'->'+e);
			}
    	}

    	if(item>1) {
			if (item!=6&&item!=9){
	    		document.getElementById('ms'+(item-1)).className = 'ds dsb';
			}else{
				if(item==6){
					document.getElementById('ms4').className = 'ds dsb';
				}else{
					document.getElementById('ms7').className = 'ds dsb';
				}
			}
    	}
    	document.getElementById('ms'+item).className = 'ds dsa';
    	document.getElementById('msc'+item).style.display = '';
 
		try{
			document.getElementById('bottomblocks').style.display='none';
		}catch(e){}
 
		try{
			document.getElementById('mgbook').style.display='none';
		}catch(e){}

    	if(!musopened[item]) {
    		switch(item) {
				case 1:
					try{
						document.getElementById('bottomblocks').style.display='block';
					}catch(e){}
					try{
						document.getElementById('mgbook').style.display='block';
					}catch(e){}
				break;
    			case 2:
    				rq('/music/rq/music_news.php?mid='+ musid, 'msc2');
    			break;
    			case 4:
					rq('/music/rq/music_gal.php?mid='+ musid, 'msc4');
    			break;
    			case 5:
    				//
    			break;
    			case 6:
    				rq('/music/rq/music_forum.php?mid='+musid, 'msc6');
    			break;
				case 7:
					rq('/music/rq/music_fans.php?mid='+ musid, 'msc7');
				break;
				case 9:
					rq('/music/rq/music_albums.php?mid='+ musid, 'msc9');
				break;
    		}
    	}else{
			switch (item){
				case 1:
					try{
						document.getElementById('bottomblocks').style.display='block';
						document.getElementById('mgbook').style.display='block';
					}catch(e){
						//
					}
				break;
				case 2:
	                newslist();
				break;
			}
    	}
    	musopened[item] = 1;

    }

    function readnews(mid, nid){
        rq('/music/rq/music_news.php?mid=' + mid + '&readnews=' + nid, 'msc2');
    }

    function newslist(){
        rq('/music/rq/music_news.php?mid=' + musid, 'msc2');
    }

	function songlist(){
		rq('/music/rq/music.php?mid='+ musid, 'msc9');
	}

    function nc(nid, pg){
        rq('/music/rq/music_news.php?mid='+ musid+'&readnews=' + nid + '&pg=' + pg, 'msc2');
    }

	function viewAlbum(aid){
		rq('/music/rq/music_albums.php?mid='+musid+'&aid='+aid, 'msc9', true);
	}

	function viewAlbumList(){
		rq('/music/rq/music_albums.php?mid='+musid, 'msc9');
	}

    function addAlbum(song_add){
		albWnd = window.open("/music/addalbum.php?mid="+musid+"&song_add="+song_add, "", 'resizable=yes,width=600, height=380');
	}

	function editAlbum(aid){
		albWnd = window.open("/music/addalbum.php?mid="+musid+"&aid="+aid, "", 'resizable=yes,width=600, height=380');
	}



	function editSong(aid, sid){
		songWnd = window.open("/music/addmusic.php?aid="+aid+"&mid="+musid+"&sid="+sid, "", 'resizable=yes,width=600,height=600');
	}

	function addSongDzsv(dzid){
		songWnd = window.open("/music/addmusic.php?dzid="+dzid+"&mid="+musid, "", 'resizable=yes,width=600,height=600');
	}
		function addSong(aid){
		songWnd = window.open("/music/addmusic.php?mid="+musid+"&aid="+musid, "", 'resizable=yes,width=600,height=600');
	}
	
    function setAlbumNameId(alid, alname){
		albid = alid;
		albtitle = alname;
	}

	function postAlbumForm(){
		var frm=document.getElementById('frmAlbumData');
		frm.target="albumDataFrame";
		frm.action="/music/music_album_handler.php";
		frm.submit();
		frm.style.display='none';
		document.getElementById('frmSavedInfoBox').style.display='block';
	}

	function postAlbumIMG(aid){
		var frmm=document.getElementById('frmAlbumImage');
		document.getElementById('sbmtbtn').style.display='none';
		if (document.getElementById('frmFile').value != ''){
			frmm.target='albumIMGFrame';
			frmm.action='http://upl.draugiem.lv/music/album.php';
			document.getElementById('album_id').value = aid;
			frmm.submit();
			frmm.style.display='none';
		}else{
			frmm.style.display='none';
       		document.getElementById('frmSavedInfoBox').innerHTML=albumSavedWaitForClose;
			window.setTimeout(window.close, 10000);
		}
	}

	function postMusicForm(edit){
		var frm=document.getElementById('frmMusicData');
		if (!edit){
			fName=document.getElementById('frmSongFile').value;
		}
		frm.target='musicDataFrame';
		frm.action='/music/music_handler.php?edit='+edit;
		frm.submit();
	}

	function postUploadForm(sid,dzid){
		dz = '';
		if(dzid) dz = dzid;
	    var frmm=document.getElementById('frmSong');
		frmm.target='musicSongFrame';
		frmm.action=MP3_UPL+'upload.php?dzid='+dz;
		document.getElementById('frmSongId').value=sid;
		document.getElementById('frmDataTable').style.display='none';
		document.getElementById('idDataSaved').style.display='block';
		frmm.submit();
//	   	window.setTimeout('updateProgress();',1000);
	}

	function updateProgress(){
		document.getElementById('frmSong').style.display = 'none';
		document.getElementById('idFileUploadedSong').style.display = 'block';
		$.get('/music/progress.php?u='+sid+'&f='+escape(fName)+'&r='+Math.floor(Math.random() * 100000000), {}, function(data){
			if (data != 'UPLOAD completed!'){
				$('#idFileUploadedSong').html(data);
				window.setTimeout("window.updateProgress();", 1000);
			}else{
				document.getElementById('idFileUploadedSong').style.display='none';
				window.close();
			}
		});
	}

	function fileuploaded(txt){
	    document.getElementById('idDataSaved').style.display = "block";
		document.getElementById('idDataSaved').innerHTML = txt;
		document.getElementById('idFileUploadedSong').style.display='none';
	}

	function albumImageUploadDone(val){
		document.getElementById('frmSavedInfoBox').innerHTML=val;
		window.setTimeout(window.close, 10000);
	}

	function addMusic(){
		if (document.getElementById('songaid').value != -1){
			if (document.getElementById('frmSongTitle').value.length > 0){
				postMusicForm(0);
			    var frm=document.getElementById('frmMusicData');
			}else{
				alert(songNameRequired);
			}
		}else{
			alert(chooseAlbum);
		}
	}

	function editMusic(){
		postMusicForm(1);
	}

	function mfcPage(mid, tid, pg){
		rq('/music/rq/music_forum.php?mid=' + mid + '&tid=' + tid + '&pg=' + pg, 'msc6');
	}

	function mfPage(mid, pg){
		rq('/music/rq/music_forum.php?mid=' + mid + '&pg=' + pg, 'msc6');
	}

    function displayLyrics(mid, sid){
		songWnd = window.open("/music/lyrics.php?mid="+mid+"&sid="+sid, "", 'scrollbars=yes,resizable=yes,width=600,height=600');
	}

	function checkLengths(isComment){
		if (!isComment){
			if (document.getElementById("frmTopicTitle").value.length < 2 || document.getElementById('frmTopicText').value.length < 2){
				alert(topic_text_too_short);
				return false;
			}
			return true;
		}else{
			if (document.getElementById("frmReplyText").value.length < 2){
				alert(reply_text_too_short);
				return false;
			}
			return true;
		}
	}

	function selAll(item){
		bl = document.getElementById('msglist');
		var lst = bl.getElementsByTagName('input');
		for (var i = 0; i < lst.length; i++){
			if (lst[i].type=='checkbox' && lst[i].name != 'selector'){
				lst[i].checked = item.checked;
			}
		}
	}

	function playSong(mid, aid, sid){
		playerWnd('/music/music_popup.php?mid='+mid+'&aid='+aid+'&sid='+sid);
	}

	function playAlbum(mid, aid){
		playerWnd('/music/music_popup.php?mid='+mid+'&aid='+aid+'&sid=0');
	}

	function playTop(lng){
		playerWnd('/music/music_popup.php?pid=1&l='+lng);
	}

	function playGenre(genre){
		playerWnd('/music/music_popup.php?pid=2&kw='+genre);
	}

function addMusicAlb(mid){
	window.open('/music/gal/newalb.php?'+mid,'alb','width=400,height=200,scrollbars=1,status=0');
}


function addMusicPic(mid,aid){
	window.open('/music/gal/newpic.php?'+mid+'&aid='+aid,'pic','width=650,height=570,scrollbars=1,status=0');
}

function addMusicVideo(mid,aid){
	window.open('/music/gal/newvideo.php?'+mid+'&aid='+aid,'pic','width=500,height=450,scrollbars=1,status=0');
}

function downloadSong(snid, fn, hs){
	window.location.href = MP3_UPL + 'download.php?mid='+musid+'&f='+snid+'&fn='+ fn +'&hs='+ hs +'&u=' + uid;
}

function checkLength(el, len, msgel){
	if (el.value.length >= len){
		document.getElementById(msgel).innerHTML=charsLeft + '0';
		el.value = el.value.substring(0,len);
	}else{
		document.getElementById(msgel).innerHTML=charsLeft + (len - el.value.length);
	}
}

function textarea_min_len(id, len, error){
	if (document.getElementById(id).value.length < len){
		alert(error)
		return false;
	}
	return true;
}

function gkw(kw, id){
	window.location.href="/music/?selectedTab=3&keyw="+kw;
}

function music_gbook(mid, pg){
	rq('/music/rq/music_guestbook.php?mid='+mid+'&pg='+pg, 'gbookcontent');
}

function togleGenres(id){
	if (document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
	}else{
		document.getElementById(id).style.display = "none";
	}
}

function submitArticleForm () {
	document.getElementById('articleCreateForm').submit();
}



function triggerUplMessage (classn,msg) {
	$('#responseMsg').html(msg);
	$('#responseMsg').removeClass();
	$('#responseMsg').addClass(classn);
	$('#responseMsg').css('display','block');
}

function setArticlesComments (oid,pg,t,d) {
	$.ajax({
		url:"/music/includes/comments.php?oid="+oid+"&pg="+pg+"&d="+d+"&t="+t,
		success: function(txt){$('#articleComments').html(txt);},
		error:function(txt){$('#articleComments').append("<strong>kluda "+txt+"</strong>");}
	}); 	
}

function selectMainGenre (nr, genreid, sel) { 
	$.ajax({
		beforeSend: function () { $('#subGenre'+nr).html('<img src="/img/load.gif" alt="" />') },
		url:"/music/create/get.php?task=get_genres&nr="+nr+"&gid="+genreid+'&sel='+sel,
		success: function(txt){$('#subGenre'+nr).html(txt);},
		error:function(txt){$('#subGenre'+nr).append("<strong>kluda "+txt+"</strong>");}
	}); 
}

	function setSearchType (t) {
	if (t == 1) {
		$('#genreSearch').css('display','inline');
		$('#defSearch').css('display','none');
		document.getElementById('searchField').value='';
	} else {
		$('#genreSearch').css('display','none');
		$('#defSearch').css('display','inline');
		document.getElementById('mgenre').selectedIndex=0;
		selectMainGenre(0,0);
	}
}

var mus_hov_set=false;

function setMusHover () {
	if (!mus_hov_set) {
	$(".smallMusList li a").hover(function(){
	  $(this).animate({ opacity:0.3}, 200);
	}, function(){
	  $(this).animate({ opacity: 1 }, 200);
	}); 
	mus_hov_set=true;
	}
}

var X = 0;
var Y = 0;
var selectedIndex = 0;

$(document).bind('mousemove',function (e){
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		X = e.pageX;
		Y = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		X = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		Y = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
	}
	
});

  function setVoteForm() {
	var newPosX = (X+20)+'px';
	var newPosY = (Y-10)+'px';
	
		var ob = document.getElementById('voteFormWrapper');
		
		if (ob) {
			ob.style.left = newPosX;
			ob.style.top = newPosY;
		} else {
			var wrapper = document.createElement('div');
			wrapper.id = 'voteFormWrapper';
			wrapper.style.left = newPosX;
			wrapper.style.top = newPosY;
			var btn = document.createElement('input');
			btn.setAttribute('type','button');
			btn.onclick = function () { document.getElementById('voteForm').submit();};
			btn.setAttribute('name','vt');
			btn.setAttribute('value',vote_string);
			btn.className = 'bt ok';
		
			wrapper.appendChild (btn); 
			document.body.appendChild(wrapper);
		}
	}
	
	function setMusArticle (index) {
	if (index != selectedIndex) {
		$('#newsitem'+index).animate({
			left:0
		},400);
		
		$('#newsitem'+selectedIndex).animate({
			left:-455
		},400);
		
		$('#firstpageArticle ul li').removeClass();
		$('#firstpageArticle ul li#li_h_'+index).addClass('selected');
		
		selectedIndex = index;
	}
}

function setTab (tab) {
	$('#topTabsContent div.tab').css('display','none');
	$('#topTabsContent #'+tab).css('display','block');
}

function setMusFansPage (pg,m) { 
	$.ajax({
		url:"/music/artist/get.php?task=fans&id="+m+"&pg="+pg,
		success: function(txt){$('#fansInner').html(txt);},
		error:function(txt){$('#fansInner').append("<strong>kluda "+txt+"</strong>");}
	}); 	
}

function setGBFansPage (pg,m) { 
	$.ajax({
		url:"/music/artist/get.php?task=gb&id="+m+"&pg="+pg,
		success: function(txt){$('#gbInner').html(txt);},
		error:function(txt){$('#gbInner').append("<strong>kluda "+txt+"</strong>");}
	}); 	
}

function deleteGBRecord(id, musid, p) {
	$.ajax({
		url:"/music/artist/get.php?task=delgb&id="+musid+"&itemid="+id,
		success: function(){ setGBFansPage(p,musid);},
		error:function(txt){$('#gbInner').append("<strong>kluda "+txt+"</strong>");}
	});
} 

function setMusicianPage(musid, page, params) {
	var container = 'musLeftCol'; 
	
	$.ajax({
		url:"/music/artist/get.php?task=get_content&id="+musid+"&page="+page+'&'+params,
		beforeSend: function () { $('#'+container).html('<img src="http://ifrype.com/img/load.gif" alt="" />') },
		success: function(txt){ $('#'+container).html(txt); },
		error:function(txt){$('#gbInner').append("<strong>kluda "+txt+"</strong>");} 
	});

}


function popUp(URL,w,h,scrollbars,resize) {
	var day = new Date();
	var id = day.getTime();
	var sc = scrollbars ? 1 : 0;
	var rs = resize ? 1 : 0;
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	return eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars="+sc+",location=0,statusbar=0,menubar=0,resizable="+rs+",width="+w+",height="+h+",top="+mytop+",left="+myleft+"')");
}


function openPlayer (mids, genreid, trackid, albumid) { 
	popUp ('/music/player/window.php?mids='+mids+'&genreid='+genreid+'&sid='+trackid+'&aid='+albumid,260, 400, false, false);
}

function alterMusItems (id, checked) {
		if (checked) {
			selMids.push(id);
		} else { 
			for (i=0;i<selMids.length;i++) {
				if (selMids[i] == id) {
					selMids.splice(i,1);
				}
			}
		}
	} 
	
function setMyMusicPg(page) {
	var selmids = selMids.join(',');
	$.ajax({
		url:"/music/artist/get.php?task=getmymus&pg="+page+'&selmids='+selmids,
		success: function(txt){$('#myMusiciansList').html(txt);},
		error:function(txt){$('#myMusiciansList').append("<strong>kluda "+txt+"</strong>");}
	}); 		
}

function setMyPlayer(page, params) {
	$.ajax({
		url:"/music/artist/get.php?task=getmyplayer&pg="+page+'&'+params,
		success: function(txt){$('#myPlayer').html(txt);},
		error:function(txt){$('#myPlayer').append("<strong>kluda "+txt+"</strong>");}
	}); 		
}

function setMyMusicians(page) {
	$.ajax({
		url:"/music/artist/get.php?task=getmymusicians&pg="+page,
		success: function(txt){$('#myMusiciansList').html(txt);},
		error:function(txt){$('#myMusiciansList').append("<strong>kluda "+txt+"</strong>");}
	}); 		
}
