

$(function(){

var imgs;	
				var totalWidth = 0;
				var imgWidth = 0;
				var imgWidthString ='';
				var index = 0;
				var count = 0;
				var margin = 10;
				var leftEdge = 0;
				
				var height = 0;
                
                $("p.loadCheck").text("Loading...");
                
                //assign your api key equal to a variable
                var apiKey = 'e7b807a6d1f589b94704901b786f1187';
                
                //the initial json request to flickr
                //to get your latest public photos, use this request: http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key=' + apiKey + '&user_id=29096781@N02&per_page=15&page=2&format=json&jsoncallback=?
				$.getJSON('http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + apiKey + '&user_id=49420626%40N03&tags=cr&tag_mode=all&content_type=1&extras=description&format=json&jsoncallback=?',
                function(data){
                
                    //loop through the results with the following function
                    $.each(data.photos.photo, function(i,item){
                    
                        //build the url of the photo in order to link to it
                        var photoURL = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_d.jpg';
                        
                        
                        
                        var photos ='<div class="image-node"><div class="image-img"><img src="' + photoURL + '" class="imagefield imagefield-field_image_large" height="200" /></div><div class="image-teaser">' + item.description._content + '</div></div>';
                        
                        $(photos).appendTo('#slider-inner');
                        
                        
                        
                        $("p.loadCheck").text("Loaded!");
                     
                  });
                  
                  imgs = $(".image-img img");
                  $(imgs).each(function(index){		
                  			
							imgWidth =  $(this).parents(".image-node").width();
							var imgWidth2 = $(this).parents(".image-node").outerWidth(true);
							imgWidthString += 'Image: ' + index + ' Width: ' + imgWidth2 + ' / ';
							
							
							
							//$("p.imgCount").text("Number of Images: " + count);
							
							//$("p.imgWidth").text("Image: " + count + " Width: " + imgWidth);
							//$("p.imgWidth").text(imgWidthString);
							
					});
					
                  count = imgs.length;
                  var text = $(imgs[index]).parents(".image-node").children(".image-teaser").html();
                  $('#slider-caption').html(text);
                  $("p.imgCount2").text("Count = "+count);
                  
                });
				
				
				
				
				
				
				
				
				//slide();
				
				$('.prev-image').click(function () {
				$('#slider-caption').hide();
				var currentImage = parseInt(imgs[index-1].width) + margin;
				var text = $(imgs[index-1]).parents(".image-node").children(".image-teaser").html();
				$("p.leftEdge").text(currentImage);
				if (index <= 0) {	
					index = 0;
					$('p.indexNum').text("At the Beginning!");
						
						} else {
					index--;
					
					$('#slider-inner').animate({'left':"+="+currentImage});
					$('p.indexNum').text(index);
					$('#slider-caption').html(text);
					$("#slider-caption").fadeIn("slow");
					}
				
				});
                
                
                $('.next-image').click(function () {
                	$('#slider-caption').hide();
                	var text = $(imgs[index+1]).parents(".image-node").children(".image-teaser").html();	
					var currentImage = parseInt(imgs[index].width) + margin;
					$("p.leftEdge").text(currentImage);
					if(index >= count-1){
						$('p.indexNum').text("At the End");
					
					} else {
									
					$('#slider-inner').animate({"left":"-="+currentImage});
					$('p.indexNum').text(index);
					$('#slider-caption').html(text);
					$("#slider-caption").fadeIn("slow");
					index++;
					}
				
				});
        		     
            });
           

