$(document).ready(function() {

// Navigation Hover States
	$("#nav li#nav-home").hover(function() {
		$(this).css("backgroundPosition","-91px -49px");
	}, function() {
		$(this).css("backgroundPosition","-91px 0");
	});
	
	$("#nav li#nav-aboutbcmpa").hover(function() {
		$(this).css("backgroundPosition","-206px -49px");
	}, function() {
		$(this).css("backgroundPosition","-206px 0");
	});

	$("#nav li#nav-industryoverview").hover(function() {
		$(this).css("backgroundPosition","-343px -49px");
	}, function() {
		$(this).css("backgroundPosition","-343px 0");
	});
	
	$("#nav li#nav-events").hover(function() {
		$(this).css("backgroundPosition","-503px -49px");
	}, function() {
		$(this).css("backgroundPosition","-503px 0");
	});
	
	$("#nav li#nav-newsandpublications").hover(function() {
		$(this).css("backgroundPosition","-588px -49px");
	}, function() {
		$(this).css("backgroundPosition","-588px 0");
	});
	
	$("#nav li#nav-industryinitiatives").hover(function() {
		$(this).css("backgroundPosition","-762px -49px");
	}, function() {
		$(this).css("backgroundPosition","-762px 0");
	});
	
// Sidebar Navigation
	$("#sidebar .sidebar-navigation-parent li a:not(#sidebar .sidebar-navigation-parent ul.sidebar-navigation-child li a, #sidebar .sidebar-navigation-parent li.current a)").hover(function() { // hovers
		$(this).css({
			"backgroundImage":"url(/frontend/images/sidebar-subnav-arrow-hover.gif)",
			"color":"#FFF"
		});
	}, function() {
		$(this).css({
			"backgroundImage":"url(/frontend/images/sidebar-subnav-arrow.gif)",
			"color":"#666"
		});
	})/*.bind('click',function() { // click toggle
		var targetLi = $(this).parent("li");
		if (targetLi.hasClass("sidebar-open")) { // click to hide
			targetLi.children("ul.sidebar-navigation-child").slideUp(300);
			targetLi.removeClass("sidebar-open").addClass("sidebar-closed");
		} else if (targetLi.hasClass("sidebar-closed")) { // click to reveal
			targetLi.children("ul.sidebar-navigation-child").slideDown(400);
			targetLi.removeClass("sidebar-closed").addClass("sidebar-open");
		}
	})*/;

// Sidebar event, remove last bottom border
	$("#sidebar .sidebar-event-name:last").parent().css("borderBottom","none");

// Sidebar URL modify

	$("#sidebar ul.sidebar-navigation-child").each(function() {
		var firstChildLink = $(this).children('li:first').children('a').attr('href');
		$(this).siblings('a').attr("href",firstChildLink);
	});

// Sidebar search
	
	
	
	$('#sidebar-search-form .submit').click(function() { // submit button
		$('form#sidebar-search-form').submit();
	});
	
	$('#sidebar-search-form #keywords').focus(function() {
		$('.sidebar-search').css({"backgroundPosition":"0 -52px"});
	});
	
	$('#sidebar-search-form #keywords').blur(function() {
	var keywordtext = $('#sidebar-search-form input#keywords').val(); 
		if (keywordtext == '') {
			$('.sidebar-search').css({"backgroundPosition":"0 0"});
		}
	});
	
// Sidebar events button

	$("#sidebar #elist-submit").click(function() {
		$('form#elistform').submit();
	});
	
// Table striping

	$("table").each(function() {
		$("tr:even",this).addClass('odd');
	});
	
// Contact form

	$('#contactusform-submit-button').click(function() {
		$('#freeform').submit();
	});

// NPD form
	
	
	$('#npd-submit-button').click(function() {
	var strm = $(".npd-filter-month option:selected").val();
	var stry = $(".npd-filter-year option:selected").val();
	var strc = $(".npd-filter-category option:selected").val();
	var dated = '';
	
	if (strm != '') {
		strm += "/";
		dated = "d/";
	}
	if (stry != '') {
		stry += "/";
		dated = "d/";
	}
	if (strc != '') {
		strc += "/";
	}
	window.location = strc + dated + stry + strm;
	});
	
// Homepage News border
	
	$('.homepage-news:last').css({'border':'0', 'margin-right':'0', 'padding-right':'0'});

// Files
	$(".file-gen a[href$='.pdf']").parent()
		.css("backgroundImage","url(/frontend/images/page_white_acrobat.png)");
	$(".file-gen a[href$='.zip']").parent()
		.css("backgroundImage","url(/frontend/images/page_white_zip.png)");
	$(".file-gen a[href$='.jpg'], .file-gen a[href$='.gif'], .file-gen a[href$='.png']").parent()
		.css("backgroundImage","url(/frontend/images/page_white_picture.png)");
	$(".file-gen a[href$='.xls'], .file-gen a[href$='.xlsx']").parent()
		.css("backgroundImage","url(/frontend/images/page_white_excel.png)");
	$(".file-gen a[href$='.doc'], .file-gen a[href$='.docx']").parent()
		.css("backgroundImage","url(/frontend/images/page_white_word.png)");

	
});

$(window).load(function() {
	// Homepage news resize
	//$('.homepage-news-thumb').imagefit();
	var keywordtextonload = $('#sidebar-search-form input#keywords').val(); //  value of the sidebar search box
	if (keywordtextonload != '') {
		$('.sidebar-search').css({"backgroundPosition":"0 -52px"});
	}
});