function buildClueTips(id, type) {
	var handle=id+' '+type;
	$(handle).each( function() {
		if ($(this).attr('title')!=='') {
			var fieldname=$(this).attr('name');
			$(handle+'[name='+fieldname+']').cluetip();
		}
	});
}

function addClueTips(id) {
	buildClueTips(id, "input[type=text]");
	buildClueTips(id, "input[type=password]");
	buildClueTips(id, "select");
}

$(document).ready(function() {

	if ($(".newsarea").length>0) {
		$(".newsarea").vTicker({
			speed: 3000,
			pause: 5000,
			showItems: 3,
			animation: 'fade',
			mousePause: true,
			height: 250,
			width: 250,
			direction: 'up'
		});
	}

	if ($("#cluetipform").length>0) {
		$.fn.cluetip.defaults.activation='focus';
		$.fn.cluetip.defaults.arrows=true;
		$.fn.cluetip.defaults.splitTitle='|';
		$.fn.cluetip.defaults.dropShadowSteps='3';
		$.fn.cluetip.defaults.width='220';
		
		if ($("form#cluetipform").length>0) {
			addClueTips("form#cluetipform");
		}
	}
	
	if ($("ul", ".adminnav").length==0) {
		$(".adminnav").hide();
	}

	if ($("#sorttable").length>0) {
		if ($("#sorttable tbody tr").length>0) {
			$("#sorttable").tablesorter({
				headers: {
					0: { sorter: false }
				},
				sortList: [[1,0]],
				widgets: ['zebra'],
				widgetZebra: { css: ['odd', 'even'] }		
			});
		} else {
			$(".blockUI").show();
			window.location = ($('#addlink').attr('href'));
		}
	
		if ($("#sorttable tbody tr").length>10) {
			$("#sorttable").tablesorterPager({size: 10, container: $('#pager'), seperator: ' of ', positionFixed: false});
			$("#pager").show();
		} else {
			$("#pager").hide();
		}
		
		$("#sorttable").tablesorterFilter({filterContainer: $("#filter-box"),
            filterClearContainer: $("#filter-clear-button"),
            filterColumns: [1,2,3],
            filterCaseSensitive: false
        });	
	}
	
	if ($("table#sorttable tbody a.deletelink").length>0) {
		$("table#sorttable tbody a.deletelink").click(function () {
			var message="Are you sure you want to delete this report?\n";
			message+="\nAll information will be deleted.";
			if (!(confirm(message))) {
				return (false);
			}
		});
	}

	if ($('#cluetipform textarea.htmleditor').length>0) {
		$('#cluetipform textarea.htmleditor').fck({
			path: '/packages/fckeditor/',
			config: {
				EditorAreaCSS: themeFolder+'/styles/htmleditor.css',
				StylesXmlPath: themeFolder+'/styles/htmleditor.xml',			
				toolbar: 'Events1'
			}
			
		});
	}
	
	if ($('.deleteConfirm').length>0) {
		$('.deleteConfirm').click(function() {
			if (!confirm('Are you sure you want to delete this item')) {
				return false;
			}
		});
	}

	if ($('.multiselect').length>0) {
		$('.multiselect').multiselect2side({
			selectedPosition: 'left',
			moveOptions: true,
			labelTop: '+ +',
			labelBottom: '- -',
			labelUp: '+',
			labelDown: '-',
			labelsx: '* Selected *',
			labeldx: '* Available *',
			search: "Find: "
		});
	}
	
	if ($('.publicgalleryimgblockui').length>0) {
		$('.publicgalleryimgblockui').hide();
	};
	
	if ($('.publicgallerythumb').length>0) {
		$('.publicgallerythumb').click(function() {
			var id='#gallery-'+this.href.replace(/.*=/, "")+'-blockui';
			$.blockUI({
				message: $(id),
				css: { 
					padding:        0, 
					margin:         '0 auto', 
					width:          '450px', 
					top:            '50px', 
					textAlign:      'center', 
					color:          '#000', 
					border:         '3px solid #aaa', 
					backgroundColor:'#fff', 
					cursor:         'auto' 
    				}
			});
			$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI);
			$('#gallery_'+this.href.replace(/.*=/, "")).anythingSlider({
				resizeContents: false,
				buildNavigation: false,
				autoPlay : false,
				startText : "Start Slide Show",
				endText : "Stop Slide Show",
				buildStartStop : false

			});
			return(false);
		});
	}
	
	if ($('.cancelBlockUI').length>0) {
		$('.cancelBlockUI').click(function() {
			$.unblockUI();
			return(false);
		})
	}
	
	if ( ($('#catmenu').length>0) && ($('#catnoitems').length>0) ) {
		if ($('option', '#catmenu').length>0) {
			$('#catmenu').show();
			$('#catnoitems').hide();
		} else {
			$('#catmenu').hide();
			$('#catnoitems').show();
		}
	}

	$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
	var ajaxInitComplete = true;
});

