var W3CDOM = (document.createElement && document.getElementsByTagName);
var isMSIE = /*@cc_on!@*/false;
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf("opera") != -1); 
var isGecko = (ua.indexOf("gecko") != -1);
var isSafari = (ua.indexOf("safari") != -1);
var isKonqueror = (ua.indexOf("konqueror") != -1);
var cp=1;
var np=1;
var slideShowDelay=10000;
var timer=null;
var fade_timer=null;

function imghover(obj, key){
	obj.src=hoverimages[key].src;
}

function imgoriginal(obj, key){
	obj.src=originalimages[key].src;
}

function findlastprojectid(){
	var lpid=1;
	for (n=9; n>0; n=n-1) {
		if (document.getElementById("release"+n)) {
			if (n>lpid) lpid=n;
			}
		}
	return lpid;
}

function projectsSlideShow(){	if ($('releases_wrapper')) {
		moveproject(1);
		if (cp==1) slideShowDelay=slideShowDelay*1.5;
		timer=setTimeout("projectsSlideShow()", slideShowDelay);
		}
}

function moveproject(step) {
	np=cp+step;
	var a=$("release"+cp);
	var b=$("release"+np);
	var c=$("openplayer_ahref");
	if (!b) {
		if (step>0) {
			np=1; var b=$("release"+np); 
			} else {
			np=findlastprojectid(); var b=document.getElementById("release"+np); 
			}
		}
	fade("releases_wrapper","out");
	var timer3=setTimeout('$("release'+cp+'").style.display="none"; $("release'+np+'").style.display="block"; fade("releases_wrapper","in");',100);
	if (b.className!="") {
		c.href="/mp3player/!"+b.className;
		c.style.display="block";
		} else {
		c.style.display="none";
		}
	cp=np;
	clearTimeout(timer);
}

function fadecycle(objid, direction) {	obj=$(objid);
	var op=obj.style.opacity;
	if (!op) op=1;
	if (direction=="in") {		op=eval(op)+0.20;
		if (op>1) op=1;
	} else {		op=eval(op)-0.20;
		if (op<0) op=0;
	}
	obj.style.opacity=op;
	if ((op>0) && (op<1)) { fade_timer=setTimeout("fadecycle('"+objid+"','"+direction+"');",20); }
}

function fadecycleie(objid, direction) {
	obj=$(objid+'_ie');
	op=parseInt(obj.style.filter.substr(14,3))/100;
	if (!op) op=1;
	if (direction=="out") {
		op=eval(op)+0.20;
		if (op>1) op=1;
	} else {
		op=eval(op)-0.20;
		if (op<0) op=0;
	}
	obj.style.filter="alpha(Opacity="+op*100+");"
	if ((op>0) && (op<1)) { fade_timer=setTimeout("fadecycleie('"+objid+"','"+direction+"');",20); }
	if (op==0) {		obj.style.display="none";
	} else {		obj.style.display="block";
	}
}

function fade(objid, direction) {	clearTimeout(fade_timer);
	if (isMSIE) {		fadecycleie(objid, direction);
		} else {		fadecycle(objid, direction);	
		}
}

var openwindow;

function window_available() {
if (window.opera) {
	return false;
} else {
    if (!openwindow) {
        return false;
    }
    else if (openwindow.closed) {
        return false;
    }
    else {
        return true;
    }
}
}

function openFullPic(theURL,winName,w,h,title) {

  var left = ((screen.width-w)/2)-40;
  var top = ((screen.height-h)/2)-40;
  
  w=w+70;
  h=h+60; feat_full='resizable=no,location=no,menubar=yes,scrollbars=yes,status=yes,left='+left+',top='+top+',toolbar=yes,fullscreen=no, dependent=no, width='+w+', height='+h+'';
  
if (window_available()) {
   openwindow.close();
   }

	openwindow=window.open("","",feat_full);
	openwindow.document.write("<HTML><HEAD><TITLE>Полноразмерное изображение</TITLE> ");
	openwindow.document.write('<META http-equiv="Content-Type" content="text/html; charset=windows-1251"> ');
    openwindow.document.write("<LINK rel='stylesheet' type='text/css' href='/css/main.css'>");
	openwindow.document.write("</HEAD><BODY style='margin-top: 10px; margin-bottom: 0px; background: #EEEDD8;'>");
	openwindow.document.write("<DIV align='center'><A style='color: #0000FF;' HREF='#' onclick='window.close();' title='Закрыть окно'><IMG style='border: 1px solid #999;' src='"+theURL+"'></A></DIV><DIV style='margin-top: 10px; margin-bottom: 0px;'>");
	if (title=="") {
	  	openwindow.document.write("<P align='center' style='font-size: 80%;'><A class='gl' HREF='#' onclick='window.close();'>Закрыть окно</A></P>");
	} else {
	 	openwindow.document.write("<P align='center' style='font-size: 80%;'><A class='gl' HREF='#' onclick='window.close();' title='Закрыть окно'>"+title+"</A></P>");
	}
	openwindow.document.write("</DIV></BODY></HTML>");
	openwindow.document.close();
  return false;
}


function openrelease(){
  var b=$("release"+cp);
  var album="";
  if (b)
  	if (b.className) {
	  album=b.className;
	  }
  return openplayer(album);
}

function openplayer(album){  var w=610;
  var h=405;
  if (album!="") album="!"+album;
  var left = ((screen.width-w)/2)-70;
  var top = ((screen.height-h)/2)-100;
  feat_full='resizable=yes, location=yes, menubar=yes, scrollbars=no, status=yes, left='+left+', top='+top+', toolbar=no, fullscreen=no, dependent=no, width='+w+', height='+h+'';
  if (window_available()) {  openwindow.close();  }
  openwindow=window.open("/mp3player/"+album,"player",feat_full);
  return false;
}

function verticalMiddle(){
	if (window.innerHeight) browserHeight=window.innerHeight;
	  else {
	  	if(document.body){
	  		if(document.body.clientHeight) browserHeight=document.body.clientHeight;
	  		} else {
	  		browserHeight=0;	
	  		}
	  }
	var clientHeight=$('all').clientHeight;
	if (browserHeight<clientHeight) clientHeight=browserHeight;
	var topPadding="0px";
	if (clientHeight>740) {
		topPadding=Math.round((clientHeight-740)/2.2)+"px";
	}
	$('topbgcolor').style.height=topPadding;
	$('middler').style.paddingTop=topPadding;
	document.cookie="toppadding="+topPadding+"; path=/; expires=Mon, 01-Jan-2029 00:00:00 GMT";
}

function $(id) {
  if (typeof id == 'string') {
    return document.getElementById(id);
  }
  alert(id);
  return id;
}

jQuery(function($) {
  $("#myname").dblclick(function(){  	 $.get("/extensions/rssimport/refresh.php");
  	 window.location="/";
  	});
});