$(function(){

	if($('#tab').length>0){
		$('#tab').tabs();
	}
	
	$("a[href$='.pdf']").addClass("pdf");
	$("a[href$='.doc']").addClass("doc");
	$("a[href$='.docx']").addClass("doc");
	$("a[href$='.xls']").addClass("xls");
	$("a[href$='.xlsx']").addClass("xls");
	$("a[href$='.ppt']").addClass("ppt");
	$("a[href$='.pptx']").addClass("ppt");

	//swap images button
	if(location.pathname != "/") {
		var now = location.href.split('/');
		var endDir = now.slice(now.length-1,now.length);
		var root = $('nav','#side').find('a[href*="'+endDir+'"]')
		var img = root.find("img");
		root.addClass("active");
		img.addClass("active");
		if((img.length>0)&&(endDir!="")){ 
			var src = img.attr('src');
			var src_on = src.substr(0, src.lastIndexOf('.')) + "_o" + src.substring(src.lastIndexOf('.'));
			img.attr('src', src_on);
		}
	}
	
	
	var postfix = '_o';
	$("nav.global").find('img','a').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});

	$("#tab").find('img','a').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});

	$("#side").find('img','a').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});

	$("#contents").find('img[alt="MORE"]').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});
	
	$("#side nav").find('img','a').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});
	});

});

