zoom_count = 0;


/* OPEN ZOOM */
/***************************************************/
function openZoom(offset,year,month,day,hour,channel_id,start_time,end_time)
{
	channel_element = document.getElementById('channel_'+channel_id);
	scroll_pos = f_scrollTop();
	client_height = f_clientHeight();
	page_size = getPageSizeWithScroll();
	
	ajax_changeZoom(offset,year,month,day,hour,channel_id,start_time,end_time);
	document.getElementById('zoom_overlay').style.display='block';
	document.getElementById('zoom_overlay').style.height=(page_size[1])+'px';
	document.getElementById('zoom_wrapper').style.display='block';
	document.getElementById('zoom_wrapper').style.top=((client_height/4)+scroll_pos)+'px';
	start_scroll_zoom();
	//opacity('zoom', 0, 100, 500);
	
}



/* CLOSE ZOOM */
/***************************************************/
function closeZoom()
{
	//opacity('zoom', 100, 0, 500);
	document.getElementById('zoom_content').innerHTML='';
	document.getElementById('zoom_overlay').style.display='none';
	document.getElementById('zoom_wrapper').style.display='none';
	zoom_count = 0;
	end_scroll_zoom();
}



/* ELEMENT POSITION */
/***************************************************/
function findPos(obj)
{
	var position = new Array();
	if (obj.offsetParent) 
	{
		position[0] = obj.offsetLeft
		position[1] = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			position[0] += obj.offsetLeft
			position[1] += obj.offsetTop
		}
	}
	return position;
}






/* OPACITY FADE */
/***************************************************/
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}





/* ZOOM AJAX */
/***************************************************/
function ajax_changeZoom(offset,year,month,day,hour,source,start,end)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('zoom_content').innerHTML=xmlHttp.responseText;
		}
	}

	url = 'download.php?offset='+offset+'&hour='+hour+'&day='+day+'&month='+month+'&year='+year+'&source='+source+'&start='+start+'&end='+end;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}





/* ZOOM PAGINATE */
/***************************************************/
function zoom_pagiante(direction)
{

	if(direction == 'prev')
	{
		zoom_count--;
		document.getElementById('zoom_'+zoom_count).style.display  = 'block';
		document.getElementById('zoom_'+(zoom_count+1)).style.display  = 'none';
	}
	else
	{
		zoom_count++;
		document.getElementById('zoom_'+zoom_count).style.display  = 'block';
		document.getElementById('zoom_'+(zoom_count-1)).style.display  = 'none';
	}
		
}
