var MaxHeightNext = -1;
var FileLocationNext = '';
var MaxHeightNext2 = -1;
var FileLocationNext2 = '';

function SetPositions(isresize){
    var myWidth = 0, myHeight = 0;
    if( typeof(window.innerWidth) == 'number'){
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    CurrentWidth = myWidth;
    SetMainImageSize(myHeight, isresize);
    SetScroller(myWidth);
}

function SetScroller(width){
    var o = document.getElementById('iframescroller');
    var ItemCount = (Math.round(width/ItemWidth)) - 1;
    ThumbsToDisplay = ItemCount;
    if(ThumbsToDisplay > ImageCount){
        ThumbsToDisplay = ImageCount;
        ItemCount = ThumbsToDisplay;
    }
    var w = ItemCount * ItemWidth;
    o.style.width = (w) + 'px';

}

function ShowImage(){
    document.getElementById('mainimagepad').style.visibility = 'visible';
    document.getElementById('mainimagetable').width = (document.getElementById('mainimage').width + 10) + 'px';
    SetCaption(FileCaption[CurrentImage - 1], FileCommentCount[CurrentImage - 1]);
}

function ForceShowImage(){
    ShowImage();
}

function SetCaption(text, c){
    if(text == ''){
        //document.getElementById('captiontext').style.display = 'none';
        document.getElementById('captiontext').innerHTML = '<span class="commentpop"><a href="javascript:CommentPop()">(' + c + ' kommentarer. Klicka h&auml;r f&ouml;r att skriva/l&auml;sa kommentarer)</a></span>';
        document.getElementById('captiontext').style.display = ''; 
    }else{
        document.getElementById('captiontext').innerHTML = text + ' <span class="commentpop"><a class="commentpop" href="javascript:CommentPop()">(' + c + ' kommentarer. Klicka h&auml;r f&ouml;r att skriva/l&auml;sa kommentarer)</a></span>';
        document.getElementById('captiontext').style.display = '';
    }
}

function SetMainImageSize(h, isresize){
    var nh = h - 280;
    var nh2 = h - 280;
    var nh3 = h - 280;
    
    //document.getElementById('mainimagepad').style.height = (nh + 90) + 'px';
    document.getElementById('mainimagepad').style.height = (nh + 80) + 'px';

    if(nh > MaxHeight){
        nh = MaxHeight;
    }
    
    if(nh2 > MaxHeightNext){
        nh2 = MaxHeightNext;
    }
    
    if(nh3 > MaxHeightNext2){
        nh3 = MaxHeightNext2;
    }    
    
    if(isresize != 1){
        document.getElementById('mainimage').src = '/photos/imageloader.aspx/imgloader.aspx?h=' + nh + '&url=' + BigImage;
        document.getElementById('nextimage').src = '/photos/imageloader.aspx/imgloader.aspx?h=' + nh2 + '&url=' + FileLocationNext;
        document.getElementById('nextimage2').src = '/photos/imageloader.aspx/imgloader.aspx?h=' + nh3 + '&url=' + FileLocationNext2;
    }
    document.getElementById('mainimage').style.height = nh + 'px';
    setTimeout('ForceShowImage()', 500);
}

function AdvancePos(){
    var o = top.frames['iframescroller'];
    o.AdvancePos();
}

function DecPos(){
    var o = top.frames['iframescroller'];
    o.DecPos();
}        

function LoadImage(url, mh){
    BigImage = url;
    MaxHeight = mh;
    SetPositions();
}

function PrevImage(){
    if(CurrentImage > 1){
        CurrentImage--;
        LoadImageById(CurrentImage);
    }
}

function NextImage(){
    if(CurrentImage < ImageCount){
        CurrentImage++;
        LoadImageById(CurrentImage);
    }
}

function LoadImageById(id){
    document.getElementById('mainimagepad').style.visibility = 'hidden';
    CurrentImage = id;
    top.frames['iframescroller'].MarkImage(CurrentImage);
    LoadImage(FileLocation[CurrentImage - 1] + '.jpg', FileMaxHeight[CurrentImage - 1]);
    MaxHeightNext = FileMaxHeight[CurrentImage + 1];
    FileLocationNext = FileLocation[CurrentImage + 1] + '.jpg';
    MaxHeightNext2 = FileMaxHeight[CurrentImage + 2];
    FileLocationNext2 = FileLocation[CurrentImage + 2] + '.jpg';
    SetCurrentImageIdDisplay();
}

function CommentPop(){
    window.open('/photos/commentpop.aspx?album=' + AlbumID + '&file=' + FileLocation[CurrentImage - 1], '_blank', 'location=0,toolbar=0,scrollbars=auto,resizable=yes,width=600,height=600');
}

var FileLocation = new Array();
var FileMaxHeight = new Array();
var FileMaxWidth = new Array();
var FileCaption = new Array();
var FileCommentCount = new Array();


var message="";

function Init(){
    MaxHeightNext = FileMaxHeight[CurrentImage + 1];
    FileLocationNext = FileLocation[CurrentImage + 1] + '.jpg';
    MaxHeightNext2 = FileMaxHeight[CurrentImage + 2];
    FileLocationNext2 = FileLocation[CurrentImage + 2] + '.jpg';
    SetPositions(0);
    if(top.frames['iframescroller']){
        top.frames['iframescroller'].MarkImage(CurrentImage);
    }
    SetCurrentImageIdDisplay();
    setTimeout("document.getElementById('headtable').style.display = '';", 100);
}

function SetCurrentImageIdDisplay(){
    document.getElementById('spancurrentimage').innerHTML = '<a href="' + CurrentImage + '.html">' + CurrentImage + '</a>';
}

function clickIE()
 
{if (document.all)
{(message);return false;}}
 
function clickNS(e) {
if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.  onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu  =clickIE;}
 
document.oncontextmenu=new Function("return false")