function preload(i) { 
	var img = new Image();
	img.src = photoDir+files[i];
	var img2 = new Image();
	img2.src = largeDir+files[i];
}

$(document).ready(function() {
	// init fotos
	preload(1);
	
    // vergroot thumb
    $("#thumb_image").click(function() {
        $("#product_image").attr("src", photoDir+files[thumbKey]);
        $("#product_big_image").attr("src", largeDir+files[thumbKey]);
        $('#tech_image').hide();
        photoKey=thumbKey;
        return false;
    });

	// controls normal+large images
    $('DIV.img_controls A.next_image,A.next_bigimage,DIV.thumb_controls A.next_thumb').click(function() {
		// loopje maken voor laatste
		if (photoKey == photoNr) {
    		var imgsrc = photoDir+files[1];
    		var bigsrc = largeDir+files[1];
        	photoKey=1;
		} else {
			var imgsrc = photoDir+files[photoKey+1];
			var bigsrc = largeDir+files[photoKey+1];
        	photoKey++;
		}
		$("#product_image").attr("src", imgsrc);
    	$("#product_big_image").attr("src", bigsrc);
		preload(photoKey);
		return false;
    });

    $('DIV.img_controls A.prev_image,A.prev_bigimage,DIV.thumb_controls A.prev_thumb').click(function() {
		if(photoKey == 1) {
			var imgsrc = photoDir+files[photoNr];
			var bigsrc = largeDir+files[photoNr];
    		photoKey=photoNr;
		} else {
    		var imgsrc = photoDir+files[photoKey-1];
    		var bigsrc = largeDir+files[photoKey-1];
    		photoKey--;
		}
		$("#product_image").attr("src", imgsrc);
    	$("#product_big_image").attr("src", bigsrc);
		preload(photoKey);
		return false;
    });

 	// controls for thumbs
    $('DIV.thumb_controls A.next_thumb').click(function() {
        if (thumbKey == photoNr) {
            $("#thumb_image").attr("src", thumbDir+files[1]);
            thumbKey=1;
        } else {
            $("#thumb_image").attr("src", thumbDir+files[thumbKey+1]);
            thumbKey++;
        }
        preload(thumbKey);
        return false;
    });

    $('DIV.thumb_controls A.prev_thumb').click(function() {
        if(thumbKey == 1) {
            $("#thumb_image").attr("src", thumbDir+files[photoNr]);
            thumbKey=photoNr;
        } else {
            $("#thumb_image").attr("src", thumbDir+files[thumbKey-1]);
            thumbKey--;
        }
        preload(thumbKey);
        return false;
    });

    //show hide big_image
    $('.shBigImg').click(function() {
        $('#big_img_container').toggle();
        return false;
    });
    
    //show hide tech_image
    $('#techSpec,#tech_image').click(function() {
        $('#tech_image').toggle();
        return false;
    });
    
    // show/hide product info
    $('#jProd_info').click(function() {
        $('DIV.product_info').toggle();
        $('DIV.product_txt').toggle();
        $('A.prev_image').toggle();
        return false;
    });
    
});