cAPI = function() {
	this.init = function() {
		API.maxZ = 100;
		API.loaded = true;
		
		if (!$.browser.msie && parseInt($.browser.version) != 6) $('#offers, .right_category').shadow({offset: -5, color: '#000000'});
		
		if (!document.getElementById('page_footer')) {} else API.initZKAjax();
		
		API.resizeFix();
		for (i=1; i <= 10; i++) {
			setTimeout(function(){
				API.resizeFix();
//				console.log('a');
			}, 1000 * ((i-1)*2));
		}
		
		$('#home_link img').css({cursor: 'pointer'}).bind('click', function(){
			link = $(this).next().attr('href');
			if (link.substr(0, 1) != '/') link = WWW_ROOT + link;
			window.location.replace(link);
		});
	};
};

cAPI.prototype.resizeFix = function() {
		if (!document.getElementById('obal2')) {} else {
			if ($(window).height() > $(document.body).height()) $('#obal2').height($(window).height() - $('#page_footer').height());
				else $('#obal2').height($(document.body).height() - $('#page_footer').height());
//			console.log($('#obal2').height() -$('#header').height() - $('#page_footer').height() - 70, $('#offers').height());
			if ($('#obal2').height() -$('#header').height() - $('#page_footer').height() - 70 < $('#offers').height()) $('#obal2').height($('#offers').height() + $('#header').height() + $('#page_footer').height() + 70);
		}
}

cAPI.prototype.initZKAjax = function() {
	return;
	$('#content a').each(function(){
		if(this.target != '_blank'){
			if (typeof this.onclick == 'undefined') this.onclick = function(){
				API.loadPage(this.href);
				return false;
			}
		}
	});

};

cAPI.prototype.loadPage = function(link){

	API.loaded = false;

	found = window.location.host + '/';
	if (link.indexOf(found) != -1) {
		link = link.substr(link.indexOf(found) + found.length);
	}

	if (typeof pageTracker != 'undefined')  pageTracker._trackPageview("/" + link);

	if (link.substr(0, 1) == '/') {
		link = link.substr(1);
	}
	
	if (link.substr(0, 4) != 'http') {
		link = 'http://' + window.location.host + '/' + link;
	}
//	console.log(link);
	
	found = window.location.host + '/';
	if (link.indexOf(found) != -1) {
		link = link.substr(link.indexOf(found) + found.length);
	}	
//	console.log(link);
/*
	$('#content').fadeTo('slow', 0.01, function(){
		if (API.loaded == false) {
			$('#content').html('<center style="margin-top: 100px;">... nahrávám ...</center>');
			$('#content').fadeTo('slow', 1);
		}
	});
*/
	$.get(WWW_ROOT + link, function(data){
		$('#content').html($(data).find('#content').html());
		API.loaded = true;
//		$('#content').fadeTo('slow', .99);
		setTimeout(function(){
			API.initZKAjax();
			for (i=1; i <= 10; i++) {
				setTimeout(function(){
					API.resizeFix();
				}, 1000 * i);
			}
		}, 10);
     });

	return;	
};


var API = new cAPI();

$(function() {
  API.init();
});


