/* AJAX */
function AddPublicationHit(ItemId) {
    $.ajax({
            url: '/ajax/AddPublicationHit.aspx?ItemId=' + ItemId ,
            async: false
            });
}

// Search field

$(document).ready(function () {

    var searchLabel = $('#site-tools #frmSiteSearch label').remove().text();
    
    $('#header-search-keywords').addClass('placeholder').val(searchLabel).focus(function () {
        if (this.value == searchLabel) {
            $(this).removeClass('placeholder').val('');
        };
    }).blur(function () {
        if (this.value == '') {
            $(this).addClass('placeholder').val(searchLabel);
        };
    });
    
    $('#frmSiteSearch').submit(function () {
        if ($('#header-search-keywords').val() == searchLabel) {
            $('#header-search-keywords').val('');
        }
    });
    
    $('.topic-expand').change(function(){
  	    if ($(this).attr('checked') == true) {
  	  	    $('.nested-checkboxes').slideDown();
  	    } else {
  	  	    $('.nested-checkboxes').slideUp();
  	    }
    })
    
});




// Accordion Expand and close 
$(function() {
	
	$('.expanding .heading-toggle').wrapInner('<a href="#"></a>');
	$('.expanding .more').hide();
	$('.expanding li:first-child .more').show();
	$('.expanding li:first-child .heading-toggle').addClass('open');
	
	$('.expanding .heading-toggle').click(function() {
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
			$(this).nextAll('.more').slideUp();
		} else {
			$(this).addClass('open');
			$(this).nextAll('.more').slideDown();
		}
		return false;
	});
	
    $("label.overlabel").overlabel();

});




// Add Inter page controls
$(document).ready(function() {
	$('ul#controls').prepend('<li><a id="minus" href="#" title="Decrease Text Size"><img src="/images/template/icons/font_smaller.png" alt="Decrease Text Size" /></a></li><li><a href="#" id="plus" title="Increase Text Size"><img src="/images/template/icons/font_larger.png" alt="Increase Text Size" /></a></li><li class="print" title="Print page"><a href="#print"><img src="/images/template/icons/printer.png" alt="Print page icon" /></a></li>');
	$('ul#controls li.print a').click(function() {
		window.print();
		return false;
	});
		

	// Resize text page control

		maxi=24;
		mini=12;
		step=2;
		subject="#wrapper";
		dColor="#CCC";
		eColor="#09C";
		$.fn.getFontSize = function(){
		    return parseInt(($(this).css("font-size")).replace("px",""));
		}
		$.fn.disableLink = function() {
		    $(this).css({color:dColor,cursor:"default"});
		}
		$.fn.enableLink = function() {
		    $(this).css({color:eColor,cursor:"pointer"});
		}
		$.fn.checkDisabled = function() {
		    if($(this).css({color:dColor})||$(this).css({cursor:"default"})) return true;
		    else return false;
		}
		$("#plus").click(function(){
		    current=$(subject).getFontSize();
		    if(current<maxi) {
		        $(subject).css("font-size",current+step);
		        if($("#minus").checkDisabled())
		            $("#minus").enableLink();
		    }
		    if((current+step)==maxi) $(this).disableLink();
		});
		$("#minus").click(function(){
		    current=$(subject).getFontSize();
		    if(current>mini) {
		        $(subject).css("font-size",current-step);
		        if($("#plus").checkDisabled())
		            $("#plus").enableLink();
		    }
		    if((current-step)==mini) $(this).disableLink();
		});
	});
