$(document).ready(function() {

	var resid = $('input#resourceid').val();
	var parid = $('input#parentid').val();

	// var path = new Array();
	var path 	= $.parseJSON($('#path').html()); // use the path set on the template files

	var links	= [];

	var url		= window.location.href.split('/');  // i.e. the last 4 url values that make up the query
	var page 	= url[url.length-1];

	$('.trailitem a').each(function() {
		link 	= $(this).attr('href').split('&');
		links.push({'lnk' : link[0]});
	});

	if (resid == 1) { // use resourceid if it is home
		menuitem = $('.nav li a[href="/"]');
	}
	else
	if (parid == 1) {
		menuitem = $('.nav li a[href="/' + resid + '"]');
	}

	if (path != null) { // if the path is nul i.e. not a template, use the trail items
		if ((parid != 1) && (path[1])) {
			menuitem = $('.nav li a[href="/' + path[1] + '"]');
		}
	}
	else
	if (links != null){
		if ((parid != 1) && (links[1])) {
			menuitem = $('.nav li a[href="' + links[1]['lnk'] + '"]');
		} else {
			menuitem = $('.nav li a[href="/"]');
		}
	}

	// highlighting for main menu
	menuitem.addClass('river-blue');

	$('.nav-sidebar li a').each(function() {

		var href = $(this).attr('href');

		if (('/' + page) == href)
			$(this).addClass('river-blue');

	});

	$('.thumb-menu').each(function(index) {
		$(this).hover(function() {
			var id = $(this).next('img').attr('id').substr(1); // r
			$(this).hide();
			$('#hover_' + id).show();
		}, function() {
			$(this).show();
			$('.image_hover').hide();
		});
	});

	// Larger thumbnail preview

	$("ul.thumb li").hover(
			function() {
				$(this).css({
					'z-index' : '10'
				});
				$(this).find('img').addClass("hover").stop()
						.animate({
							marginTop : '-110px',
							marginLeft : '-110px',
							top : '50%',
							left : '50%',
							width : '174px',
							height : '174px',
							padding : '20px'
						}, 200);

			},
			function() {
				$(this).css({
					'z-index' : '0'
				});
				$(this).find('img').removeClass("hover").stop()
						.animate({
							marginTop : '0',
							marginLeft : '0',
							top : '0',
							left : '0',
							width : '100px',
							height : '100px',
							padding : '5px'
						}, 400);
			});

	// Swap Image on Click
	$("ul.thumb li a").click(function() {
		var mainImage = $(this).attr("href"); // Find Image
												// Name
		$("#main_view img").attr({
			src : mainImage
		});
		return false;
	});

	// autoclear login boxes
	$("input.login").click(function() {
		$(this).val('');
	});

	// / size of input buttons
//	$('.actionbutton').each(function() {
//		var text = $(this).val().length;
//		if (text > 10) {
//			$(this).css('background-image',	'url("/site/im/input-background-150.png")');
//			$(this).css('width', '150px');
//		}
//	});

}); // end document ready function

