﻿//$(window).load(function(){if($.query.get('fade')!="off"){$("#images").find("img:not(:first)").fadeTo(0,0.3)}});function slide(a){if($("#images").is(":animated")){return}var b="#image"+a var c=$(b);var d=c.offset().left-$("#imagewrapper").offset().left if(d==0){return}$("#numbernav").find("a").attr("class","sublink");$("#sublink"+a).attr("class","sublink-active");Cufon.replace('#numbernav a',{fontFamily:'Avenir-Heavy',hover:true});if($.query.get('fade')!="off"){$("#images").find("img:not("+b+")").fadeTo(500,0.3)}$("#images").animate({marginLeft:"-="+d},500);if($.query.get('fade')!="off"){c.fadeTo(1000,1.0)}}

/// <reference path="jquery-intellisense.js"/>


$(document).ready(function(){
        $("#linkPrevious").hide();
});
  
var slideBusy = false;
  
function slideToNext()
{
    if ($("#images").is(":animated")){return;}
  
    if (slideBusy == true){return;}
    slideBusy = true;
    
    $("#linkPrevious").show();
    
    // myImages[] and current are the global variables
    // find current position inside the array
    var currentIndex = indexInArray(myImages, current)
    
    // slide to the next array position
    currentIndex = currentIndex + 1
    if (currentIndex >= myImages.length) 
    {
        slideBusy = false;
        return;
    }
    
    var newValue = myImages[currentIndex];
    var values = newValue.split("-");
    slide(values[0], values[1]);
    
    // set new current position, we don't send the index, because the index
    // value can be changed by the user
    current = newValue;
    slideBusy = false;

    
}
    
 
function slideToPrevious()
{
    if ($("#images").is(":animated")){return;}
    if (slideBusy == true){return;}
    slideBusy = true;
    
    $("#linkNext").show();
    
    // myImages[] and current are the global variables
    // find current position inside the array
    var currentIndex = indexInArray(myImages, current)
    
    // slide to the next array position
    currentIndex = currentIndex - 1
    if (currentIndex < 0) 
    {
        slideBusy = false;
        return;
        
    }
    var newValue = myImages[currentIndex];
    var values = newValue.split("-");
    slide(values[0], values[1]);
    
    // set new current position, we don't send the index, because the index
    // value can be changed by the user
    current = newValue;
    slideBusy = false;
    

}
    
 
function indexInArray(theArray, theValue){
    var arLength = theArray.length;
    for(var i=0; i<arLength; i++)
    {
        if (theArray[i] == theValue){
            return i;
            }
    }
    return 0;
} 

function slide(imageID, numberofSiblings)
{
    if (window.columnElement === undefined) {columnElement = 'img';}
    
    //next previous stuff
    current = imageID + "-" + numberofSiblings;
    var currentIndex = indexInArray(myImages, current)
    if (currentIndex <= 0)
        {$("#linkPrevious").hide();$("#linkNext").show();}
    else
        {$("#linkPrevious").show()}
    
    if (currentIndex >= (myImages.length - 1))
        {$("#linkNext").hide();$("#linkPrevious").show();}
    else
        {$("#linkNext").show()}
    
    // prevent from running
    if ($("#images").is(":animated")){return;}

    // grab image id, find location of current image
    // set margin left
    var imageSelector = "#image" + imageID 
    var actualImage = $(imageSelector);
    var offsetLeft = actualImage.offset().left - $("#imagewrapper").offset().left
    if (offsetLeft == 0)  {return;}
    

    // change color of links
    $("#numbernav").find("a").attr("class", "sublink");
    $("#sublink" + imageID).attr("class", "sublink-active");
   
    Cufon.replace('#numbernav a', {fontFamily: 'Avenir-Heavy', hover: true});

    // prepare images for fading
    var maxIndex = Number(imageID) + Number(numberofSiblings);
    
    var imageElements;
    if (columnElement == "img")
     {imageElements = $("#images").find('img');}
    else
     {imageElements = $("#images").children(columnElement);}

    imageElements.each(function(index)
    {
        if (index < imageID || index > maxIndex)
        {
            $(this).attr("class", "image");
        }
        else
        {
                        
            $(this).attr("class", "image-active");
        }
    });
    

    $(".image").fadeTo(600, 0.3);

    // grab offset of container, and subtract to find the actual image offset
    $("#images").animate({marginLeft: "-=" + offsetLeft}, 400);
    
    $(".image-active").fadeTo(600, 1.0);

}

function InitialDim(imageID, numberofSiblings)
{
    if (window.columnElement === undefined) {columnElement = 'img';}
    
    // prepare images for fading
    var maxIndex = Number(imageID) + Number(numberofSiblings);
    
    var imageElements;
    if (columnElement == "img")
     {imageElements = $("#images").find('img');}
    else
     {imageElements = $("#images").children(columnElement);}

    imageElements.each(function(index)
    {
        if (index < imageID || index > maxIndex)
        {

            $(this).attr("class", "image");
        }
        else
        {
            $(this).attr("class", "image-active");
        }
    });    
    $(".image").fadeTo(0, 0.3);
    $(".image-active").fadeTo(0, 1.0);
}