var thisUserAgent = window.navigator.userAgent;
if (/MSIE (5\.5|6).+Win/.test(thisUserAgent)) thisUserAgent = 'IE6';
if (/MSIE (7).+Win/.test(thisUserAgent) || /MSIE (8).+Win/.test(thisUserAgent)) thisUserAgent = 'IE7';
if (/Safari/.exec(thisUserAgent)) thisUserAgent = 'Safari';

var brick, brickLiWidth, CCount;



$(document).ready(function(){ 
	if (document.getElementById('user-corner') && thisUserAgent != 'IE6') userblock_fixed()
})

window.onscroll = function () {
	if (document.getElementById('user-corner') && thisUserAgent != 'IE6') userblock_fixed()
}

window.onresize = function() {
	//if (thisUserAgent != 'IE6') {
	if (document.getElementById('outline')) {
		winWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
		winWidth = 727 ;// ((winWidth - 295*2) < 420) ? 420 : (winWidth - 295*2);
		CCount = 6;//Math.floor(winWidth/brickLiWidth);
		visibleCoverCount = CCount*3;
		VisibleCover();
		initBrickSize(brick, CCount, brickLiWidth) //#outline
	}
}


function showflash(id,url){
document.getElementById(id).innerHTML=''+
//'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="15" height="15"><param name="movie" value="/images/prehear.swf"><param name="flashvars" value="source_mp3='+url+'&splay=on"><param name="quality" value="high"><param name="menu" value="false"><param name="scale" value="noscale"><param name="salign" value="TC"><param name="wmode" value="transparent">'+
'<EMBED src="/images/prehear.swf" flashvars="source_mp3='+url+'&splay=on" width="15" height="15" wmode="transparent" menu="false" quality="high" scale="noscale" salign="TC" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
'</EMBED></OBJECT>';
}


function show_help () {
	window.open ('/help.html', 'soundkeyHelp', 'left=50, top=50, height=470, width=700, resizable=0, scrollbars=0, status=0, menubar=0');
}

function presentation () {
	window.open ('/presentation.html', 'soundkeyPr', 'left=50, top=50, height=675, width=900, toolbar=0, menubar=0, scrollbars=0');
}



function open_softkey (email, username, userid) {
	var url = 'http://www.softkey.ru/catalog/externalorder.php?oid=' + document.credit_form.oid.value + '&amp;q=1&amp;pt=F&amp;email=' + email + '&amp;contact_person=' + username + '&amp;phone=' + document.credit_form.phone.value + '&amp;ps=' + document.credit_form.ps.value + '&amp;location_id=48&amp;site=9806&amp;compid=364297&amp;ad1=' + userid;
	var div = document.getElementById('moneystuff');
	div.innerHTML = '<iframe src="' + url + '" width="100%" height="600" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" />';
	document.getElementById('recomend').parentNode.style.display = 'none';
	
}

function validphone() {
	var ip_error = document.getElementById('ip_error');
	var phone_error = document.getElementById('phone_error');
	
	ip_error.innerHTML = phone_error.innerHTML = '';
	
	if (document.alternatecredit.ip.value != '') {
		document.getElementById('ip_error').innerHTML = '';
		if (document.getElementById('phone').value != '') {
				if (!document.getElementById('phone').value.match(/[^0-9\(\)\-\+\ ]+/)) 
					//open_softkey (email, username, userid);
					return true;
				else phone_error.innerHTML = 'недопустимые символы'; return false
			}
		else  phone_error.innerHTML = 'поле не заполнено'; return false
	}
	else  ip_error.innerHTML = 'поле не заполнено'; return false
}


function credit () {
	var ip = document.alternatecredit.ip; //деньги
	var ps = document.alternatecredit.ps; //способ оплаты
	var ps_option = ps.getElementsByTagName('option');
	predel = 12;
	
		if (ip.value && ip.value < 100) {
			for (var i = predel; i < ps_option.length; i++) {
				ps_option[i].selected = false; // safari
				ps_option[i].disabled = true;
			}
			ps_option[0].selected = true;
			ps.onchange = function (event) {credit_ie(ps_option, predel)};
		}
		else {
			for (var i = predel; i < ps_option.length; i++) 
				ps_option[i].disabled = false;
				ps.onchange = '';
		}
}



function credit_ie (el_option, predel) {
	for (var i = predel; i < el_option.length; i++) {
		if (el_option[i].selected == true) {
			alert('Минимальная сумма платежа для данного способа оплаты - 100 руб.')
			el_option[0].selected = true;
		}
	}
}


function ie6fix (b) {
	if (thisUserAgent == 'IE6') {
		return b;
	}
}



function preview (el) {
	var cols = document.getElementsByTagName ('td');
	var object_onclick = "this.title = this.title == 'остановить' ? 'проиграть' : 'остановить'";
	for (var i = 0; i < cols.length; i++) {
		if (cols[i].className == 'preview') {
			cols[i].innerHTML = '<a href=" " title="проиграть" onclick="return false"></a>';
			cols[i].onclick = function (event) { preview (this) };
		}
	}
	el.onclick = '';
	el.innerHTML = ''+
	'<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="22" height="22" title="остановить" onclick="' + object_onclick + '"><PARAM NAME=movie VALUE="/images/preview.swf"><PARAM NAME=flashvars value="source_mp3='+el.id+'&splay=on&button_color=0xc20000"><PARAM NAME=quality VALUE=high><PARAM NAME=menu VALUE=false><PARAM NAME=scale VALUE=noscale><PARAM NAME=salign VALUE=TC><PARAM name=wmode value=transparent>'+
	'<EMBED src="/images/preview.swf" flashvars="source_mp3='+el.id+'&splay=on&button_color=0xc20000" width="22" height="22" wmode="transparent" menu=false quality=high scale=noscale salign=TC swLiveConnect=true TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
	'</EMBED></OBJECT>';
}



function select_all (element) {
	var inputs = document.getElementById('album').getElementsByTagName ('input');
	for (var i = 0; i < inputs.length; i++)
		if(inputs[i].type == 'checkbox' &&  inputs[i].disabled == false) inputs[i].checked = element.checked;
}


function track_info (el, track_id) {
	var req = false;
	var info = document.createElement ('div');
	info.className = 'trackinfo';
	info.innerHTML = '<img src="/images/user-loading.gif"/>';
	el.parentNode.appendChild (info);
	el.onclick = function (event) { remove_track_info (this, track_id); return false}
	el.title = 'Скрыть информацию о треке';

	if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) req.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (req) {
		req.onreadystatechange = function() { if (req.readyState == 4) if (req.status == 200) {
			info.innerHTML = req.responseText;
			if (thisUserAgent = 'IE6') {
				document.getElementsByTagName('body')[0].style.marginBottom = '1px'; //footer
				document.getElementsByTagName('body')[0].style.marginBottom = '0px';
			}
		}
	}
		req.open('GET', '/track/info/' + track_id + '/', true);
		req.send(null);
	}
	

}


function remove_track_info (el, track_id) {
	$(el.parentNode).find('div').remove()
	el.onclick = function (event) { track_info (this, track_id); }
	el.title = 'Показать информацию о треке';
}



function flv_video (data, img, rtime, band, label) {
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="380" id="videoplayer" align="middle">',
'<param name="allowScriptAccess" value="sameDomain" />',
'<param name="allowFullScreen" value="false" />',
'<param name="movie" value="/video/v-player.swf" />',
'<param name="quality" value="high" />',
'<param name="wmode" value="transparent" />',
'<param name="bgcolor" value="#ffffff" />',
'<param name="flashvars" value="data=', data, '&img=', img, '&settings=/video/settings.xml&rtime=' + rtime + '&begun=http://www.soundkey.ru/data/begun/&band=' + band + '&label=' + label + '"/>',
'<embed src="/video/v-player.swf" flashvars="data=', data, '&img=', img, '&settings=/video/settings.xml&rtime=' + rtime + '&begun=http://www.soundkey.ru/data/begun/&band=' + band + '&label=' + label + '" quality="high" wmode="transparent" width="400" height="380" name="videoplayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />',
'</object>');
}



function view_albums (div, urls, start, c, loadimage, notBrick) {
	var div_in = document.getElementById('nt_'+div+'s');
	var div_hid = document.getElementById('hid-'+div);
	var loading_name = 'loading';
	var loading = document.getElementById(loading_name);
	loadimage = loadimage ? loadimage : '';
	start = loadimage == '' ? start : start + c;
	
	
/*	if (loadimage == '' && div != 'band') {
		//$(div_in).animate({opacity:0.3}, 100);
		view_albums (div, urls, start, c, '&short=yes');
	}*/

	var req = false;
	if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) req.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
		
		if (req) {
		req.onreadystatechange = function() {
			if (req.readyState !== 4 && loadimage == '') loading.style.visibility = 'visible';
			if (req.readyState == 4) if (req.status == 200) {
				if (loadimage == '') {
					div_hid.innerHTML = req.responseText;
					if ((/latest/.test(div)) || (/popular/.test(div))) VisibleCover();
					div_in.innerHTML = div_hid.innerHTML;
					if (loadimage == '') loading.style.visibility = 'hidden';
					//if (div != 'band') $(div_in).animate({opacity:1}, 100, "easein");
					}
				else div_hid.innerHTML = req.responseText;
		 	}
		}
			req.open('GET', urls + 'start=' + start + loadimage, true);
			req.send(null);
		}
}


function view_user (back_url) {
	var req = false;
	var userblock = document.getElementById('userblock');
	var get_url = '/account/userblock/?back='+ back_url;
	userblock.className = '';
	userblock.innerHTML = '<img src="/images/user-loading.gif"/>';
	if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) req.overrideMimeType('application/xml'); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
			if (req.status == 200) {
					userblock.innerHTML = req.responseText;
					var userXML = req.responseXML.documentElement;
					varUserDiscount(userXML);
				}
				else {userblock.innerHTML = 'Не удалось получить данные'; userblock.className = 'error'}
			}
		 }
		req.open('GET', get_url, true);
		req.send(null);
	}
}

function view_mainblock (get_url) {
	var req = false;
	var userblock = document.getElementById('mainblock');
	userblock.className = '';
	userblock.innerHTML = '<img src="/images/user-loading.gif"/>';
	if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) req.overrideMimeType('text/html'); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
			if (req.status == 200) userblock.innerHTML = req.responseText;
				//user_status = document.getElementById('userblock').firstChild.tagName == 'FORM' ? 'none' : 'yes';}
				else {userblock.innerHTML = 'Не удалось получить данные'; userblock.className = 'error'}
			}
		 }
		req.open('GET', get_url, true);
		req.send(null);
	}
}


function varUserDiscount (userXML) {
	window.userDiscount = userXML.getElementsByTagName('span')[0] ? userXML.getElementsByTagName('span')[0].childNodes[0].nodeValue : 1;
	window.userDiscount = window.userDiscount > 1 ? 1 - (window.userDiscount / 100) : 1;
}

function album_discount (track, album_price) {
	var buy = album_input();
	var setUserDiscount;
	if ( buy == 0) document.album_form.buytrack.disabled = true;
	
	if (isNaN(window.userDiscount)) {
		setUserDiscount = 1;
		window.setTimeout('setLjDiscount(0, "'+track+'", "'+album_price+'")', 2000);
	}
	else {
		setUserDiscount = window.userDiscount
	}
	
	summ(track, album_price, '', setUserDiscount)
	summ_discount (setUserDiscount);
}

function setLjDiscount (countInterval, track, album_price) {
  if (isNaN(window.userDiscount) && countInterval < 10) window.setTimeout('setLjDiscount(' + ++countInterval + ', "'+track+'", "'+album_price+'")', 2000);
  if (window.userDiscount < 1) {
  	summ(track, album_price, '', window.userDiscount)
		summ_discount (window.userDiscount);
  }
}


function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}



function fsale(el) {
	var a = $("#fsale_help").offset({ scroll: false });
	alert(a);
	//$("div#fsale_help").OpenVertically('normal');

}


function WinResize(w_name) {
					if (w_name == "cover") {
						i = document.getElementById("cover-full");
						ww = i.width+55
						hh = i.height+115
						p = document.getElementById('cover_title').offsetHeight;
						if (ww < 300) ww = 300;
						if (ww > 900) ww = 900;
						if (p > 30) hh = hh + p;
						if (hh > 715) hh = 715;
						window.resizeTo(ww,hh);
					}
				}
				

function video_size (img_url) {
	var img_out = newImage(img_url);
	document.write (Math.round(img_out.width * 1.6) + 'x' + Math.round(img_out.height * 1.6));
}


function newImage(arg)
{
   rslt = new Image();
   rslt.src = arg;
   return rslt;
}

function safari_search() {
	var form = document.forms.search;
		if (thisUserAgent == 'Safari') {
			form.query.setAttribute ('type', 'search');
			form.query.setAttribute ('results', '10');
			form.query.setAttribute ('autosave', 'www.mp3maxi.ru');
			form.query.setAttribute ('placeholder', 'Найти');
			form.getElementsByTagName('input')[1].style.width = '100%';
			form.getElementsByTagName('input')[2].style.display = 'none';
		}
		form.query.focus();
}




function discover(e) {
	var active = (e.parentNode.className == 'active') ? 1 : 0;
	var el_li = e.parentNode.parentNode.getElementsByTagName('li');
	for (var i = 0; i < el_li.length; i++) if (el_li[i].className != 'nostyle') el_li[i].className = '';
	if(active == 1) {e.parentNode.className == ''}
	else {e.parentNode.className = 'active'}
}


function enable_form (track, el) {
var checks = document.getElementsByTagName('input');
	var buy = 0;
	var album = document.getElementById('album');
	for (var i = 0; i < checks.length; i++)
		if (checks[i].className == 'buy' && checks[i].checked) buy++;
		if (buy > 0) {
			if (track==buy) {
				album.action = '';
				window.location="/account/basket/?buy_album=" + el;
				return false;
			}
			else {
				album.action = '/account/basket/';
				album.submit();
			}
		}
		else {
			album.action = '';
			return false;
			}
}


function summ (track, album_price, album, discount) {
var checks = document.getElementsByTagName('input');
var out = document.getElementById('track_summ');
var buy = 0;
var count = 0;
	for (var i = 0; i < checks.length; i++) {
		if (checks[i].className == 'buy') {
			var tr = checks[i].parentNode.parentNode;
			if (checks[i].checked || checks[i].type == 'hidden') {
				count++;
				buy += checks[i].id * 1;
				tr.className = 'sum';
			}
			else tr.className = '';
		}
	}
	buy = count==track ? album_price : buy;
	discount = discount > 0 ? discount : 1;
	buy = buy * discount;
	out.innerHTML = Math.round(buy) != buy ? buy.toFixed(2) : buy;
	if (document.album_form && document.album_form.buytrack) document.album_form.buytrack.disabled = (count > 0) ? false : true;
}

function summ_discount (discount) {
	var out = document.getElementById('track_summ').parentNode.parentNode;
	var a = document.createElement('a');
	if (discount > 0 && discount < 1) {
		a.href = '/account/settings/';
		a.innerHTML = 'с учетом вашей скидки ' + (100 - discount * 100) + '%';
	}
	else {
		a.href = '/discounts/';
		a.innerHTML = 'скидки блоггерам';
	}
		var p = document.createElement('p');
		p.className = 'discountText';
		p.appendChild(a);
		out.appendChild(p);
}


function cart_del (element, id, button) {
	var tr = button.parentNode.parentNode;
	var del_input = tr.getElementsByTagName('input')[0];

	del_el_cookie (element, id);

	del_input.value = '';
	del_input.id = '';
	tr.className = tr.className == 'even' ? 'even del' : 'del';
	button.onclick = '';
	
	if (document.basket.save && album_input() == 0) document.basket.save.disabled = true;
}


function enable (track, el) {
		var buy = album_input ();
		if (buy > 0) {
			if (track==buy) 
				cart('album', el);
			else {
				var checks = document.getElementsByTagName('input');
				for (var i = 0; i < checks.length; i++)
				if (checks[i].className == 'buy' && checks[i].checked) cart('track', checks[i].value);
			}
		}
		else {document.album_form.buytrack.disabled = true;}
}

function album_input() {
	var checks = document.getElementsByTagName('input');
	var buy = 0;
	for (var i = 0; i < checks.length; i++)
		if (checks[i].className == 'buy' && (checks[i].checked || (checks[i].type == 'hidden' && checks[i].id != ''))) buy++;
	return buy;
}


function cart_album (el) {
	cart('album', el) //old, for top player
}

function cart_track (el) {
	cart('track', el) //old, for top player
}



function cookie_array() {
 cookie_tracks = getCookie('cart_tracks')!= null ? getCookie('cart_tracks').split(',') : [];
 cookie_albums = getCookie('cart_albums') != null ? getCookie('cart_albums').split(',') : [];
}

function cart (el, elId) {
	cookie_array();
	
	var cookieVar = el=='track' ? cookie_tracks : cookie_albums;
	var cookieName = 'cart_' + el + 's';
	var trackSumm = 0;
		if (cookieVar == '') {
			cookieVar[0] = elId;
			setCookie(cookieName, cookieVar, 30, '/')
			}
		else {
			for (var s=0; s<cookieVar.length; s++) 
					if(cookieVar[s] == elId) trackSumm = ++trackSumm;
			if (trackSumm == 0)
					addToCart(cookieVar, cookieName, elId)
		}
	window.location='/account/basket/';
}

function addToCart(cookieVar, cookieName, elId) {
	cookieVar[cookieVar.length] = elId;
	setCookie(cookieName, cookieVar, 30, '/')
}


function check_basket(el) {
		var cookieVar = el=='buy' ? cookie_tracks : cookie_albums;
		var classElement = el == 'buy' ? 'input.' + el : 'a.' + El
			$(classElement).filter (	
				function (pos){
					for (var i = 0, j = cookieVar.length; i < j; i++) {
						if (cookieVar[i] == this.value) {
							return this.checked = 'checked';
					}
				}
    	}
		)
	}
	
function cart_del (element, id, button) {
	var tr = button.parentNode.parentNode;
	var del_input = tr.getElementsByTagName('input')[0];

	del_el_cookie (element, id);

	del_input.value = '';
	del_input.id = '';
	tr.style.display = 'none';
	
	if (document.basket.save && album_input() == 0) document.basket.save.disabled = true;
}

function track_reload () {
	var checks = document.getElementsByTagName('input');

	for (var i = 0; i < checks.length; i++) {
			if (checks[i].name == 'buy_track' && checks[i].checked == false) {
				del_el_cookie ('track', checks[i].value)
			}
			if (checks[i].name == 'buy_album' && checks[i].checked == false) {
				del_el_cookie ('album', checks[i].value)
			}
		}
	window.location='/account/basket/';

}

function del_el_cookie (element, id) {
	var cookieVar = element=='track' ? cookie_tracks : cookie_albums;
	var cookieName = 'cart_' + element + 's';
	
	for (var s=0; s<cookieVar.length; s++) {
		if(cookieVar[s] == id) cookieVar.splice(s, 1);
	}
	setCookie(cookieName, cookieVar, 30, '/')
}


function validate_search (el) {
	src = el.query.value;
	if (src.length == 0) return false;
	/*if (src.length == 1) {
		window.location = "/search/?letter=" + encodeURI(src);
		return false;
		}*/
	if (src.length > 2) return true;
	else return false;
}

function help_drm () {
	var winWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	left = (winWidth - 515) / 2 - 20;
	var newWin = window.open('/help_drm.html','drm','left=' + left + ',top=120,resizable=yes,scrollbars=yes,status=yes,menubar=no,width=515, height=440'); newWin.focus()
}




function getCookie( name ) {
	var start = document.cookie.indexOf( name + '=' );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.
substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'=' + value +
		( ( expires ) ? ';expires='
+expires_date.toGMTString() : '' ) +
//expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


function userblock_fixed () {
		if (/Safari/.exec(thisUserAgent)) {document.getElementById('user-corner').className = 'userblock-absolute';}
		
		var sLeft = document.body.scrollLeft || window.pageXOffset || document.documentElement.scrollLeft;

		document.getElementById('user-corner').style.left = -sLeft + 'px';
		document.getElementById('user-corner').className = 'userblock-fixed';
}



function printAddr (_hamper,_prefix,_postfix,_face) {
  _hamper = _prefix + "@" + _hamper + (_postfix || '');
  _face = !(_face) ? _hamper : _face;
  document.write(_face.link("mailto:"+_hamper));
}


function putplayer (w, h, fname) {
document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + w + '" height="' + h + '" id="player" align="middle">' +
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="allowFullScreen" value="false" />' +
	'<param name="flashvars" value="url=/data/tracklist.xml"/>'+
	'<param name="movie" value="/images/'+ fname +'" />'+
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<param name=wmode value=transparent>' +
	'<param name=scale value=noscale>' +
	'<embed src="/images/' + fname + '" flashvars="url=/data/tracklist.xml" quality="high" bgcolor="#ffffff" width="' + w + '" height="' + h + '" name="player" align="middle" wmode="transparent" scale=noscale allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}

function print_presentation () {
	document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="900" height="675" id="presentation" align="middle">'+
		'<param name="allowScriptAccess" value="sameDomain" />' +
		'<param name="movie" value="presentation.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="presentation.swf" quality="high" bgcolor="#ffffff" width="900" height="675" name="presentation" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}


function switcher(el, divName) {
		var list = document.getElementById('box_menu').getElementsByTagName('a');
		var divSwitch = document.getElementById(divName).parentNode.getElementsByTagName('div');
		for (var i = 0; i < list.length; i++) {
			list[i].className = '';
		}
		for (var j = 0; j < divSwitch.length; j++) {
			if (divSwitch[j].className == 'switch') divSwitch[j].style.display = 'none';
		}
		el.className = 'select';
		document.getElementById(divName).style.display = 'block';
	}
	
	
function view_cover(el, hid) {
	var imgs = el.parentNode.parentNode.getElementsByTagName('img');
	for (var i = 0; i < imgs.length; i++) {
		if (imgs[i].parentNode.className == 'cover') imgs[i].parentNode.style.display = 'none'
		if (imgs[i].parentNode.parentNode.tagName == 'TD') imgs[i].parentNode.parentNode.parentNode.parentNode.parentNode.style.display = 'none'
	}
	if (el.getElementsByTagName('a')[el.getElementsByTagName('a').length-1].className == 'cover') {
		el.getElementsByTagName('a')[el.getElementsByTagName('a').length-1].style.display = 'inline';
		//$(el.getElementsByTagName('a')[el.getElementsByTagName('a').length-1]).animate({opacity:1}, 100);
	}
	if (el.getElementsByTagName('table')[0]) el.getElementsByTagName('table')[0].style.display = 'block';
}



function initBrickSize(brick, lisCount, lisWidth) {
		var lis = brick.getElementsByTagName('ul')[0].getElementsByTagName('li'); // all the li
		var box_menu = document.getElementById('box_menu');
		var marginWidth = Math.floor((winWidth - (lisCount * lisWidth))/2)-1;
		if (thisUserAgent != 'IE6') marginWidth = ++marginWidth;
		simplifyCSSBlock(document.styleSheets[0], marginWidth);
		if (thisUserAgent == 'IE6' || thisUserAgent == 'IE7') box_menu.style.margin = '0 ' + marginWidth + 'px';
}

function VisibleCover() {
	for (var i = 0; i < brick.getElementsByTagName('ul').length; i++) {
		var lis = brick.getElementsByTagName('ul')[i].getElementsByTagName('li');
		for (var j = 0; j < lis.length; j++) {
			if (j < visibleCoverCount) lis[j].style.display = 'inline';
			else lis[j].style.display = 'none'
		}
	}
}

function simplifyCSSBlock(cssDoc, cssValue) {
  var theRules = new Array();
	theRules = cssDoc.rules || cssDoc.cssRules;
	theRules[theRules.length-1].style.margin = '0 ' + cssValue + 'px';
}


function addRemoveClass (el, className) {
	if (el.className) {
		el.removeAttribute('class')
		el.removeAttribute('className')
	}
	else el.className = className;
}

function loadingSide(sideImg) {
	var elImg = document.getElementById('loading').firstChild;
	var valueImg = 4;
	if (sideImg == 'left') {
		elImg.style.left = '5px';
		elImg.style.right = 'auto';
	}
	else {
		elImg.style.right = '5px';
		elImg.style.left = 'auto';
	}
}


function writeNavigation(divName, urlPage, allCount, count, startNext, startPrev, currentPage) {
	var pNavigation = document.getElementById(divName+'Navigation').getElementsByTagName('p')[0];
	startPrev = startPrev < -30 ? 0 : startPrev;
	urlPage = urlPage + 'c=' + visibleCoverCount + '&';
	if (visibleCoverCount < count) {
		
		pNavigation.parentNode.className='navigation';
		
		
		if (startPrev) {
			currentPage = Math.round((startPrev + visibleCoverCount) / visibleCoverCount + 2)
			pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + currentPage - 1 + '&'), '', (currentPage-2)*visibleCoverCount, visibleCoverCount, "nav-left", 'left'));
			if (currentPage - 4 > 1) pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=0&'), 1, 0, visibleCoverCount, '', 'left'));
			if (currentPage - 4 > 2) pNavigation.appendChild(document.createTextNode(' ... '));
			for (var i = (currentPage-4); i < currentPage; i++) {
				if (i > 0) 
					pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + i + '&'), i, (i*visibleCoverCount - visibleCoverCount), visibleCoverCount), '', 'left');
			}
			
		}
		
		else {
			currentPage = 1;
			pNavigation.appendChild(noImgNavigation('left', 'prev'));
			//pNavigation.appendChild (currentPageWrite (1));

		}
		
		pNavigation.appendChild (currentPageWrite (currentPage));
		
		if (startNext) {
			if (allCount) {
				for (var i = (currentPage + 1); i <= (currentPage + 4); i++) {
					if (i * visibleCoverCount <= allCount) 
						pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + i + '&'), i, (i*visibleCoverCount - visibleCoverCount), visibleCoverCount),'' , 'right');
				}
				if (currentPage + 4 < (allCount / visibleCoverCount - 1)) pNavigation.appendChild(document.createTextNode(' ... '));
				if (currentPage + 4 < allCount / visibleCoverCount) {
					var lastPage = Math.floor(allCount / visibleCoverCount);
					var lastPage = (lastPage*visibleCoverCount < allCount) ? ++lastPage : lastPage;
					pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + lastPage + '&'), lastPage, (lastPage*visibleCoverCount - visibleCoverCount), visibleCoverCount),'', 'right');
				}
			}
			else
				pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + (currentPage + 1) + '&'), (currentPage + 1), ((currentPage+1)*visibleCoverCount - visibleCoverCount), visibleCoverCount, "", 'right')); 
				
			pNavigation.appendChild(pageWrite (divName, (urlPage + 'page=' + (currentPage + 1) + '&'), '', ((currentPage+1)*visibleCoverCount - visibleCoverCount), visibleCoverCount, "nav-right", 'right'));
		}
	}
	//addHandler('window', 'resize', '"writeNavigation(' + divName + ', ' + urlPage + ', ' + allCount + ', ' + count + ', ' + startNext + ', ' + startPrev +', '+ currentPage + ')"');
}


function pageWrite (divName, urlPage, textWrite, pageStart, count, classWrite, loadSide) {
	var tag = document.createElement ('a');
	if (classWrite) tag.className = classWrite
	if (thisUserAgent == 'IE6' || thisUserAgent == 'IE7') tag.onclick = function(event) {loadingSide(loadSide); view_albums(divName, urlPage, pageStart, count)};
	else tag.setAttribute('onclick', "loadingSide('" + loadSide + "'); view_albums('" + divName + "', '" + urlPage + "', " + pageStart + ", " + count + ")");
	tag.innerHTML = textWrite;
	return tag;
}

function currentPageWrite (textWrite) {
	var tag = document.createElement ('strong');
	tag.innerHTML = textWrite;
	return tag;
}

function noImgNavigation(side, navName) {
	var noPrev = document.createElement('img');
		noPrev.className = 'nav-'+side;
		noPrev.src = '/images/nav-'+ navName +'-none.gif';
		return noPrev;
}




function addHandler(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}

function removeHandler(object, event, handler)
{
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}





function req(divIn, pageUrl, error, ifGood) {
	var req = false;
	if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) req.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } }
	if (req) {
		req.onreadystatechange = function() {
			//if (req.status == 500) error;
			if (req.readyState == 4) if (req.status == 200) {
					divIn.innerHTML = req.responseText;
					ifGood
		 	}
		}
			req.open('GET', pageUrl);
			req.send(null);
		}
}


function addClipboard(el, text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/images/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
    
    var elText = el.innerHTML;
    el.innerHTML = 'Код плеера скопирован в буфер обмена';
    el.className = 'copy';
    
    var elTimer = setTimeout(function(){clipboardMsg (el, elText)}, 5000);
  }
}

function clipboardMsg (el, elText) {
	el.innerHTML = elText;
	el.removeAttribute('class')
	el.removeAttribute('className')
}

function hiddenEl (el) {
	el.style.display = 'none'
}