jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

$(document).ready(function() {

    $.ajaxSetup ({
        // Disable caching of AJAX responses
        cache: false
    });
    
	if (navigator.userAgent.match(/Mobile/i)) {
		window.scrollTo(0,0); // reset in case prev not scrolled
		var nPageH = $(document).height();
		var nViewH = window.outerHeight;
		if (nViewH > nPageH) {
			nViewH = nViewH / window.devicePixelRatio;
			$('BODY').css('height',nViewH + 'px');
		}
		window.scrollTo(0,1);
	}

	// Prevent anchor links and buttons and .nodrag items from being dragged
	$('A,.button,.nodrag,IMG')
		    .css('-moz-user-select','none')
			.css('-webkit-user-select','none')
		    .bind('selectstart', function(e) {
		    		e.preventDefault();
		            return false;
		    })
		    .bind('draggesture', function(e) {
		    		e.preventDefault();
		            return false;
		    })
		    .bind('draggable', function(e) {
		    		e.preventDefault();
			    	return false;
		    })
		    .bind('dragstart', function(e) {
		    		e.preventDefault();
			    	return false;
		    });	
		    
	$('.single-new').focus(function(){
		try {
			var sRel = $(this).attr('rel');
			if ((sRel == undefined) || (sRel.length == 0)) {
				var s = $(this).val();
				$(this).attr('rel',s);
				$(this).val('').css('color','#444');
			}
		} catch (e) {}
	});
	
	$('.single-new').blur(function(){
		try {
			var s = $(this).val().trim();
			if (s.length == 0) {
				$(this).val($(this).attr('rel')).css('color','#BBB').attr('rel','');
			}
		} catch (e){}
	});
	
	$('.pull-left').live('click',function(e){
		e.preventDefault();
		var t = $(this);
		var c = $(this).parent();
		c.fadeOut('normal',function(){
			c.find('A').each(function(){
				$(this).css('display','inline-block');
			});
			c.fadeIn('normal');
			t.removeClass('pull-left').addClass('close-right');
		});
		return false;
	});
	
	$('.pull-right').live('click',function(e){
		e.preventDefault();
		var t = $(this);
		var c = $(this).parent();
		c.fadeOut('normal',function(){
			c.find('A').each(function(){
				$(this).css('display','inline-block');
			});
			c.fadeIn('normal');
			t.removeClass('pull-right').addClass('close-left');
		});
		return false;
	});	
	
	$('.close-left').live('click',function(e){
		e.preventDefault();
		var t = $(this);
		var c = $(this).parent();
		t.removeClass('close-left').addClass('pull-right');
		c.find('A').each(function(){
			$(this).hide();
		});
		t.show();
		return false;
	});
	
	$('.close-right').live('click',function(e){
		e.preventDefault();
		var t = $(this);
		var c = $(this).parent();
		t.removeClass('close-right').addClass('pull-left');
		c.find('A').each(function(){
			$(this).hide();
		});
		t.show();
		return false;
	});	
	
	$('.button').keydown(function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		if (code == 32) {
			$(this).click();
		}
		if (code == 27) {
			$(this).blur();
		}
	});	
	
});



