﻿var spyCam = {
	
	api_key: 'a01d83c781d7477a6745fb6cc598fee0',//'59f274e3514f672180c069409c7b745f', 
	secret: '27e29ce1c6485b75',
	user_id:'47320488@N04',
	container:'#spycam_flickr',
	num_pics: 1000000,
	flickr:function(){
	var _self = this;
		
		    fli_method = 'flickr.photosets.getPhotos',
		    set_id = '72157626746306429',//'72157626693726353';
			
			api_call = 'http://api.flickr.com/services/rest/?method=' + fli_method + '&api_key=' + this.api_key + '&photoset_id=' + set_id + '&extras=url_s,url_l&format=json&jsoncallback=?';
		
			$.ajax({
				type: "GET",
				url: api_call,
				dataType: "json",
				success: function (data) {
					
					var _container = _self.container;
					var pics = data.photoset.photo;
					
					//Image loaded handler
					img_loaded = function(){
						
						$(this).hide()
							   .fadeIn();
					};
					
					
					$(pics).each(function(i, photo){
					
						if (i < _self.num_pics) {
						var portrait = false;
						
						if(photo.width_s < photo.height_s) {
							var pic_width = 180;
							var pic_height = 268;
							portrait = true;
						} else {
							var pic_width = 180;
							var pic_height = 121;
						}
							
						var pic_url = photo.url_s;
						var pic_url_m = photo.url_l;
						var picM_width = photo.width_l;
						var picM_height = photo.height_l;
						
						var pic_id = "bi_photo_"+i; //Hard coded file suffix convention 
					
						var my_img = $('<img></img>').attr('src', pic_url);
						
						if ($.browser.msie){ //if MSIE add queries to fool IE and have it reload the img everytime, therefore no cashing for IE!! 
							my_img.attr('src', pic_url + '?random=' + (new Date()).getTime());	
						}
						
						if(portrait){
							my_img.css('position', 'relative');
						}
						
						my_img 
						.attr('height', pic_height)
						.attr('width', pic_width)
						.hide()
						.bind("load",img_loaded)
						.appendTo($('<a rel="flickr_group"></a>').addClass('lightbox-img-wrap')
																 .attr('href', pic_url_m));
						
						my_img.parent().appendTo(_container);
						
						
						//my_img.parent().lightBox();
						
						if (i==6) {
							$('#spycam-phrase-one').appendTo(_container).show();
						
						}
						
						if (i==31) {
							$('#spycam-phrase-two').appendTo(_container).show();
						
						}

						
						
						}else{
						
						return false;
						}
						
					});
					
				 //Add Fancybox to func
				 $("#spycam_flickr a").fancybox({
												'overlayColor': '#000',
												'transitionOut'	:	'elastic',
												'speedOut'		:	600 
												});
				 
					
				},
			});//End of Ajax	

	}//End of Flickr
};//End of Riser

$(document).ready(function() {

	spyCam.flickr();

});
