function getUriRegion() {
    try {
        var shortUri = window.location.href.toString().toLowerCase().replace(/http\:\/\//g, '').replace(/https\:\/\//g, '');
        var startRegion = shortUri.indexOf("/");
        if (startRegion > -1) {
            startRegion++;
            var endRegion = shortUri.indexOf("/", startRegion + 1);
            return shortUri.substr(startRegion, endRegion - startRegion);
        }
        else {
            return null;
        }
    }
    catch (e) {
        return null;
    }
}

function initRegionChanger() {
    if (jQuery("#ls-region-selector").length > 0) {
    	var uriRegion = getUriRegion();
	if (uriRegion != null) {
    		jQuery("#ls-region-selector select").val(uriRegion);
	}
    	jQuery("#ls-region-selector select").bind("change", function () {
        	changeRegion(jQuery("#ls-region-selector select").val());
    	});
    }
}

function changeRegion(a) {

    //Manually set cookie
    jQuery.cookie("ls-region", a, { path: "/" });
    jQuery.cookie("ls-regionch", "1", { path: "/" });

    window.location.reload();
}

$(document).ready(function () {
    initRegionChanger();    

    $('#rotator-images').cycle({
        fx: 'fade',
        timeout: 6000,
        next: '#rotator-next',
        prev: '#rotator-prev'
    });
});


