﻿/* ---------------------------------------------------
URL FRIENDLY 
------------------------------------------------------ */

function urlFriendly(str) {
    var url = str
  		.toLowerCase() // change everything to lowercase
 		.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces		
  		.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
 		.replace(/[^a-z0-9-åäö]+/g, "") // remove all non-alphanumeric characters except the hyphen
 		.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
		.replace(/^-+|-+$/g, "") // trim leading and trailing hyphens				
 		;
    return url;
}

$(document).ready(function() {
    $("#draggable").draggable({ axis: 'x' });
    $("#draggable").bind('dragstop', function(event) {
        var position = $("#draggable").position();
        if (position.left > 0) {
            $("#draggable").css("left", "0px");
        }
        if (position.left < -5480) {
            $("#draggable").css("left", "-5480px");
        }

    })

});

function scrollToPreviousHour() {
    $("#draggable").animate({ "left": "+=253px"}, "slow" );
}

function scrollToNextHour() {
    $("#draggable").animate({ "left": "-=253px"}, "slow" );
}