if (typeof(console) == "undefined") { console = {}; }
if (typeof(console.log) == "undefined") { console.log = function() { return 0; } }

var currentNav;

function init(){
	
	currentNav = $('body').attr('class');
	$('.t-sear a').click(toggleSearch);
	
	
	$('#overlay').live('click',function(){
		$('#overlay').hide();
		$('#dialog').fadeOut('fast').empty();
		return false;
	});
	
	$('.dialog-close').live('click',function(){
		$('#overlay').hide();
		$('#dialog').fadeOut('fast').empty();
		return false;
	});
	
	$('.showVideo').click(function(){
		$('#overlay').fadeIn();
		$('#dialog').load($(this).attr('href')).show();
		return false;
	});
	
	$('.showQtvr').click(function(){
		$('#overlay').fadeIn();
		$('#dialog').load($(this).attr('href')).show();
		return false;
	});
	
	
	$('ul.tabs').tabs('div.pane',{
		onBeforeClick: function(event,i){
	
			var pane = this.getPanes().eq(i);
			var targ = this.getTabs().eq(i).attr("href");
			var live = this.getTabs().eq(i).attr("rel");

			if(targ != '#'){
				if (pane.is(":empty") || live == 'live') {
					loadtoobj(pane,this.getTabs().eq(i).attr("href"));	
				}
			}
		}	
	});
	
	
		
}

function initOnLoad(){
	
	// fix footer (incase content grows)
	var h	= 1
		 	+ $('#footer-links').outerHeight()
			+ $('#footer-copyright').outerHeight();
			
	$('#wrapper').css('margin-bottom','-'+h+'px');
	$('#shim').css('height',h+'px');
	$('footer').css('height',h+'px');
	
	
}


function loadtoobj(obj,url,params){
	
	var loadDelay = setTimeout(
		function(){
			obj.html('<div class="loading">LOADING</div>');
		},300
	);

	obj.load(
		url,
		params,
		function(response,status,xhr){
			clearTimeout(loadDelay);
			if (status=="error") {
				var msg = "Error: ";
				obj.html('<div class="error"><p><strong>ERROR RETRIEVING DATA:</strong><br/>'+ xhr.status + ' ' + xhr.statusText +'</p></div>');
				
			}
		}	
	);
	
}

function toggleSearch(){
	
	if(currentNav == 'sear') return false;
	
	if($('body').attr('class') == 'sear'){
		$('body').removeClass().addClass(currentNav);
		$('#header-search').slideUp('fast');
	}else{
		$('body').removeClass().addClass('sear');
		$('#header-search').slideDown('fast');
		$('#q').focus();
	}
	return false;
}

