function init(){
	setTimeout(initialOverlayHide,5000);
	adjustOverlay();
	if($('#preview-splash'))
		$('#preview-splash').cycle({fx:'fade',timeout:8000,after:fixSlideShow});      
	if(document.getElementById('whatson')){
		$('#whatson').load("./whatson.php",null,setupWhatson);	
	}
	//$('.clear').html('<!-- --!>');
	repairMenu();
	//initJsBox();

	$('.goto').click(function(){
		
		$.scrollTo($(this.rel),800);
		return false;
	});
	$('img').load(function(){
		if(!$(this).attr('width'))
			$(this).attr('width',$(this).width());
		if(!$(this).attr('height'))
			$(this).attr('height',$(this).height());
	});
	$('.cart-add-button').click(addToCart);
	$('.close-overlay-button').click(hideTopMessage);
	$('.close-overlay').click(hideTopMessage);
	
	setUpHiddens()
	preinit();
	

}
 $(window).load(function(){
 	
 	initialOverlayHide();
 	preinit();
 	loadTransImgs();
 });

function postAjax(){
	setUpHiddens();
	$('img').load(function()
		{
			if(!$(this).attr('width'))
				$(this).attr('width',$(this).width());
			if(!$(this).attr('height'))
				$(this).attr('height',$(this).height());
	});
	$('.cart-add-button').click(addToCart);
	$('.close-overlay-button').click(hideTopMessage);
	$('.close-overlay').click(hideTopMessage);
	loadTransImgs();
}
function setUpHiddens(){
	$('.show').unbind();
	$('.show-simple').unbind();
	$('.hidden').hide();
	$('.show').click(function(){
		$(this).hide(500);
		$($(this).attr('rel')).show(500);
		return false;
	});
	$('.show-simple').click(function(){
		$($(this).attr('rel')).show(500);
		return false;
	});
}
var ih = 0
function initialOverlayHide(){
	if(ih == 0){
		hideOverlay();
		ih = 1;	
	}	
}
function showOverLoader(speed,callback){
	if(!speed) speed = 500;
	$('.over-loader').fadeIn(speed);
	if(callback){
		callback();
	}
}
function hideOverLoader(speed,callback){
	if(!speed) speed = 500;
	$('.over-loader').fadeOut(speed);
	if(callback){
		callback();
	}
}

function adjustOverlay(){
	$('.over-loader').vCenter();
	$('.overlay').css('width',$(window).width()+'px');
	$('.overlay').css('height',$(window).height()+'px');
}
function showOverlayButton(){$('.close-overlay-button').show();}
function hideOverlayButton(){$('.close-overlay-button').hide();}
function showTopMessage(text){
	showOverlayButton();
	if(text){
		$('.top-message-text').html(text);
	}
	$('.close-overlay-button').show();
	$('.top-message').vCenter();
	showOverlay(function(){$('.top-message').fadeIn(500)});
}
function hideTopMessage(){
	$('.top-message').fadeOut(500,hideOverlay)
}
function hideOverlay(){
	ih = 1;
	$('.overlay').hide();
}
function showOverlay(callback){
	ih = 1;
	adjustOverlay();
	$('.overlay').show();
	
	if(callback){
		callback();
	}
}

function preinit(){
	var caps = $('.captionimg');
	for(c=0;c<caps.length;c++){
		$(caps[c]).find('img').load(function()
		{
			$(this.parentNode).css("width",$(this).width()+"px");
		}	);
		
	}
	var images = $('img:visible');
	for(c=0;c<images.length;c++){
		$(images[c]).load(function()
		{
			if($(this).attr('width') && $(this).attr('height')){
				return 0;
			} 
			$(this).css("width",$(this).width()+"px");
			$(this).css("height",$(this).height()+"px");
			var check = this.src.substring(this.src.lastIndexOf("."));
			if (check == ".png" || check == ".PNG"){
				objMyImage = new OpacityObjectImg(this);
				objMyImage.setBackground();
			}			
			
		});
		
	}

}
function setupWhatson(){
	$('#whatson').find('br').hide();
	$('#whatson').find('.whatsonnowdate:gt(0)').hide();
}
function repairMenu(){
	$('#navheader').children('li:first').html('<a href="/">Home</a>');
	$('#navheader').children().eq(1).html('<a href="/about/schedule">Schedule</a>');
	$('#navheader').children().eq(2).html('<a href="/about/programming">Programming</a>');
	$('#navheader').children().eq(3).html('<a href="/about/from_the_president">About WTCI</a>');
}

function throb(who){
	_throbOut(who);
}
function _throbIn(who){
	setTimeout(function(){
	$(who).fadeTo(400,1,function(){_throbOut(who)});
	},100);
}
function _throbOut(who){
	setTimeout(function(){
	$(who).fadeTo(400,.10,function(){_throbIn(who)});
	},500);
}

function loadTransImgs(){
		var images = document.getElementsByTagName('img');
		for (var h = 0; h < images.length; h++){
			var check = images[h].src.substring(images[h].src.lastIndexOf("."));
			if (check == ".png" || check == ".PNG"){
				objMyImage = new OpacityObjectImg(images[h]);
				objMyImage.setBackground();
			}
		
		}
	
	}
