$(function(){
	$(".overlay").height($(document).height());
	
	$(".close,.overlay").click(function(){
		$(".window").hide();
		$(".overlay").fadeOut("slow");
		$('.closeModalWindow').trigger('click');
	});
	/* Remove twitter header */
	$('.twtr-hd').hide();
	
	$('#back2Top').live('click', function() {
		goToByScroll('borderTop');
		return false;
	});
	
	$('.show_hide_sponsors').click(function() {
		goToByScroll('footer');
	});
	
	$('.widget .title').click(function(){
		var wid = $(this).parent()
		if(!wid.hasClass("widget-close")){
			closewid(wid);
		} else {
			openwid(wid);
		}
	});
	tween.init();
	
});
$(document).keyup(function(e) {
	// esc
	if (e.keyCode == 27) {
		$('.closeModalWindow').trigger('click');
	}
});


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;
}

function goToByScroll(id){
	$('html,body').animate({ scrollTop: $("#"+id).offset().top }, 'slow');
}

function closewid(wid){
	wid = wid.get(0);
	$(wid).addClass("widget-close");
	$(wid).find(".widget-content").slideUp();
	tween.close(wid)
}

function openwid(wid){
	wid = wid.get(0);
	$(wid).removeClass("widget-close");
	$(wid).find(".widget-content").slideDown();
	tween.open(wid)
}
