// URL Parser
function parseURL(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')
    };
}

$(document).ready(function() {		
	$("#tdr_nav_list > li:gt(4)").remove();
	var currentURL, imagePath, imgExists;
	imgExists = true;
	// Split URL into segments
	currentURL = parseURL(document.URL).segments;
	if (currentURL[0] != "") {
		// Check which directory current Page is in
		switch(currentURL[0]) {
			case "about": imagePath = "about.jpg";
			break;
			case "aps": imagePath = "aps.jpg";
			break;
			case "faculty": imagePath = "faculty.jpg";
			break;
			case "evc": imagePath = "evc.jpg";
			break;
			case "resource-admin": imagePath = "resource-admin.jpg";
			break;
			case "staff": imagePath = "staff.jpg";
			break;
			case "staffhr": imagePath = "staffhr.jpg";
			break;
			case "students": imagePath = "students.jpg";
			break;
			case "ug-ed": imagePath = "ug-ed.jpg";
			break;
			case "visitors": imagePath = "visitors.jpg";
			break;
			default : imgExists = false; // No Image for Current URL
		}
		// Check if an image Exists for the current Path
		if (imgExists) {
			// Attach Image banner to page
			imagePath = "<img alt='' src='/_images/header/" + imagePath + "' />";
			$('#tdr_2_col_content').prepend(imagePath);
		}
	}
});
