var setupSite = { 
    webServiceUrl: "/service/"
}
 
function newService(service, vars) {
	var service = new webService({ server: setupSite.webServiceUrl, service: service, lang: setupSite.langId });
	service.setVars(vars);
	return service;
}

function webService(init) {
    var _init = init;
    var _vars = new Array();
	
	this.setVars = function(vars) {
		for (var indx in vars) {
            this.addVar(indx, vars[indx]);
        }
	}
    
    this.addVar = function(key, val) {
        _vars[_vars.length] = { k: key, v: val };
    }
    
    this.getUrl = function() {
        var res = "lang=" + _init.lang;
        
        for (var indx in _vars) {
            var obj = _vars[indx];
            res += "&" + obj.k + "=" + encodeURIComponent(obj.v);
        }
        return { url : _init.server + init.service + '.php', data : res };
    }
    
    this.call = function(params) {
        var urlData = this.getUrl();
        var dataType = typeof(params.dataType) != "undefined" ? params.dataType : "html";
        $.ajax( {  type: typeof(params.type) != "undefined" ? params.type : "POST",
                   async : typeof(params.async) != "undefined" ? params.async : true,
                   dataType : typeof(params.dataType) != "undefined" ? params.dataType : "html",
                   cache: false,
                   complete: function(res, txtStatus) {
                        if (res.status == 506) {
                            redirect(res.responseText);
                            return;
                        }
						if (params.xmlError == 'undefined' || params.xmlError == false) {
							dataType = res.status != 200 ? dataType = "html" : dataType; // errors return always in html format
						}
						
						params.success(dataType == "html" ? res.responseText : res.responseXML, res.status == 200 ? "success" : "error");
                   },
                   url: urlData.url,
                   data: urlData.data
                });
       
       // reset vars
       _vars = new Array();
    }
}

function redirect(url) {
    window.location = url
}

$(document).ready(function(){
	for (var i = 0; i < 4; i++) {
		if ($("#scrollable"+i).length) {
			$("#scrollable"+i).scrollable({  easing: 'custom', speed: 300, size: 6});
		}
	}

	$.easing.custom = function (x, t, b, c, d)  {
		var s = 1.70158;
		if ((t/=d/2) < 1) 
			return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;     
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}	
});

function gallery(id) {
	$.get('photo.php?id='+id, function(data) {
		$('#photo').replaceWith(data);
	});
}


$(function() {
if ($('#modal-bg').length) {
	height = $(document).height();
	$('#modal-bg').css('height', height);
	$('#modal-banner').css('height', height);

	$('#modal-close').click(function() {
		$.get('/modalclose.php', function() {
			$('#modal-bg').remove();
			$('#modal-banner').remove();
		});
	});
}
});
