// 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($("#featured-work").length > 0){
				
				
				$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=62049118@N08&lang=en-us&format=json&jsoncallback=?", function(data){
				  $.each(data.items, function(i,item){
					
					if(i == 4){
					
						return false
						
					} else {
					var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");
					
					var sourceLarge = (item.media.m).replace("_m.jpg", ".jpg");
					
					$("#flickr-cont").append("<div id='flickr-"+i+"'><a href='"+ sourceLarge +"' title='"+ item.title+ "' rel='bhfancybox'><img src='"+sourceSquare+"'></a></div>")
					}
				
				
			  });
			  
			  
				$("#flickr-cont a[rel=bhfancybox]").fancybox({
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'titlePosition' 	: 'over',
					'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					}
				});
			  
			
			  
			});
			
			
			
			
			
			}
			
			
			
			if($("#portfolio-cont").length > 0){

			
				
			//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);
			
			
		},
		
		
		
		releaseTabs : function(e){
			
			if($("#artist-page").length > 0){
				
				firstTab ="nickwagner_bio";
				
				this.releaseTabs();
				
			}
			
			if (e != undefined) {
					e.preventDefault();
				}
			
			$("#photo-loader").show();
			$("#release-cont").hide().html('');
			
			if (firstTab != '') {
				var tab = firstTab
			} else {
				var tab = $(this).attr("rel");
			}
			
			//console.log(tab)
			
			var sUrl = "http://www.blackhivetattoo.com/wordpress/wp-content/themes/blackhive/"+tab+".php";
			
			$("#release-cont").load(sUrl, function(){
				
					$("#release-cont .lb").lightBox(
								{
									imageLoading: 'http://www.chimaira.com/the-infection/images/lightbox-ico-loading.gif',
									imageBtnClose: 'http://www.chimaira.com/the-infection/images/lightbox-btn-close.gif',
									imageBtnPrev: 'http://www.chimaira.com/the-infection/images/lightbox-btn-prev.gif',
									imageBtnNext: 'http://www.chimaira.com/the-infection/images/lightbox-btn-next.gif'
								}
							);
				
					firstTab = '';
					$("#photo-loader").hide();
					$("#release-cont").show();
				
			});
			
		},
		
		
		
		
		
		
		galleryBuild : function(itemID, setTitle){
			
			var sUrl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=b85a8851a9c86a2689fb8ce7cfa6e8d0&user_id=62049118@N08&photoset_id="+itemID+"&extras=url_sq%2Curl_o%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").html('');
					
											$("#portfolio-galleries").removeClass('loading');
											
											$("#portfolio-galleries").prepend("<h3>"+setTitle+"</h3><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_o +"' title='"+ item.title+ "' rel='bhfancybox'><img src='"+ item.url_sq +"'></a></li>")
													
												
												
											  });
										
										
											//add fancy box call here
											
											//$(".photo-gallery-cont a").
											
											$(".photo-gallery-cont a").fancybox({
												'transitionIn'		: 'none',
												'transitionOut'		: 'none',
												'titlePosition' 	: 'over',
												'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
													return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
												}
											});


											
											
											
										})
				
			
		},
		
	
		
		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();
})

