var xmlHttp = createXmlHttpRequestObject();
 

function createXmlHttpRequestObject() {

    var xmlHttp;
    try {

        xmlHttp = new XMLHttpRequest();
    }
    catch(e)  {

        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");

    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
          try { 

              xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
          } 
          catch (e) {}
    }
}

  if (!xmlHttp) alert("Ошибка создания XMLHttpRequest");
  else return xmlHttp;
}


function onf(id){

    if (id!=document.getElementById('active_icon').value && document.getElementById('active_icon').value!=0){
    document.getElementById(id).style.border="#fff solid 2px";
    document.getElementById(id).style.position="relative";
    document.getElementById(id).style.margin = "-2px";
    }

}

function ons(id){

    if (id!=document.getElementById('active_icon').value && document.getElementById('active_icon').value!=0){
    document.getElementById(id).style.border="none";
    document.getElementById(id).style.position="relative";
    document.getElementById(id).style.margin = "0";
    }
}



function NextFoto($contest_id,$foto_id,$kind){

        if (xmlHttp) {
            try {

		var stl    = 'mid_foto' + $foto_id;
                var slink  = 'link'     + $foto_id;
		var zooms1 = 'zooms'    + $foto_id;
		var spanel = 'panel'    + document.getElementById('active_icon').value;

		var okoshko1 = 'okoshko'    + $foto_id;
		document.getElementById(okoshko1).style.display="none";


                document.getElementById(spanel).innerHTML = '<a href="javascript:void(0);" onclick="SelectFoto('+$contest_id+','+document.getElementById('active_icon').value+',2);" id="link'+document.getElementById('active_icon').value+'" onMouseOver="onf(this.id);" onMouseOut="ons(this.id);"><img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img"  /></a>';
		document.getElementById(zooms1).style.display="none";	
                document.getElementById(slink).style.border="none";
                document.getElementById(slink).style.position="relative";
                document.getElementById(slink).style.margin = "0";

                xmlHttp.open("GET", "/cmd/next_contest_foto.php?contest_id="+$contest_id+"&foto_id="+$foto_id+"&kind="+$kind, true);
                xmlHttp.onreadystatechange = handlerNextFoto;
                xmlHttp.send(null);

        }
        catch(e) {}
    }

}

function SelectFoto($contest_id,$foto_id,$kind){

        if (xmlHttp) {
            try {

                var stl    = 'mid_foto' + document.getElementById('current_foto').value;
		var zooms1 = 'zooms' + document.getElementById('current_foto').value;
		var spanel = 'panel' + document.getElementById('active_icon').value;


		var okoshko1 = 'okoshko' + document.getElementById('current_foto').value;
		document.getElementById(okoshko1).style.display="none";



		document.getElementById(spanel).innerHTML = '<a href="javascript:void(0);" onclick="SelectFoto('+$contest_id+','+document.getElementById('active_icon').value+',2);" id="link'+document.getElementById('active_icon').value+'" onMouseOver="onf(this.id);" onMouseOut="ons(this.id);"><img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img"  /></a>';
		document.getElementById(zooms1).style.display="none";

                xmlHttp.open("GET", "/cmd/select_contest_foto.php?contest_id="+$contest_id+"&foto_id="+$foto_id+"&kind="+$kind, true);
                xmlHttp.onreadystatechange = handlerNextFoto;
                xmlHttp.send(null);

        }
        catch(e) {}
    }

}



function handlerNextFoto() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            try {
                var content = xmlHttp.responseText;


		a = content.split("|");
		$count = document.getElementById('count_fotos').value;		


		var stl1 = 'mid_foto' + a[0];
    		var slink = 'link' + a[0];
		var spanel = 'panel' + a[0];
		var zooms = 'zooms' + a[0];

		var okoshko = 'okoshko' + a[0];
		document.getElementById(okoshko).style.display="block";

	        //document.okno.src = '/img2.php?mod=contest_img&fname='+a[0]+'_'+a[1];


		if (a[8]>=648 && a[9]>=425)    
	        document.getElementById(zooms).style.display="block";

		document.getElementById('current_foto').value = a[0];
		document.getElementById(slink).style.border="#949383 solid 5px";
		document.getElementById(slink).style.position="relative";
		document.getElementById(slink).style.margin = "-5px";
		document.getElementById('active_icon').value = a[0];
		document.getElementById('active_file').value = '/files/contest_img/'+a[0]+'_'+a[1];
		document.getElementById(spanel).innerHTML = '';
		document.getElementById(spanel).innerHTML = '<img src="'+document.getElementById('active_file').value+'" width="80" height="60" alt="img" style="border: #949383 solid 5px; position: relative; margin: -5px" />';


		document.getElementById('bot').innerHTML = '';


		if ($count>7)
		{

		if (a[10]==1) document.getElementById('sprev').innerHTML = '<img src="/images/ru_times/gall_prev_one.gif" class="prev_image">';
		if (a[10]==2) document.getElementById('sprev').innerHTML = '<a href="javascript:stepcarousel.stepBy(\'mygallery\', -1)" id="gall_prev" class="gall_nav" title="предыдущая"><strong>предыдущая</strong></a>';
		if (a[11]==1) document.getElementById('snext').innerHTML = '<img src="/images/ru_times/gall_next_one.gif" class="next_image">';
		if (a[11]==2) document.getElementById('snext').innerHTML = '<a href="javascript:stepcarousel.stepBy(\'mygallery\', 1)" id="gall_next" class="gall_nav" title="следующая"><strong>следующая</strong></a>';


		if (a[4]>0) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);stepcarousel.stepBy(\'mygallery\', -1);" class="left">Предыдущая</a><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';
		if (a[4]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);stepcarousel.stepBy(\'mygallery\', -1);" class="left">Предыдущая</a><span class="right">Следующая</span>';
		if (a[4]==0 & a[6]==1) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';
		if (a[7]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);stepcarousel.stepBy(\'mygallery\', 1);" class="right">Следующая</a>';

		} else {

	if (a[4]>0) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);" class="left">Предыдущая</a><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';
	if (a[4]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',1);" class="left">Предыдущая</a><span class="right">Следующая</span>';
	if (a[4]==0 & a[6]==1) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';
	if (a[7]==0 & a[6]==2) document.getElementById('bot').innerHTML = '<span class="left">Предыдущая</span><a href="javascript:void(0);" onclick="NextFoto('+a[2]+','+a[0]+',2);" class="right">Следующая</a>';



		}


	        document.getElementById('foto_name').innerHTML = '';
		document.getElementById('foto_name').innerHTML = a[3];

		document.getElementById('foto_info').innerHTML = '';
                document.getElementById('foto_info').innerHTML = a[10];

                }
            catch(e) {}
        }
        else {}
  }
}










