﻿// JScript File
// **********************************************************************************
// Tanımlamalar
// **********************************************************************************
var ns4up = (document.layers) ? 1 : 0;
var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
var myDivTop = 0;
var obj = "";

// **********************************************************************************
// DivCikart(ZeminDivID, GoruntulenecekDivID, Yeniden mi Boyutlandırıldı(O yada 1))
// **********************************************************************************
function DivCikart(Zemin,Goruntu,YenidenBoyutlandir,AnimasyonOlsun)
{
    objZemin = document.getElementById(Zemin);
    objGoruntu = document.getElementById(Goruntu);
    //-- Tarayıcının boyutu değiştirildiğinde DivCikart metodu tekrar çalışıp div'lerin doğru gözükmesini sağlayacak.
    window.onresize = function () {DivCikart(Zemin, Goruntu, true)};
    if( objZemin!=null || objGoruntu!=null)
    {
        bodyWidth = 0;
        bodyHeight = 0;
        browserType = 0;
        bodyDispWidth = 0;
        
        if(navigator.appName.indexOf("Microsoft Internet Explorer")>-1)
            browserType = 1;
        if(navigator.appName.indexOf("Netscape")>-1)
            browserType = 2;
        if(navigator.appName.indexOf("Opera")>-1)
            browserType = 3;

        switch(browserType)
        {
            case 1: //-- IE
                //-- Body nin acilan bir browserdaki GERCEK genisligi/uzunlugu
                bodyWidth = document.body.clientWidth;
                bodyHeight = document.body.clientHeight;
                //-- Body nin acilan bir browserdaki GORUNEN genisligi/uzunlugu
                bodyDispWidth = document.documentElement.clientWidth;
                bodyDispHeight = document.documentElement.clientHeight;                    
                if (bodyHeight < bodyDispHeight)
                    bodyHeight = bodyDispHeight;
                break;
            case 2: //-- NS
                //-- Body nin acilan bir browserdaki GERCEK genisligi/uzunlugu
                bodyWidth = document.body.clientWidth-16;
                bodyHeight = document.body.clientHeight;
                //-- Body nin acilan bir browserdaki GORUNEN genisligi/uzunlugu
                bodyDispWidth = window.innerWidth-16;
                bodyDispHeight = window.innerHeight+10;
                if (bodyHeight < bodyDispHeight)
                    bodyHeight = bodyDispHeight;
                break;
            case 3: //-- OP
                //-- Body nin acilan bir browserdaki GERCEK genisligi/uzunlugu
                bodyWidth = document.documentElement.clientWidth;
                bodyHeight = document.documentElement.clientHeight;
                //-- Body nin acilan bir browserdaki GORUNEN genisligi/uzunlugu
                bodyDispWidth = document.body.clientWidth;
                bodyDispHeight = document.body.clientHeight+10;
                if (bodyHeight < bodyDispHeight)
                    bodyHeight = bodyDispHeight - 10;
                break;
            default : break;
        }              
                           
        //-- Ortada cikan div in genisligi/uzunlugu
        if(objGoruntu!=null)
        {
            dispWidth = parseInt(objGoruntu.style.width);
            dispHeight = parseInt(objGoruntu.style.height);            
        }

        //-- Arkaplanda cikan div in genisligi BODY nin gercek genisligine/uzunluguna ataniyor
        if(objZemin!=null)
        {
            objZemin.style.width = bodyWidth + "px";
            objZemin.style.height = bodyHeight +"px";
        }
        
        //-- Ortada cikan div in SOL/YUKARIDAN dan uzakligi hesaplaniyor (ortalama)                        
        if(objGoruntu!=null)
        {
            objGoruntu.style.left = ((bodyDispWidth-dispWidth)/2)+"px";
            objGoruntu.style.top = ((bodyDispHeight-dispHeight)/2)+"px";
        }

        if(objZemin!=null)
        {
            if (!YenidenBoyutlandir)
            {
                objZemin.style.display = "block";
                if (AnimasyonOlsun)
                {         
                    shiftOpacity(Zemin, 800, 90);
                }
                else
                {
                    objZemin.style.opacity = "0.9";    
                    objZemin.style.filter = "alpha(opacity=90)";
                }
            }
        }
        
        if(objGoruntu!=null)
        {
            if (!YenidenBoyutlandir)
            {
                objGoruntu.style.display = "block";
                if (AnimasyonOlsun)
                {         
                    shiftOpacity(Goruntu, 600, 100);
                }
                else
                {
                    objGoruntu.style.opacity = "0.9";    
                    objGoruntu.style.filter = "alpha(opacity=90)";
                }
            }
            //-- Ortada cikan div in konumlandirilmasi icin atamalar yapiliyor (ortalama)
            ObjPositionNow(Goruntu);
            SetDivPosition();
        }
    }      
}
// ***********************************************************************************************************
// shiftOpacity(UygulanacakID, MiliSaniye, OpacityBitisDeger) --> Fade in Fade Out İşleminin Başlangıcı
// ***********************************************************************************************************
function shiftOpacity(id, millisec, opacSon) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, opacSon, millisec); 
    } else { 
        opacity(id, opacSon, 0, millisec); 
    } 
}
// ***********************************************************************************************************
// opacity(UygulanacakID, OpacityBaslangicDeger, OpacityBitisDeger, MiliSaniye) --> Animasyonu gerçekleştirir.
// ***********************************************************************************************************
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++; 
        } 
    } 
} 

// ************************************************************************************
// changeOpac(OpacityDegeri, UygulanacakID) --> Çeşitli tarayıcılara göre opacity verir
// ************************************************************************************
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 + ")"; 
} 
 
// ************************************************************************************
// ObjPositionNow(GoruntulenenDiv) --> Baslangicta DIV in nerede oldugunu almaya yarar.
// ************************************************************************************
function ObjPositionNow(prmObj)
{
    obj = prmObj;
    if(obj!="" && document.getElementById(obj))
    {
        myDivTop = parseInt(document.getElementById(obj).style.top);    
        window.onscroll = SetDivPosition;        
    }
}

// **************************************************************************************************
// SetDivPosition() --> Div icin Scroll Çekildikce Yeniden Konumlandirilmasini Sağlar
// **************************************************************************************************
function SetDivPosition()
{
    if (myDivTop!=0)
    {
        GetY = (document.all) ? document.body.scrollTop : window.pageYOffset;   
        GetY = (GetY==0 && document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : GetY ;
        GetY = (GetY==0 && document.body) ? document.body.scrollTop : GetY ;
        
        if (ie4up){
     	   document.all[obj].style.pixelTop = myDivTop + GetY ;
        }
        else if (ns6up){
     	   document.getElementById(obj).style.top = myDivTop + GetY + "px";
        }
        else if (ns4up) {
     	   document.layers[obj].top = myDivTop + GetY + "px";
        }    
     }
}

// **********************************************************************************
// DivKapat(ArkaPlanDiv, GoruntulenenDiv) --> Div için kapatma işlemi gerçekleştirir.
// **********************************************************************************
function DivKapat(Zemin1,Goruntu1)
{
    if(Zemin1!="" && document.getElementById(Zemin1) && Goruntu1!="" && document.getElementById(Goruntu1))
    {
        //Zemini kapat ve değerlerini 0 a çek
        document.getElementById(Zemin1).style.display = "none";
        document.getElementById(Zemin1).style.opacity = "0.0";    
        document.getElementById(Zemin1).style.filter = "alpha(opacity=0)";
        //Görüntülenen Divi Kapat ve değerlerini 0a çek
        document.getElementById(Goruntu1).style.display = "none";
        document.getElementById(Goruntu1).style.filter = "alpha(opacity=0)";
        document.getElementById(Goruntu1).style.opacity = "0.0";
    }
    window.onscroll = null;
    window.onresize = null;
}
