// soubor s javascriptem
var htmlobj_i, htmlobj_a;
var IE = document.all?true:false;

function zobraz(img, url, aEvent, imgx, imgy) {
    var e = aEvent ? aEvent : window.event;
    var posx=0, posy=0;

    if(htmlobj_i || htmlobj_a) skryj();
    htmlobj_a = document.createElement('a');
    htmlobj_a.href=url;
    htmlobj_a.id='aimgid';
    htmlobj_i = document.createElement('img');
    htmlobj_i.src=img;
    htmlobj_i.style.backgroundColor='black';
    htmlobj_i.style.width=imgx+'px';
    htmlobj_i.style.height=imgy+'px';
    htmlobj_i.style.border= 'solid blue';
    htmlobj_i.style.borderWidth= '3px';
    htmlobj_i.style.position='absolute';
    htmlobj_i.style.zIndex=100;

    if (e.pageX || e.pageY) {
	posx = e.pageX;
	posy = e.pageY;
    } else if (e.clientX || e.clientY) {
	posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
    }

    addEventSimple(htmlobj_i,'mouseout',skryj);

    htmlobj_i.style.left=(posx-(imgx/2))+'px';
    htmlobj_i.style.top=(posy-(imgy/2))+'px';
//    document.body.appendChild(htmlobj_a);
    document.getElementById('pro_nahledy').appendChild(htmlobj_a);
    htmlobj_a.appendChild(htmlobj_i);
}

function skryj() {
    if(htmlobj_i) {
        htmlobj_a.removeChild(htmlobj_i);
        htmlobj_i=false;
    }
    if(htmlobj_a) {
        document.getElementById('pro_nahledy').removeChild(htmlobj_a);
        htmlobj_a=false;
    }
}

function refreshPage(){
    document.location.reload();
}

function blink(id){
    document.getElementById(id).style.backgroundColor="red";
    setTimeout("document.getElementById('"+id+"').style.backgroundColor=''", 500);
    setTimeout("blink('"+id+"')",1500);
}

function newvideowin(path) {
    var win;
    win = window.open('','_blank','width=660, height=500, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
    win.focus();
    win.document.writeln(
    '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n'+
    '<html lang=\"cs\">\n'+
    '<head>\n'+
    '<title>Erotický portál sexmedia.cz - video rozhraní</title>\n'+
    '</head>\n'+
    '<body bgcolor=\"#000000\">\n'+
    '<center><div style=\"border: 2px #d9b256 solid; background-color: #500000; width: 640px; height: 480px;\">\n'+
    '<div id=\"mediaspaceN\"></div>\n'+
    '<script type=\"text/javascript\" src=\"/files/swfobject.js\"></script>\n'+
    '<script type=\"text/javascript\">\n'+
    'function runvideoN_f() { alert(\"pica\"); }\n'+
    'function runvideoN() {\n'+
    '  var s1 = new SWFObject(\"/files/player.swf\",\"plyN",\"640\",\"480\",\"9\",\"#ffffff\");\n'+
    '  s1.addParam(\"allowfullscreen\",\"true\");\n'+
    '  s1.addParam(\"allowscriptaccess\",\"always\");\n'+
    '  s1.addParam(\"wmode\",\"opaque\");\n'+
    '  s1.addParam(\"flashvars\",\"file='+path+'&streamer=lighttpd&autostart=true\");\n'+
    '  s1.write(\"mediaspaceN\");\n'+
    '}\n'+
    '//window.onload=runvideoN_f();\n'+
    '</script>\n'+
    '</body>\n'+
    '</html>\n');
    win.document.close();
    return false;
}


var MAXn=NaN, MAXv=NaN, MAXnum=NaN, MAXact=NaN;
var obj_x=NaN, obj_y=NaN;
var mou_x=NaN, mou_y=NaN;

function addEventSimple(obj,evt,fn) {
    if (obj.addEventListener)
        obj.addEventListener(evt,fn,false);
    else if (obj.attachEvent)
	obj.attachEvent('on'+evt,fn);
}
function removeEventSimple(obj,evt,fn) {
    if (obj.removeEventListener)
        obj.removeEventListener(evt,fn,false);
    else if (obj.detachEvent)
	obj.detachEvent('on'+evt,fn);
}
function kurzorCh(prc) {
    var s=Math.floor((MAXnum/MAXv)*(prc/100));
    var first=Math.max(0,Math.min(s-MAXn/2,Math.floor(MAXnum/MAXv)-MAXn));
    for(i=0;i<document.links.length;i++) {
	if(document.links[i].name=="seek") {
	    var shref = document.links[i].href;
	    var inner = document.links[i].innerHTML;
	    var num=shref.match("([&?])s=([0-9]+)"); 
	    var newhref=shref.replace(num[0],num[1]+'s='+first);
	    document.links[i].innerHTML = first;
	    document.links[i].href = newhref;
/*	    if(MAXact==first)
		document.links[i].className += ' sel';
	    else
		document.links[i].className = document.links[i].className.replace(' sel','');
*/	    first++;
	}
    }
}

function clickDrag(ae) {
    var e = ae ? ae : window.event;
    pos_x = (e.offsetX) ? e.offsetX : (e.layerX - document.getElementById('kurzor-lista').offsetLeft);
    kurzorCh(100*pos_x/700);
    document.getElementById('kurzor-dot').style.left = Math.min(Math.max(pos_x-9, 0),700) + 'px';
}
function startDrag(ae) {
    var e = ae ? ae : window.event;
    mou_x = e.clientX;
    mou_y = e.clientY;
    tmp_x = document.getElementById('kurzor-dot').style.left.replace('px','');
    tmp_y = document.getElementById('kurzor-dot').style.top.replace('px','');
    obj_x = (tmp_x) ? parseInt(tmp_x) : 0;
    obj_y = (tmp_y) ? parseInt(tmp_y) : 0;
    addEventSimple(document,'mousemove',dragMove);
    addEventSimple(document,'mouseup',dragStop);
    document.getElementById('kurzor-dot').className += ' dragged';
    return false;
}
function dragMove(ae) {
    var e = ae ? ae : window.event;
    var dX = e.clientX - mou_x;
    if(dX!=0) {
//	document.getElementById('ozn').innerHTML=obj_x+dX;
	document.getElementById('kurzor-dot').style.left = Math.min(Math.max(obj_x+dX, 0),700) + 'px';
	kurzorCh(Math.min(Math.max(obj_x+dX, 0),700)*100/700);
    }
    return false;
}
function dragStop(ae) {
    var e = ae ? ae : window.event;
    removeEventSimple(document,'mousemove',dragMove);
    removeEventSimple(document,'mouseup',dragStop);
    document.getElementById('kurzor-dot').className = document.getElementById('kurzor-dot').className.replace(/dragged/,'');
}

var tmpvote=NaN;
function loadXMLDoc(url, vote) {
    xmlhttp=null;
    tmpvote=vote;
    if (window.XMLHttpRequest) {
	xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp!=null) {
	xmlhttp.onreadystatechange=state_Change;
	xmlhttp.open("GET", url+'&sid='+Math.random(), true);
	xmlhttp.send(null);
    } else {
	alert("Your browser does not support XMLHTTP.");
    }
}
function state_Change() {
    if (xmlhttp.readyState==4) {
	if (xmlhttp.status==200) {  // 200 = OK
	    var str=xmlhttp.responseText;
	    if(str=="hlasovano") {
		var rating=parseFloat(document.getElementById('rating').innerHTML);
		var ratingcount=parseInt(document.getElementById('ratingcount').innerHTML);
		rating=rating*(ratingcount/(ratingcount+1))+(tmpvote/(ratingcount+1));
		rating=Math.round(rating*10)/10;
		ratingcount++;
		document.getElementById('rating').innerHTML = rating;
		document.getElementById('ratingcount').innerHTML = ratingcount;
		alert("Hlasování proběhlo úspěšně. Děkuji");
	    } else if(str=="oblibeno") {
		alert("Nahrávka byla přidána mezi Vaše oblíbené");
	    } else if(str=="jizoblibene") {
		alert("Nahrávku již mezi oblíbenými máte");
	    } else if(str=="znelibeno") {
		alert("Nahrávka byla odstraněna z oblíbených");
	    } else if(str=="bad")
		alert("Došlo k chybě");
	} else {
	    alert("Problem retrieving XML data");
	}
    }
}

function rmbg(elem, file) {
    if(elem.value == "") {
	elem.style.backgroundImage=file;
    } else {
	elem.style.backgroundImage="none";
    }
}


