(function($){
        $.fn.extend({
                center: function (options) {
                        var options =  $.extend({transition:300, minX:0, minY:0}, options);
                        return this.each(function() {
                                $(this).css('position', 'absolute');
                                var top = ($(window).height() - $(this).outerHeight())/2+$(window).scrollTop();
                                var left = ($(window).width() - $(this).outerWidth())/2+$(window).scrollLeft();
                                $(this).animate({
                                        top: (top > options.minY ? top : options.minY)+'px',
                                        left: (left > options.minX ? left : options.minX)+'px'
                                }, options.transition);
                                return $(this);
                        });
                }
        });
})(jQuery);

$(function() {
	$.getDocHeight = function(){
	     var D = document;
	     return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
	};
    $('#slideshow')
    .before('<div id="slidenav">')
    .cycle({
		fx: 'fade',
		pager: '#slidenav'
	});
	$('#quotes')
    .cycle({
		cleartype: 1,
		cleartypeNoBg: true,
		slideExpr: '.quote'		
	});
	$("#searchSite").fieldtag();
	def=$("#searchSite").attr("value");
    $('#searchSubmit').click(function() {
		s = $("#searchSite").attr("value");
		if(s!=def) {
			window.location="/publisher/search.aspx?searchString="+encodeURIComponent(s); return false;	
		} else {
			return false;	
		}
	});
	$("#searchSite").live("keypress", function(e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
             $("#searchSubmit").click();  
             return false;  
         } else {  
             return true;		
		}
	});

	$("#regselect").click(function(){
	    $("body > table").before('<div id="backdrop">')
		$("#regpop").center();
		$("#regpop").fadeIn(300);
		$("#backdrop").css({backgroundColor: '#bccad1', opacity: '0.7', width: $(window).width(), position: 'absolute', zIndex: '199', height: $.getDocHeight()}).fadeIn();
	});
	$("#backdrop,#regpop").click(function(){
		$("#regpop").fadeOut(0);
		$("#backdrop").fadeOut(50);
	});
	$(".flaguk").click(function(){
		$("#regpop").fadeOut(0);
		$("#backdrop").fadeOut(50);	
		return false;	
	});
	$(".flagus").click(function(){
		ChangeSite();
		return false;
	});
});


