/*
    Copyright by Aykut Çevik
*/

function Main(){
    SetEvents();
    ScaleAll();
    SetImgFader();
}

function SetEvents(){
    
    // resize event
    $(window).resize(function(){
        ScaleAll();
    });
}

function ScaleAll(){
    ScaleSliderContainer();
    ScalePic();
}

function ScaleSliderContainer(){
       
    // get max height
    var iMaxH = $(document).height();
    var iMaxW = $(document).width();
    
    // set to slider
    $("#slider").height(iMaxH);
    $("#slider").width(iMaxW);
}

function ScalePic(){
    
    // get max width
    var iMaxW = $(document).width();
    var iMaxH = $(document).height();
    
    // set to slider
    if(iMaxH - 100 < iMaxW)
        $("#sliderpic").width(iMaxW + 100);
    else
        $("#sliderpic").width(iMaxW);
}

var sImgPath = "src/slider/";
var sImages = new Array("4.jpg", "3.jpg", "1.jpg");
var iIndex = 0;
function SetImgFader(){
    window.setInterval(function(){
        
        // count
        iIndex++;
        
        if(iIndex == sImages.length)
            iIndex=0;
        
        $("#sliderpic").fadeOut('fast', function(){
            $("#sliderpic").attr("src", sImgPath + sImages[iIndex]);
        });
        $("#sliderpic").fadeIn('slow',function(){});
        
    }, 6000); // every 6s
}
