

var ElementWidth = 320;

if (document.captureEvents && Event.KEYUP) {
    document.captureEvents(Event.KEYUP);
}
document.onkeyup = ClosePopupOnKeyDown;

window.onresize = function() {

    Resize();

}




/*

//store data using name/value format
document.cookie = "sitename=rt"

//retrieve value from cookie
var beginindex, endindex, result
//set begin index to 1st letter of value ("W")
beginindex = document.cookie.indexOf("sitename") + 9
endindex = beginindex
//while we haven't hit ";" and it's not end of cookie
while (document.cookie.charAt(endindex) != ";" &&
endindex <= document.cookie.length)
    endindex++
//result contains "JavaScript Kit"
var result = document.cookie.substring(beginindex, endindex);
alert(result);
*/





function Pager(NextOrPrev) {
    
    if (NextOrPrev == 'next') {
        NextPage = CurrentPage + 1;
       
            sUrl = 'index.php?CurrentPage=' + NextPage + '&ImagesPerPage=' + ImagesPerPage;
            Redirect(sUrl);
        
    } else {
        PrevPage = CurrentPage - 1;
      
            sUrl = 'index.php?CurrentPage=' + PrevPage + '&ImagesPerPage=' + ImagesPerPage;
            Redirect(sUrl);
        
    }

    //alert(CountElements);
    //alert(CurrentPage);


}

function Redirect(sUrl) {
    //alert(123);
   // setTimeout("Redirect2("+sUrl+")", 2000);
    window.location.href = sUrl;
     
}
function Redirect2(sUrl) {
    window.location.href = sUrl;
}


function Resize() {

    var WindowWidth = document.body.offsetWidth;
    var WindowHeight = document.body.offsetHeight;
    //document.getElementById('MainContainer').offsetWidth
    
    document.getElementById('ShadowLayer').style.width = WindowWidth;
    document.getElementById('ShadowLayer').style.height = WindowHeight;


    document.getElementById('Wrapper').style.width = WindowWidth;
     //alert(document.getElementById('MainContainer').offsetWidth);



     if ((WindowWidth > 1261) && (WindowWidth < 1581)) {
         document.getElementById('Wrapper').style.width = '1260px';
         if (ImagesPerPage != 12) {
            sUrl = 'index.php?CurrentPage=' + CurrentPage + '&ImagesPerPage=12';
            //window.location.href = sUrl;
            Redirect(sUrl);
        }
   
    }

    if ((WindowWidth > 1582)) {
        document.getElementById('Wrapper').style.width = '1581px';
        if (ImagesPerPage != 15) {
            sUrl = 'index.php?CurrentPage=' + CurrentPage + '&ImagesPerPage=15';
            //window.location.href = sUrl;
            Redirect(sUrl);
        }
       // alert('1660');
    }


    if ((WindowWidth < 1260)) {
        document.getElementById('Wrapper').style.width = '1000px';
        //alert(ImagesPerPage);
        if (ImagesPerPage != 9) {
            sUrl = 'index.php?CurrentPage=' + CurrentPage + '&ImagesPerPage=9';
            //window.location.href = sUrl;
            Redirect(sUrl);
        }
     
       // alert('1000');
    }


}

function PopupDisplay() {


    document.getElementById('ShadowLayer').style.display = '';
    document.getElementById('ShadowLayer').style.height = document.getElementById('MainContainer').offsetHeight;
    document.getElementById('ShadowLayerContent').style.display = '';
    
    document.getElementById('ShadowLayerContent').style.width = '620px';
    document.getElementById('ShadowLayerContent').style.left = ((document.getElementById('MainContainer').offsetWidth - 620) / 2) + 'px';
    //document.getElementById('ShadowLayerContent').style.top = '50px';

    nHeight = document.getElementById('ShadowLayerContent').offsetHeight;
    nMarginTop = (((screen.availHeight - 180) - (nHeight)) / 2);
    document.getElementById('ShadowLayerContent').style.top = nMarginTop + 'px';
}
function Popup(elementText, largeImage, closeText, elementName) {

   document.getElementById('BigImage').src = largeImage;
   document.getElementById('PopupText').innerHTML = elementText;
  
    document.getElementById('CloseImage').title = closeText + ' ' + elementName;
    document.getElementById('CloseImage').alt = closeText + ' ' + elementName;

 
    document.getElementById('CloseBtn').title = closeText + ' ' + elementName;
    document.getElementById('CloseBtn').alt = closeText + ' ' + elementName;



    window.setTimeout("PopupDisplay()", 1);
    

/*
    alert((screen.availHeight));
    //alert((document.body.clientHeight));
    alert(document.getElementById('ShadowLayerContent').clientHeight);
    alert((screen.availHeight - document.getElementById('ShadowLayerContent').clientHeight));
    alert((screen.availHeight - document.getElementById('ShadowLayerContent').clientHeight) / 4);
*/

}

function Close(){
    document.getElementById('ShadowLayer').style.display = 'none';
    document.getElementById('ShadowLayerContent').style.display = 'none';

    document.getElementById('BigImage').src = 'i/Thumb.jpg';
}

function ClosePopupOnKeyDown(e) {
    if (!e) {
        if (window.event) {
            e = window.event;
        } else {
            return;
        }
    }
    if (typeof (e.keyCode) == 'number') {
        e = e.keyCode;
    } else if (typeof (e.which) == 'number') {
        e = e.which;
    } else if (typeof (e.charCode) == 'number') {
        e = e.charCode;
    } else {
        e = 0;
    }
    if (e == '27') {
        Close();
    }
}
