// global JS object
tattooGlobalJS = function() {


		//global vars
		var firstTab;

	return{
		
		/************************
			Init function
			-- attach event handlers
			-- fire drop down menu if present
			-- country select disable for forms
		
		************************/
		init: function(){
			

			//console.log("hello");
			
			
			if($("#portfolio-cont-page").length > 0){
			
				$("#portfolio-cont-page .photo-gallery-cont a img, #lightbox-nav").live("contextmenu",function(e){
					alert("All images are the property of Kian Forreal");
					return false;
				});
				
			};
			
			/*
			
			if($("#portfolio-cont-page").length > 0){
			
				$("#portfolio-cont-page .photo-gallery-cont a img, #lightbox-nav").live("contextmenu",function(e){
					alert("All images are the property of Kian Forreal");
					return false;
				});

			
				$.ajax(
					   {
							url : "http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=faf7deffc611943bcb4a4b590b99646f&user_id=56975929@N05&format=json&nojsoncallback=1",
							//url : "http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=cb67ca735825df9b505901fcd878d961&user_id=29549600@N02&format=json&nojsoncallback=1",
						   	dataType : "JSONP",
						   	success: function(data){
										tattooGlobalJS.galleryNav(data);
									},
							error: this.error,
							complete : this.galleryBuilt
						}
				)
			
			
			
			}
			*/
			
			
			
			if(typeof(flickrSet1) != 'undefined'){
				
				
				//alert(flickrSet1);
				
				tattooGlobalJS.galleryPage(flickrSet1);
				
			}
			
			
			//set nav
			
			$("#portfolio-list ul li a").live("click",function(e){
					
					e.preventDefault();
					
					var thisId = $(this).attr("data-set-id");
					var thisTitle = $(this).attr("data-set-title");
					
					if($("#gallery-"+thisId).length < 1){
						
						
						
						tattooGlobalJS.galleryBuild(thisId, thisTitle);
						
					} else {
						
						tattooGlobalJS.showModal("Gallery already loaded");
						
					}
					
					
					
			})
			
			//modal handle
			
			$("#error-modal").click(this.killModal);
			
			
		},
		
		galleryNav : function(data){
			
					
				
				data = eval("("+ data +")")
				
				//console.log(data);
				

				 $.each(data.photosets.photoset, function(i,item){
												
					//console.log(item.id);		
						
					$("#portfolio-list ul").append("<li><a href='http://www.flickr.com/photos/56975929@N05/sets/"+item.id+"' data-set-id='"+item.id+"' data-set-title='"+item.title._content+"'>"+item.description._content+"</a></li>")
					//$("#portfolio-list").append("<li><a href='http://www.flickr.com/photos/29549600@N02/sets/"+item.id+"'>"+item.id+"</a></li>")
				
					//tattooGlobalJS.galleryBuild(item.id, item.title._content);
				
				});
				

				//build latest set
				tattooGlobalJS.galleryBuild(data.photosets.photoset[0].id, data.photosets.photoset[0].title._content);
				
		
		},
		
		galleryBuild : function(itemID, setTitle){
			
			var sUrl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=faf7deffc611943bcb4a4b590b99646f&user_id=56975929@N05&photoset_id="+itemID+"&extras=url_sq%2Curl_m%2Ctags&format=json&jsoncallback=?"
			
			//var sUrl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=cb67ca735825df9b505901fcd878d961&user_id=29549600@N02&photoset_id="+itemID+"&extras=url_sq%2Curl_m%2Ctags&format=json&jsoncallback=?"
			//var sUrl = 
			
			
			$("#portfolio-galleries").addClass('loading');
			
			
			$.getJSON(sUrl, function(data){
					
		
					
					
											$("#portfolio-galleries").removeClass('loading');
											
											$("#portfolio-galleries").prepend("<h2>"+setTitle+"</h2><ul id='gallery-"+itemID+"' class='photo-gallery-cont clearfix'/>")
					
											var galleryId = "gallery-"+itemID;
											
											$.each(data.photoset.photo, function(i,item){
												
													
													//var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
													
													//var sourceLarge = (item.media.m).replace("_m.jpg", ".jpg");
													
													$("#"+galleryId).append("<li><a href='"+ item.url_m +"' title='"+ item.title+ "'><img src='"+ item.url_sq +"'></a></li>")
													
												
												
											  });
										
										
											//console.log("gallery built");
											$(".photo-gallery-cont a").lightBox(
													{
														imageLoading: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/ajax-loader.gif',
														imageBtnClose: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_close.gif',
														imageBtnPrev: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_prev.gif',
														imageBtnNext: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_next.gif'
													}
												);

											
											
											
										})
				
			
		},
		
		galleryPage : function(itemID){
			
			var sUrl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=faf7deffc611943bcb4a4b590b99646f&user_id=56975929@N05&photoset_id="+itemID+"&extras=url_sq%2Curl_m%2Ctags&format=json&jsoncallback=?"
			
			//var sUrl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=cb67ca735825df9b505901fcd878d961&user_id=29549600@N02&photoset_id="+itemID+"&extras=url_sq%2Curl_m%2Ctags&format=json&jsoncallback=?"
			//var sUrl = 
			
			
			$("#portfolio-galleries").addClass('loading');
			
			
			$.getJSON(sUrl, function(data){
					
		
					
					
											$("#portfolio-galleries").removeClass('loading');
											
											$("#portfolio-galleries").prepend("<ul id='gallery-"+itemID+"' class='photo-gallery-cont clearfix'/>")
					
											var galleryId = "gallery-"+itemID;
											
											$.each(data.photoset.photo, function(i,item){
												
													
													//var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
													
													//var sourceLarge = (item.media.m).replace("_m.jpg", ".jpg");
													
													$("#"+galleryId).append("<li><a href='"+ item.url_m +"' title='"+ item.title+ "'><img src='"+ item.url_sq +"'></a></li>")
													
												
												
											  });
										
										
											//console.log("gallery built");
											$(".photo-gallery-cont a").lightBox(
													{
														imageLoading: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/ajax-loader.gif',
														imageBtnClose: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_close.gif',
														imageBtnPrev: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_prev.gif',
														imageBtnNext: 'http://kianforreal.awesomedudehq.com/wp-content/themes/kianforreal/images/lb_next.gif'
													}
												);

											
											
											
										})
				
			
		},
		
		galleryBuilt : function(e){
			
				
		},
		
		showModal : function(msg){
		
				
				$("#error-modal h2").text(msg);
				$("#error-modal").show()
				
		},
		
		killModal : function(e){
				$("#error-modal").hide()
		}
		
		
		
		
			
	 }

}();

// load on document ready
$(function() {
	tattooGlobalJS.init();
})

