
//Byter en bilds källbild
function swap(ID,ImgPath)
{
    try
    {
	    document.getElementById(ID).src=ImgPath;
	}
	catch(err)
    {
    }
}

//Byter en länks källa
function swapLink(ID,URL)
{
	document.getElementById(ID).href=URL;
}



//--- Bildspel -----------------------------------------------------------
var CurrentSlideshowImage = 1;
var SlideshowImages = '';
var preloaded_pics; 

function SetImages(images)
{
    SlideshowImages=images;
    var Imagepaths = images.split(',');
    var preloaded_pics =  new Array(Imagepaths.length);
    for(i=0;i<Imagepaths.length;i++)
    {
        preloaded_pics[i] = new Image();
        preloaded_pics[i].src="landscape3.gif";
    }
}

function Next(ID,IDLink,total,w,h)
{
    var nextImage = CurrentSlideshowImage;
    if(nextImage<total) 
    {
        nextImage++;
    }
    else
    {
        nextImage=1;
    }
    
    var Imagepaths = SlideshowImages.split(',');

    swapAndResize(ID,Imagepaths[nextImage-1],w,h,nextImage);
    swapLink(IDLink,Imagepaths[nextImage-1]);
}

function Prev(ID,IDLink,total,w,h)
{
    var prevImage = CurrentSlideshowImage;
    if(prevImage>1) 
    {
        prevImage--;
    }
    else
    {
        prevImage=total;
    }
    
    var Imagepaths = SlideshowImages.split(',')

    swapAndResize(ID,Imagepaths[prevImage-1],w,h,prevImage)
    swapLink(IDLink,Imagepaths[prevImage-1]);
}

function swapAndResize(ID,ImgPath,w,h,c)
{
    var widthRatio,heightRatio;
    var newimage;
    var newwidth,newheight
    newimage = new Image();
    newimage.src = ImgPath;
           
    CurrentSlideshowImage = c;           
                      
    widthRatio = newimage.width / w; 
    heightRatio = newimage.height / h;


    if (widthRatio > heightRatio)
    {
        //Anpassa efter bredd
        if (newimage.width >= w)
        {
            newwidth = parseInt(newimage.width / widthRatio+0.5);
            newheight = parseInt( newimage.height / widthRatio+0.5);
        }
        else
        {
            newwidth = newimage.width;
            newheight =  newimage.height;    
        }        
    }
    else
    {
        //Anpassa efter höjd
        if (newimage.height >= h)
        {
            newwidth = parseInt(newimage.width / heightRatio+0.5);
            newheight = parseInt(newimage.height / heightRatio+0.5);
        }
        else
        {
            newwidth = newimage.width;
            newheight =  newimage.height;    
        }        

    }    
    
	document.getElementById(ID).width=newwidth;
	document.getElementById(ID).height=newheight;    
	setTimeout('document.getElementById("'+ ID +'").src="'+newimage.src+'";',5);
}



function flashObject(moviePath, width, height) {
    return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '">'+
          '<param name="movie" value="' + moviePath  + '" />'+
          '<param name="quality" value="high" />'+
          '<param name="menu" value="false" />'+
          '<param name="wmode" value="opaque" />'+
          '<param name="bgcolor" value="#ffffff" />' +
          '<param name="scale" value="noborder" />' +
          '<param name="allowScriptAccess" value="sameDomain" />' +
          '<embed src="' + moviePath  + '" width="' + width + '" height="' + height + '" wmode="opaque" quality="high" scale="noborder" allowScriptAccess="sameDomain" bgcolor="#ffffff" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>'+
        '</object>';
}



/*PDF*/
function AddOrRemoveFromPdf(elm, id, add, remove, lcid)
{
    var sLocation = "PrintToPDF/AddOrRemoveFromPdf.aspx?id=" + id + "&lcid=" + lcid;
    
    //only use text add/remove if both are supplied
    //else assume image link
    if(add.length > 0 && remove.length > 0)
    {
        var ix = -1;
        
        try
        {
            ix = elm.innerText.indexOf(add);
        }
        catch(e)
        {
            try
            {
                ix = elm.innerHTML.indexOf(add);
            }
            catch(e2)
            {
                return;
            }
        }
            
        if(ix >= 0)
        {
            elm.innerHTML = remove + " &#187;";
            sLocation += "&mode=add";
        }
        else
        {
            elm.innerHTML = add + " &#187;";
            sLocation += "&mode=delete";
        }
    }
    else
        sLocation += "&mode=add";
    
    var winPdf = window.open(sLocation, "winPdfPop", "height=75,width=100,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no", true);
}

function RemoveFromPdf(id, lcid)
{
    var sLocation = "PrintToPDF/AddOrRemoveFromPdf.aspx?mode=delete&id=" + id + "&lcid=" + lcid;
    var winPdf = window.open(sLocation, "winPdfPop", "height=75,width=100,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no", true);
}

function AddRangeToPdf(range, lcid)
{
    var sLocation = "PrintToPDF/AddOrRemoveFromPdf.aspx?mode=addrange&id=" + range + "&lcid=" + lcid;
    var winPdf = window.open(sLocation, "winPdfPop", "height=75,width=100,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no", true);
}
