﻿// JScript File

var clipRight = 860;
var clipLeft = 0;

var clipTop = 0;
var clipBottom = 50;

var topper = 0;
var lyrheight = 0;
var lyrwidth = 0;
var time,amount,theTime,theHeight,DHTML;

var count = 0;
var type = "";
var images = new Array();

window.onload = function()
{
    positionComent();
    positionPreloader();

    var sp = document.getElementById("_ctl0_sp_type");
    if(sp.innerHTML != "") 
    {
        type = sp.innerHTML;
        send(type);
    }
    init();
}

function positionPreloader()
{
    var div = document.getElementById("_ctl0_div_preload");
    if(div)
    {
        div.style.marginTop = div.parentNode.offsetHeight/2 - 68 + "px";
        div.style.marginLeft = div.parentNode.offsetWidth/2 - 77 + "px";
        div.style.visibility = "visible";
    }
}

function positionComent()
{
    var p = document.getElementById("_ctl0_p_coment");
    if(p) p.style.width = p.parentNode.offsetWidth + "px";
}

//------ AJAX BLOCK ---------------------------

function send(str)
{
    req = getRequest();
    req.onreadystatechange = stateChange_send;
    req.open("POST", "loadimg.aspx", true);
    req.setRequestHeader("Content-Type", "text/html");
    req.send(str);
}
function getRequest()
{
    var xreq = null;
    if(window.XMLHttpRequest)
    {
        xreq = new XMLHttpRequest;
    }
    else if(typeof ActiveXObject != "undefined")
    {
        xreq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xreq;
}
function stateChange_send()
{
    if(req.readyState == 4)
    {   
        parseResponce(req.responseText.split("*send*")[1]);
    }
}

function parseResponce(str)
{
    count = str.split("***").length;
    var urls = str.split("***");
    images.length = count;
    var name = "dot";
    if(type.search(/galery/) != -1) name = "prev";
    
    for(var i = 0; i < count; i++)
    {
        images[i] = new Image;
        images[i].src = urls[i];
        images[i].name = name + i;
    }
    intervalID = setInterval("completeLoad()", "10");
}

function completeLoad()
{
    var k = 0;
    for(var i = 0; i < count; i++)
    {
        if(images[i].complete)
        {
            k++;
            var dot = document.getElementById(images[i].name);
            if(dot) dot.style.visibility = "visible";
        }
    }
    if(k == count) 
    {
        clearInterval(intervalID);
        var preload = document.getElementById("_ctl0_div_preload");
        if (preload) preload.style.display = "none";
    }
}

//----------------------------------------------------

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('div_flash');
	if(x.obj!=null)
	{
	//var x2 = document.getElementById('ctl00_ContentPlaceHolder3_JournalArchiveControl1_DataGrid1');
//	    if (document.layers)
//	    {
//		    lyrheight = x.style.clip.bottom;
//		    lyrheight += 20;
//		    x.style.clip.top = clipTop;
//		    x.style.clip.left = clipLeft;
//		    x.style.clip.right = clipWidth;
//		    x.style.clip.bottom = clipBottom;
//	    }
	    //else 
	    if (document.getElementById || document.all)
	    {
	        var img_flash= document.getElementById("_ctl0_img_flash");
		    lyrwidth = img_flash.offsetWidth;
	        if(lyrwidth<=clipRight)
	        {
	            document.getElementById('to_left').style.visibility='hidden';
	            document.getElementById('to_right').style.visibility='hidden';
	            x.style.clip = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
	            scrollToCenter();
	            x.style.width = clipRight - topper + "px";
	        }
	        else
	        {
	            document.getElementById('to_left').style.visibility='visible';
	            document.getElementById('to_right').style.visibility='visible';
	            
		        x.style.clip = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		        x.style.width = clipRight + "px";
		        srollToRight();
		    }
		    var td = document.getElementById("_ctl0_td_center");
		    td.style.height = img_flash.offsetHeight + "px";
		    x.style.visibility = "visible";
	    }
	}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipLeft += amount;
	clipRight += amount;
	topper -= amount;
//	if (clipTop < 0 || clipBottom > lyrheight)
//	{
//		clipTop -= amount;
//		clipBottom -= amount;
//		topper += amount;
//		return;
//	}
	if (clipLeft < 0 || clipRight > lyrwidth)
	{
		clipLeft -= amount;
		clipRight -= amount;
		topper += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
	    thelayer = new getObj('div_flash');
		clipstring = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.marginLeft = topper + 'px';
		thelayer.style.width = parseInt(amount) + parseInt(thelayer.style.width) + "px";
	}
//	else if (document.layers)
//	{
//		thelayer.style.clip.top = clipTop;
//		thelayer.style.clip.bottom = clipBottom;
//		thelayer.style.top = topper;
//	}
	time = setTimeout('realscroll()',theTime);
}

function scrollToCenter()
{
    if (!DHTML) return;
    thelayer = new getObj('div_flash');
    while(true)
    {
	    topper += 1;
	
        if (topper > ((clipRight - lyrwidth)/2))
	    {   
		    topper += 1;
		    thelayer.style.marginLeft = topper + 'px';
		    return;
	    }
	}
}

function srollToRight()
{
 if (!DHTML) return;
 thelayer = new getObj('div_flash');
    while(true)
    {
	clipLeft += 1; 
	clipRight += 1;
	topper -= 1;
	
        if (clipRight > (lyrwidth/2 + 430))
	    {
		    clipLeft -= 1;
		    clipRight -= 1;
		    topper += 1;
		    clipstring = 'rect(auto,'+clipRight+'px,auto,'+clipLeft+'px)';
		    thelayer.style.clip = clipstring;
		    thelayer.style.marginLeft = topper + 'px';
		    thelayer.style.width = parseInt(clipLeft) + parseInt(thelayer.style.width) + "px";
		    return;
	    }
	    
	}
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  	if(document.getElementById(name) !=null)
  	{
	    this.style = document.getElementById(name).style;
	}
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

//------------- For Images --------------------

function changeImg(n)
{
    if (document.getElementById || document.all)
	{
        var img_flash = document.getElementById("_ctl0_img_flash");
        img_flash.src = images[n].src;
        
        topper = 0;
        clipRight = 860;
        clipLeft = 0;
		
		init();
    }
}