/*
* Custom jQuery functions
*/
$(document).ready(function() {
	if ($("#stainsolutionSelector").size() > 0) {
		//$("#stainsolutionSelectorContent select").uniform();
		fillStainFinder();
		$(function(){ $("#stainsolutionSelectorContent select").uniform(); });
	}
	 $('#homeSlideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
});


/* Sitemap */
function toggleSitemap(id, aId) {
	if($('#'+id).css('display') == 'none') {
		$('#'+id).css('display','block');
		$('a#'+aId+' img.toggleButton').attr('src',imgPath+'sitemap/min.png');
	}else{
		$('#'+id).css('display','none');
		$('a#'+aId+' img.toggleButton').attr('src',imgPath+'sitemap/plus.png');
	}
}

function fillStainFinder() {
	$.ajax({
		type: "GET",
		url: rootPath+'page/ajax.php',
		data: "action=getStainGroups",
		dataType: 'json',
		success: function(msg){
			$('select#stainGroup').html('');
			var totalGroups = msg.length;
			var selectedItems = '';
			for(var i=0;i<totalGroups;i++) {
				// TODO fill selectlist
				//alert(msg[i]['projectGroupId']);
				//alert(msg[i]['name']);
				
				selectedItems += '<option value="'+msg[i]['projectGroupId']+'">'+msg[i]['name']+'</option>';
			}
			$('#uniform-stainGroup span').html(msg[0]['name']);
			$('select#stainGroup').html(selectedItems);
			fillStains();
		}
	});
}

function fillStains() {
	var groupId = 0;
	// Get groupId from selectlist
	groupId = $('select#stainGroup').val();
	
	// Get the stains
	$.ajax({
		type: "GET",
		url: rootPath+'page/ajax.php',
		data: "action=getStains&groupId="+groupId,
		dataType: 'json',
		success: function(msg){
			$('select#stainItem').html('');
			var totalStains = msg.length;
			var selectedItems = '';
			for(var i=0;i<totalStains;i++) {
				// TODO fill selectlist
				// alert(msg[i]['projectItemId']);
				// alert(msg[i]['name']);
				selectedItems += '<option value="'+msg[i]['projectItemId']+'">'+msg[i]['name']+'</option>';
			}
			$('#uniform-stainItem span').html(msg[0]['name']);
			$('select#stainItem').html(selectedItems);
		}
	});
}
