/*
* jQuery resize event - v1.1 - 3/14/2010
* http://benalman.com/projects/jquery-resize-plugin/
* 
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);

var browser = navigator.appName;
var browser_version = navigator.appVersion;
var version = parseFloat(browser_version);
var GCRI = {

    ANIMATION_SPEED: 250,
    ANIMATION_SPEED_SLOW: 500,
    SUPPORTS_OPACITY: true,
    init: function () {

    },

    staffExtendedBio: function () {

        $('.staff-item a.read').click(function () {
            var currentID = ".short" + $(this).attr("rel");
            $(this).prev('div').slideToggle(GCRI.ANIMATION_SPEED);

            if ($(this).hasClass('read-collapsed')) {
                $(currentID).hide("fast");
                $(this).removeClass('read-collapsed');
                $(this).addClass('read-expanded');
                $(this).html('Collapse biography');
            } else {
                $(currentID).show("fast");
                $(this).removeClass('read-expanded');
                $(this).addClass('read-collapsed');
                $(this).html('Read full biography');
            }
            return false;

        });

        $('.staff-item a.read2').click(function () {
            var currentID = ".short" + $(this).attr("rel");
            $("#" + $(this).attr("rel")).slideToggle(GCRI.ANIMATION_SPEED);

            if ($(this).hasClass('read2-collapsed')) {
                $(currentID).hide("fast");
                $(this).removeClass('read2-collapsed');
                $(this).addClass('read2-expanded');
                $(this).html('Collapse');
            } else {
                $(currentID).show("fast");
                $(this).removeClass('read2-expanded');
                $(this).addClass('read2-collapsed');
                $(this).html('Read more');
            }
            return false;

        });

    },

    innovationExtendedBio: function () {

        $('.sub-feature-unit a.read2').click(function () {
            var currentID = ".short" + $(this).attr("rel");
            $("#" + $(this).attr("rel")).slideToggle(GCRI.ANIMATION_SPEED);

            if ($(this).hasClass('read2-collapsed')) {
                $(currentID).hide("fast");
                $(this).removeClass('read2-collapsed');
                $(this).addClass('read2-expanded');
                $(this).html('Collapse');
            } else {
                $(currentID).show("fast");
                $(this).removeClass('read2-expanded');
                $(this).addClass('read2-collapsed');
                $(this).html('Read more');
            }
            return false;

        });

    },

    eventFAQSection: function () {

        $('.faq-section h3.toggle a').click(function () {
            $(this).parent().next('div').slideToggle(GCRI.ANIMATION_SPEED_SLOW);
            if ($(this).parent().hasClass('toggle-closed')) {
                $(this).parent().removeClass('toggle-closed');
                $(this).parent().addClass('toggle-opened');
            } else {
                $(this).parent().removeClass('toggle-opened');
                $(this).parent().addClass('toggle-closed');
            }
            return false;

        });
        $('#expandAll').click(function () {
            $('.faq-section h3.toggle-closed a').trigger("click");
            return false;

        });
        $('#collapseAll').click(function () {
            $('.faq-section h3.toggle-opened a').trigger("click");
            return false;

        });
    },

    tc2Expansion: function () {

        $('.tc2-list a.read').click(function () {

            $(this).prev('div').slideToggle(GCRI.ANIMATION_SPEED);
            if ($(this).hasClass('read-collapsed')) {
                $(this).removeClass('read-collapsed');
                $(this).addClass('read-expanded');
                $(this).html('Collapse');
            } else {
                $(this).removeClass('read-expanded');
                $(this).addClass('read-collapsed');
                $(this).html('Read more');
            }
            return false;

        });

    },
    eventDetailSegment: function () {

        $('.event-detail-segments h3.toggle a').click(function () {

            $(this).parent().next('div').slideToggle(GCRI.ANIMATION_SPEED_SLOW);
            if ($(this).parent().hasClass('toggle-closed')) {
                $(this).parent().removeClass('toggle-closed');
                $(this).parent().addClass('toggle-opened');
            } else {
                $(this).parent().removeClass('toggle-opened');
                $(this).parent().addClass('toggle-closed');
            }
            return false;

        });

    },
    shadowBoxCenter: function () {
        myWindowWidth = parseInt($(window).width());
        mySBWidth = parseInt($('#sb-wrapper').width());
        mySBoffset = parseInt($('#sb-wrapper').css('left'));
        space = mySBoffset - parseInt((myWindowWidth - mySBWidth) / 2);
        $('#sb-wrapper').css('marginLeft', "-" + space + "px");

    },

    pageResizeClass: function () {
        // check window size on page load
        if (parseInt($(window).width()) > 1160) {
            $('html').removeClass('smallScreen').addClass('bigScreen');
        } else {
            $('html').addClass('smallScreen').removeClass('bigScreen');
        }
        if (parseInt($(window).width()) > 1280) {
            $('#frontpageSearch').css('left', "1046px").css('right', "auto");
        }
        $(window).resize(function () { // check window size in case of resize

            if (parseInt($(window).width()) > 1160) {
                $('html').removeClass('smallScreen').addClass('bigScreen');
            } else {
                $('html').addClass('smallScreen').removeClass('bigScreen');
            }
            if (parseInt($(window).width()) > 1280) {
                $('#frontpageSearch').css('left', "1046px").css('right', "auto");
            } else {
                $('#frontpageSearch').css('right', "20px").css('left', "auto");
            }
        });
    }
};
 
 $(document).ready(function() { 
 	
	if($('#frontpageSearch').length){
		GCRI.pageResizeClass();
	}
	
     $('#sidebar-1 input').focus(function(){ // judiciously clear form
         if(!$(this).data('edited')){
             $(this).data('oldValue', $(this).attr("value"));
            $(this).attr("value", ""); // clear
        }
    });
    $('#sidebar-1 input').blur(function () { // add unfocus behaviour
        if (!$(this).attr("value")) {
            $(this).attr("value", $(this).data('oldValue'));
            $(this).data('edited', 0);
        } else {
            $(this).data('edited', 1);
        }
    });
    $('#sidebar-1 input, #frontpageSearch input').focus(function () { // judiciously clear form
        if (!$(this).data('edited')) {
            $(this).data('oldValue', $(this).attr("value"));
            $(this).attr("value", ""); // clear
        }
    });
    $('#sidebar-1 input, #frontpageSearch input').blur(function () { // add unfocus behaviour
        if (!$(this).attr("value")) {
            $(this).attr("value", $(this).data('oldValue'));
            $(this).data('edited', 0);
        } else {
            $(this).data('edited', 1);
        }
    });
});


