$(function() { /* Menu */ $('#menu ul li').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); }); $('#account_menu ul li a').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); }); /* User Login Area */ $('#header #login').mouseover(function() { if ($('#header #login form').length > 0) { if ($('#header #login form:visible').length == 0) { $('#header #login form').slideDown(300); $('#header #login').animate({height: '44px'}, 300); } } }); $('#header #login input[name="username"]').focus(function () { if ($(this).val() == 'username') { $(this).val(''); } }); $('#header #login input[name="username"]').blur(function() { if ($(this).val() == '') { $(this).val('username'); } }); $('#header #login input[name="password"]').focus(function () { if ($(this).val() == 'password') { $(this).val(''); } }); $('#header #login input[name="password"]').blur(function() { if ($(this).val() == '') { $(this).val('password'); } }); $('.whats_this_link').click(function() { var id = $(this).attr('rel'); $('#'+id).show(); }); $('.whats_this').live('click', function() { $(this).hide(); }); $('#register input[name="backward"]').click(function() { window.location.replace(SITE_URL+"grants/register_signup/"); }); $('#confirm input[name="backward"]').click(function() { window.location.replace(SITE_URL+"grants/register_details/"); }); $('.expand').live('click', function() { $(this).siblings('.refine_option_content').slideDown(300); $(this).addClass('close'); $(this).removeClass('expand'); $(this).html('CLOSE'); }); $('.close').live('click', function() { $(this).siblings('.refine_option_content').slideUp(300); $(this).addClass('expand'); $(this).removeClass('close'); $(this).html('EXPAND'); }); $(document).mousemove(function(e) { var top = e.pageY + 10; var left = e.pageX + 10; $('#region_title').css('top', top+'px').css('left', left+'px'); }); $('map[name="browse_uk"] area, map[name="news_uk"] area').mouseover(function() { $('#region_title').show(); if ($('#region_title').attr('rel') != 'disable_hover') { $('#region_title').html($(this).attr('name')); } }); $('map[name="browse_uk"] area, map[name="news_uk"] area').mouseout(function() { $('#region_title').hide(); }); $('map[name="browse_uk"] area').click(function() { $('#region').val($(this).attr('rel')); $('#region_title').html($(this).attr('name')); return false; }); $('map:not([name="browse_uk"]):not([name="news_uk"]) area').click(function() { var newWindow = window.open(this.getAttribute('href'), '_blank'); newWindow.focus(); return false; }); $('#category').change(function() { var this_id = $(this).attr('value'); $('.subcategory_list').attr('disabled', true).hide(); if ($('#subcategory_'+this_id).length > 0) { $('#subcategory_'+this_id).attr('disabled', false).show(); } else { $('#subcategory_none').attr('disabled', false).show(); } }); $('#agency').change(function() { var this_id = $(this).attr('value'); $('.organisation_list').attr('disabled', true).hide(); if ($('#organisation_'+this_id).length > 0) { $('#organisation_'+this_id).attr('disabled', false).show(); } else { $('#organisation_none').attr('disabled', false).show(); } }); $('#search_tips a').click(function() { if ($('#search_tips_text:visible').length == 0) { $('#search_tips_text').slideDown(); } else { $('#search_tips_text').slideUp(); } }); $('#all_categories').click(function() { if ($(this).is(':checked')) { $('input.category').attr('checked', true); } else { $('input.category').attr('checked', false); } }); $('#all_regions').click(function() { if ($(this).is(':checked')) { $('input.region').attr('checked', true); } else { $('input.region').attr('checked', false); } }); $('input.remove').live('click', function() { $this = $(this); $.ajax({ url: '/js/remove_grant.php', type: 'post', data: 'GrantID='+$this.attr('rel'), success: function() { $this.parent('li').slideUp(200).fadeOut(200, function() { }); } }); }); $('input.save').live('click', function() { $(this).attr('src', '/images/button_saving.png'); $this = $(this); $.ajax({ url: '/js/save_grant.php', type: 'post', data: 'GrantID='+$this.attr('rel'), success: function() { $this.fadeOut(200, function() { $this.removeClass('save'); $this.addClass('saved'); $this.attr('src', '/images/button_saved.png'); $this.attr('disabled', 'disabled'); $this.fadeIn(200); }); } }); }); /* Forms */ $('input.text, input.email, input.password').focus(function() { $(this).css('-moz-box-shadow', '0px 0px 2px #3A83D0'); $(this).css('-webkit-box-shadow', '0px 0px 2px #3A83D0'); }); $('input.text, input.email, input.password').blur(function() { $(this).css('-moz-box-shadow', 'none'); $(this).css('-webkit-box-shadow', 'none'); $(this).css('border', '1px solid #999999'); }); /** News List **/ var timer; $(window).scroll(function(e) { if (timer) clearTimeout(timer); if ($(window).scrollTop() >= $(document).height() - $(window).height() - 300) { if ($('#news_loader').css('display') == 'none') { timer = setTimeout(function() { timer = null; // Load next items var key = $('input[name="news_list_key"]').val(); $('#news_loader').show(); $('
').load(SITE_URL+'grants/news/?key='+key+' #main_news_list', function() { if ($(this).children().length) { $('#main_news_list').append($(this).children().html()); $('input[name="news_list_key"]').val(parseInt(key)+5); $('#news_loader').hide(); } else { $('#news_loader').html('No more news items'); } }); }, 200); } } }); });