/* Custom utility functions */
String.prototype.capitalize = function(){
    return this.replace(/\S+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
}

var current_title = "";
function formatTitle(title) {
	current_title = getFormatTitle(title)
    return 'Rankin Live' + current_title;
}
function getFormatTitle(title) {
	title = title.split("/")[1].replace(/\//g, '').replace(/\_/g,' ').capitalize();
	return (title != '' ? ' / ' + title : '');
}
/* */


/* Custom SWFAddress and Ajax handling */
function handleChange(event) {
	
	//links
    var index, rel, links = document.getElementsByTagName('a');
    for (var i = 0, l; link = links[i]; i++) {
        index = link.rel.indexOf('?');
        rel = (index > -1) ? link.rel.substr(0, index) : link.rel;
        link.className = rel == event.path ? 'selected' : '';
    }
    
    //url object
    var object = {};
    for (var p in event.parameters) {
        object.p = event.parameters[p];
    }
    object.swfaddress = event.path;
    
    if(!current_title || getFormatTitle(event.path) != current_title)
    {
	    //pages
	    $.get("datasource.php", object, putContent);
	    
	    //title
//	    $.get("ajax/pageTitle.php", object, putTitle);
	    SWFAddress.setTitle(formatTitle(event.path));
    }
}
function putContent(data)
{
	$("#content").hide();
	$("#content").html(data);
	$("#content").fadeIn();
}
function putTitle(data)
{
	if(data != "")
		document.title = "RANKIN LIVE | " + data;
	else
		document.title = "RANKIN LIVE";
}
/* */


/* Event */
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
/* */