var images = [
    ['rajred', 'Copyright: Raj N'], 
    ['xterra', 'Cuker Interactive'], 
    ['wedcouch', 'Photographer: Hung Tran'], 
    ['nasha', 'Copyright: Nasha Apparel'],  
    ['sun', 'Photographer: Elijah Star'],  
    ['wall', 'Photographer: Elijah Star'], 
    ['smoke', 'Photographer: Hung Tran'],        
    ['shernide', 'Copyright: Shernide Delva'],
    ['david', 'Photographer: Julia Britz'],   
	['sepia', 'Copyright: Bridgman'], 
    ['dip', 'Photographer: Hung Tran'],  
    ['lauren', 'Photographer: Elijah Star'],  
    ['boobs', 'Photographer: Elijah Star'],  
    ['rachel', 'Photographer: Andrea Britz'],     
    ['preg', 'Photographer: Jared Kuolt'], 
    ['jess', 'Photographer: Elijah Star'],     
    ['garden', 'Photographer: Julia Britz'],
    ['raj', 'Copyright: Raj N'], 
    ['bwbeachwed', 'Photographer: Hung Tran'], 
    ['millsap2', 'Photographer: Elijah Star'],     
    ['grad', 'Photographer: Jared Kuolt'], 
    ['rb', 'Photographer: Zion Ama Dio'],  
    ['jason', 'Photographer: Jared Kuolt'],     
    ['plant', 'Photographer: Julia Britz'],  
    ['high', 'Photographer: Elijah Star'],    
                          
];
var apreload = [];
var bpreload = [];
var current = 0;

$ = function (id) {
    return document.getElementById(id);
};

preload_images = function () {
    for(i in images){
        apreload[i] = new Image();
        apreload[i].src = 'images/portfolio/' + images[i][0] + '_after.jpg';
        
        bpreload[i] = new Image();
        bpreload[i].src = 'images/portfolio/' + images[i][0] + '_before.jpg';
    }
};

previous_photo = function () {
    current--;
    if(current < 0) current = images.length - 1;
    show_photo(false);
    return false;
};

next_photo = function () {
    current++;
    if(current >= images.length) current = 0;
    show_photo(false);
    return false;
};

show_photo = function (before) {
    var img = $('img');
    if(before) {
        img.src = bpreload[current].src;
    } else {
        img.src = apreload[current].src;
    }
    $('caption').innerHTML = images[current][1];
    
};

init = function (){
    preload_images();
    show_photo(false);

    $('img').onmouseover = function () {show_photo(true);}
    $('img').onmouseout = function () {show_photo(false);}
    
};

formcheck = function () {
    var errors = '';
    if($('name').value == '') errors += 'Please enter your name.\n';
    if($('contact').value == '') errors += 'Please enter a contact method.\n';
    if(errors == '') return true;
    
    alert(errors);
    return false;
};
