/**
 * gallery js
 *
 * Author - Tim Cross - 29 Apr 2010
 *
 * Created to control the display of gallery tabs
 *
 */


$(document).ready(function() {
						   
	LoadCategory('gallery_ourwork');
	
	$("#gallery_tabs").tabs({
			
		load: function(event, ui) {
			//$(".gallery_thumbs a[rel^='prettyPhoto']").prettyPhoto();
		},

		select: function(event, ui){
		
		}
							
	}).addClass('gallery_tabs');
	
	// Load gallery category
	function LoadCategory (gall_id){
		
		if(gall_id == 'gallery_ourwork'){
			gall_url = "./templates/content/gallery_ourwork.tpl";
		}else if(gall_id == 'gallery_embroidered'){
			gall_url = "./templates/content/gallery_library.tpl";
		}

		$.ajax({
		   type: "GET",
		   url: gall_url,
		   success: function(jsonData){
				$('#gallery_category_holder').html(jsonData);	
				GallerySelect(gall_id);
				LoadInitialGallery(gall_id);
		   }
		 });
		
	}
	
	// Load gallery category on click
	$(".gall_link").click(function() {
								   
		gall_id = $(this).attr('id');
		LoadCategory (gall_id);

	});
	
	
	// load initial gallery
	function LoadInitialGallery(gall_id){
		
		if(gall_id == 'gallery_ourwork'){
			galleryid = 3;
			gall_url = "./templates/ajax/gallery_list.php";
		}else if(gall_id == 'gallery_embroidered'){
			galleryid = 16;
			gall_url = "./templates/ajax/gallery_list_library.php";
		}
		
		$.ajax({
			data: "galleryid="+galleryid,
			type: "GET",
			url: gall_url,
			success: function(jsonData) {
				$('#gallery_holder').html(jsonData);	
				
			}
		});
	}
	
	// load gallery via select menu
	function GallerySelect(gall_id){
		
		if(gall_id == 'gallery_ourwork'){
			gall_url = "./templates/ajax/gallery_list.php";
		}else if(gall_id == 'gallery_embroidered'){
			gall_url = "./templates/ajax/gallery_list_library.php";
		}
		
		/*var cat_list_select = $('select#cat_list').selectmenu({
			select: function(event, options) {
				$.ajax({
					data: "galleryid=" + options.value,
					type: "GET",
					url: gall_url,
					success: function(jsonData) {
						// add the returned HTML (the new select)
						$('#gallery_holder').html(jsonData);	
						
					}
				});
			}
		});*/
		
		$('select#cat_list').click(function() {
			$.ajax({
				data: "galleryid=" + this.value,
				type: "GET",
				url: gall_url,
				success: function(jsonData) {
					// add the returned HTML (the new select)
					$('#gallery_holder').html(jsonData);	
					
				}
			});
		});
		
		
	}
	
	
});
