﻿$(document).ready(function() {

    $('#print').click(function() {
        window.print();
    });

    var cookieName = "acicr";
    var originalFontSize = 100;

    if ($.cookie(cookieName)) {
        var size = $.cookie(cookieName);
        $('html').css("font-size", size + '%');
    } else {
        $.cookie(cookieName, originalFontSize, { path: "/" });
    }

    $("#font-resizer").click(function() {
        var size = $.cookie(cookieName);
        if (size == originalFontSize) {
            size = 110;
        }
        else {
            size = originalFontSize;
        }

        $("html").css("font-size", size + '%');
        $.cookie(cookieName, size, { path: "/" });
    });

    $('.documents a').click(function() {
	pageTracker._trackPageview($(this).attr('href')); 
    });


    var watermark = false;
    $('#q')
        .autocomplete('/search/autocomplete', {
            minChars: 2,
            width: 203,
            autofill: false
        })
        .result(function(event, item) {
            location.href = item[1];
            return false;
        })
        .focus(function() {
            if (watermark == false) {
                watermark = true;
                $(this).val('');
            }
        })
        .blur(function() {
            var $me = $(this);
            if ($me.val().length == 0 && watermark) {
                watermark = false;
                $me.val('Search');
            }
        });

    $('#request').click(function () {
	var title = $('#Resource-Title').text();
	var id = $('#Resource-ID').text();

        $.fancybox({
            'padding': 10,
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'title': 'Resource Request',
            'width': 500,
            'height': 300,
            'href': 'http://request.acicr.ca/?ResourceID=' + id + '&ResourceName=' + title,
            'type': 'iframe'
        });

        return false;
    });
});

