function pause(id){
	$(id).cycle('pause');	
}
function play(id){
	//alert(id);
	$(id).cycle('resume');
}
function control(id,cont){
	//alert(id);
	$(id).cycle(cont);
}

String.prototype.absUrl = function() {
	var l = window.location, h, p, f, i;
	if (/^\w+:/.test(this)) {
		return this.toString();
	}
	h = l.protocol + '//' + l.host;
	if (this.indexOf('/') === 0) {
		return h + this.toString();
	}
	p = l.pathname.replace(/\/[^\/]*$/, '');
	f = this.match(/\.\.\//g);
	if (f) {
		var n = this.substring(f.length * 3);
		for (i = f.length; i--;) {
			p = p.substring(0, p.lastIndexOf('/'));
		}
	} else {
		n = this.toString();
	}
	return h + p + '/' + n;
};

// compare two arrays to see if they are similar
Array.prototype.compare = function(t) {
	if (this.length != t.length) { return false; }
	for (var i = 0; i < t.length; i++) {
		if (this[i] !== t[i]) { 
			return false;
		}
	}
	return true;
};

// remove trailing slashes
String.prototype.noSlash = function() {
	return this.lastIndexOf('/') === this.length-1 ? this.substr(0,this.length-1) : this.toString();
};

// get the window's url
function windowUrl(address) {
	var _l = window.location;
	var _w = (_l.protocol + '//' + _l.hostname + address).split('/');
	return _w;
}

function force_pound(){
  var p = window.location.pathname;    
  var h = window.location.href.split("?");
  
  if(p != "/"){ 
    if (h.length < 2){ window.location = "/saralov2/#"+p;} // no querystring
    else{ window.location = "/#"+p+"?"+h[1]; }    // add qs to location
    //window.location = "#/"+p;
  }
  
}

function initialCap(hops) {
   hops = hops.substr(0, 1).toUpperCase() + hops.substr(1);
   return hops;
}

function xhrLoader(response, status, xhr){
  // handle 404 pages
  if (xhr.status == "404"){
    $("#page_content").html(response);
  }
  if (xhr.status == "503"){
    var tryAgain = function(dest){
      $("#page_content").load(""+$.address.value(),xhrLoader);
    };
    $("#page_content").html(response);
    window.setTimeout(tryAgain,900); // this should do something more logarithmic
  } 
 var pagetitle = $.address.value();
 pagetitle = pagetitle.replace("/","");
 pagetitle = initialCap(pagetitle);
 
  if(pagetitle && pagetitle.length > 0){
    $.address.title("Sara Lov - " + pagetitle);
  }else{
    $.address.title("Sara Lov");
  }
  $("#page_content").fadeIn(350).css({display:"block"}); 
  $("a[rel]",this).address();
  var root = $.address.pathNames()[0];
 

}



function loadPage(){
  force_pound();
  
  //alert($.address.value());
  
  if($.address.value() == "/"){
    //$("#page_content").hide(0).load(""+$.address.value(),xhrLoader);
    $("#page_content").hide(0).load("news/",xhrLoader);
  }else{
    var dick = $.address.value();
    var barf = dick.substring(1);
    //$("#page_content").hide(0).load(""+$.address.value(),xhrLoader);
    $("#page_content").hide(0).load(barf,xhrLoader);
  }
  

}




$(document).ready(function(){
  $.address.change(loadPage);
});
  

