$(function(){
$('.ham').simpletip({showTime: 400, hideTime: 400,
   position: ["-15", 5]
}).simpletip().load('chameleon.php');
});


function checks(obj)
{
	return (document.getElementById ? document.getElementById(obj) : (document.all ? document.all[obj] : null));
}
function clean(obj, val)
{
	el = checks(obj);
	if (el.value == val) 
		el.value = "";
}
function rewrite(obj, val)
{
	el = checks(obj);
	if (el.value == "") 
		el.value = val;
}
function show_little(nam, more)
{
	el = checks(nam);
	el.innerHTML = "<a href='' onClick=\"show_more(" + nam + ", '" + more + "'); return false;\"><img src='img/more.png' border='0' alt=''></a>";
}
function show_more(id, more) 
{
	JsHttpRequest.query
	(
		'incNew.php', 
		{
			'id': id 
		},
		function(result, errors) 
		{
			var nam = result["id"];
			el = checks(nam);
			el.innerHTML = more + "<a href='' onClick=\"show_little(" + nam + ", '" + more + "'); return false;\"><img src='img/little.png' border='0' alt=''></a>";
		},
		false
	);
}
/***********************************
Archive
***********************************/
function doLoad(page, sel) 
{	
	if(sel == 1)
		mon = checks('arMonth').value;
	var req = new JsHttpRequest();
    req.onreadystatechange = function() 
	{
        if (req.readyState == 4) 
		{
            checks('archive').innerHTML = req.responseText;
			if(sel == 1)
				checks('arMonth').value = mon;
        }
    }
    req.open(null, 'calendar.php', true);
	if(sel == 1)
	{
		year = checks('arYear').value;
		req.send( { 'q': page, 'year': year, 'month': mon } );
	}
	else
	{
		req.send( { q: page } );
	}
}
function colorArchive(mode)
{	
	el1 = checks('archiveName');
	el1 = (el1.style ? el1.style : el1);
	el2 = checks('archive_click');
	el2 = (el2.style ? el2.style : el2);
	if(mode == 1)
	{	
		el1.color = "#9EC068";	
		el2.color = "#9EC068";
	}
	else
	{
		el1.color = "#E9003E";	
		el2.color = "#AFAFAF";
	}
}
function closeArchive()
{
	checks('archive').innerHTML = '';
}



/***********************************
Search
***********************************/
function doSearch(val) 
{
	JsHttpRequest.query
	(
		'search.php', 
		{
			'con': val 
		},
		function(result, errors) 
		{
			el = checks('results');
			el.innerHTML = "<a href='news.php?q=" + result["nQuery"] + "'>" + result["nQuantity"] + "</a>";
		},
		false
	);
}

/***********************************
Statisticks
***********************************/
function doStat(all) 
{
	day = checks('calenDay').value;
	mon = checks('calenMonth').value;
	ye = checks('calenYear').value;
	JsHttpRequest.query
	(
		'stat.php', 
		{
			'all': all, 
			'calenDay': day, 
			'calenMonth': mon, 
			'calenYear': ye 
		},
		function(result, errors) 
		{
			el = checks('statSongs');
			el.innerHTML = result["statSongs"];
			el = checks('statVisits');
			el.innerHTML = result["statVisits"];
			el = checks('statAll');
			el1 = checks('statAllFont');
			if(all == 0)	
			{
				el.innerHTML = 'вся';
				el1.innerHTML = 'или ';
			}
			else
			{
				el.innerHTML = '';
				el1.innerHTML = '';
			}
		},
		false
	);
}

function addStat(add, what)
{
	//add 1 || -1
	//what songs-1 visits-2  conc-3
	day = checks('calenDay').value;
	mon = checks('calenMonth').value;
	ye = checks('calenYear').value;
	JsHttpRequest.query
	(
		'add_stat.php', 
		{
			'add': add,
			'what': what,
			'calenDay': day, 
			'calenMonth': mon, 
			'calenYear': ye 
		},
		function(result, errors) 
		{
			el = checks('statSongs');
			el.innerHTML = result["statSongs"];
			el = checks('statVisits');
			el.innerHTML = result["statVisits"];
			el = checks('statConcerts');
			el.innerHTML = result["statConcerts"];
		},
		false
	);
}
/***********************************
PlayerAudio
***********************************/
function playerGo(action) 
{
	window.clearTimeout(time);
	id = checks('playerSongId').value;
	trueId = id;
	if(action == 'prev')
	{
		move = -1;
	}
	if(action == 'next')
	{
		move = 1;
	}
	
	JsHttpRequest.query
	(
		'player.php', 
		{
			'songId': id,
			'move': move
		},
		function(result, errors) 
		{
			el = checks('playerSongId');
			el.value = result["id"];
			nam = checks('fontName');
			nam.innerHTML = result["name"];
			obj = checks('playerMenu' + trueId);
			setOuterHTML(obj, '<span id="playerMenu' + result["id"] + '"></span>');
			var mPlayer = new SWFObject("javascript/playerMenu.swf", "menu" + result["id"], "41", "36", "7", "#000000");
			mPlayer.addVariable("autoPlay", "no");
			mPlayer.addVariable("soundPath", "albums_songs/" + result["file"]);
			mPlayer.write("playerMenu" + result["id"]);
			moveTitle(' *** Dato - ' + result["name"], 14);
		},
		false
	);
	
}
/***********************************
End PlayerAudio
***********************************/


function goToAllNews(other)
{
	location.href = "news.php?cat=all" + other;
}
function goToPage(other)
{
	location.href = other;
}
function setOuterHTML(element, toValue)
{
	if (typeof(element.outerHTML) != 'undefined')
		element.outerHTML = toValue;
	else
	{
		var range = document.createRange();
		range.setStartBefore(element);
		element.parentNode.replaceChild(range.createContextualFragment(toValue), element);
	}
}
function more()
{
	n = checks('quant');
	obj = checks('imgsMore');
	c = n.value * 1 + 1;
	n.value = c;
	setOuterHTML(obj, '<input type="file" name="image[]"><br><span id="imgsMore"></span>');
}
function moreSong(a)
{
	n = checks('quant');
	obj = checks('songsMore');
	c = n.value * 1 + 1;
	n.value = c;
	if(!a)
		setOuterHTML(obj, '<br><font>Песня #' + c + '</font><br><input type="text" id="' + c + '" name="name[]" value="название" onFocus="clean(\'' + c + '\', \'название\');" onBlur="rewrite(\'' + c + '\', \'название\');" size="72"><br><input type="file" name="song_' + c + '" size="60"><span id="songsMore"></span>');
	else if(a == 1)
		setOuterHTML(obj, '<br><font>Песня #' + c + '</font><br><input type="text" id="' + c + '" name="name[]" value="название песни" onFocus="clean(\'' + c + '\', \'название песни\');" onblur="rewrite(\'' + c + '\', \'название песни\');" size="72"><span id="songsMore"></span>');
}
function moreBonus()
{
	n = checks('quantBonus');
	obj = checks('bonusMore');
	c = n.value * 1 + 1;
	n.value = c;
	setOuterHTML(obj, '<br><font>Бонус #' + c + '</font><br><input type="text" id="' + c + 'B" name="nameB[]" value="название бонуса" onFocus="clean(\'' + c + '\', \'название бонуса\');" onblur="rewrite(\'' + c + 'B\', \'название бонуса\');" size="72"><span id="bonusMore"></span>');
}
/***********************************
MoveTitle
***********************************/
var time, startPos = 0, direct = 1;
function moveTitle(title, width)
{	
	el = checks('fontName');
	el.innerHTML = title.substring(0, width);
	title = title.substring(1, title.length) + title.substring(0, 1);
	time = window.setTimeout("moveTitle('" + title + "', " + width + ")", 193);
}
/***********************************
End MoveTitle
***********************************/


/***********************************
MenuPayer
***********************************/
function createMenuPlayer(pre, file)
{
	var mPlayer = new SWFObject("javascript/playerMenu.swf", "menu", "40", "24", "7", "#000000");
	mPlayer.addVariable("autoPlay", "no");
	mPlayer.addVariable("soundPath", "albums_songs/" + file);
	mPlayer.write("playerMenu" + pre);
}
/***********************************
End MenuPayer
***********************************/


/***********************************
Menu Color
***********************************/
function colorMenu(link)
{	
	checks(link + 'Left').innerHTML = '<img src="images/menuOverLeft.png" alt="" border="0">';
	checks(link + 'Right').innerHTML = '<img id="ima" src="images/menuOverRight.png" alt="" border="0">';
	checks(link + 'Up').innerHTML = '<div style="width:100%; overflow:hidden"><img src="images/menuOverUp2.png" alt="" border="0" width="100%" height="1"></div>';
}
function unColorMenu(link)
{	
	checks(link + 'Left').innerHTML = '';
	checks(link + 'Right').innerHTML = '';
	checks(link + 'Up').innerHTML = '';
}
/***********************************
End Menu Color
***********************************/



/***********************************
viewCham

function viewCham(link) 
{
	checks('cham').innerHTML = "идет загрузка...";
	//checks('cham').innerHTML = link;
	var req = new JsHttpRequest();
    req.onreadystatechange = function() 
	{
        if (req.readyState == 4) 
		{
            checks('cham').innerHTML = req.responseText;
        }
    }
    req.open(null, 'chameleon.php', true);
	req.send( { l: link } );
	//req.send( { l: 1 } );
}

End viewCham
***********************************/

function openpopup(popurl){
var winpops=window.open(popurl,"","width=320,height=215")}
