

var cPage = function() {

	this.init = function() {
		this.load_func_starter = 'no';
	};
	
	this.onload = function(){
		
        $("a[rel*='external']").click(function(){
            this.target = "_blank";
        });

        /*$('a.lightbox').lightBox();
		$('a.lightbox_single').each(function(){
			$(this).lightBox();
		});
		$.addwatermarks();

        $('form.initRequired').each(function() {
             $(this).validate({
                focusCleanup: true,
                focusInvalid: false,
                errorElement: "em"
            });
        });

    	$('a.print').bind('click', function(){
    		window.print();
    		return false;
    	});*/
    	
		if (typeof $.ifixpng != 'undefined') $('*').ifixpng(ROOT + 'themes/images/blank.gif');
/*
		var e = document.createElement('script');
		e.type = 'text/javascript';
		if (HTMLinfo.lang == 'sk') fb_lng = '//connect.facebook.net/sk_SK/all.js';
			else fb_lng = '//connect.facebook.net/cs_CZ/all.js';
		e.src = document.location.protocol + fb_lng;
		e.async = true;
		if (!document.getElementById('fb-root')) {} else {
			document.getElementById('fb-root').appendChild(e);
		};
	*/	
		if (typeof userInfo == 'undefined') {
			$('a.ajax').unbind('click').bind('click', function(){
				PAGE.load_func_starter = 'yes';
				PAGE.load($(this).attr('href'), null, null, null, null, null, 'no');
				return false;
			});
			/*
			$('a.ajax_history').unbind('click').bind('click', function(){
				PAGE.load($(this).attr('href'));
				return false;
			});
			$('form').unbind('submit').bind('submit', function(){
				url = $(this).attr('action');
				pars = $(this).serialize();
				
				gatrack(url);
				$.history.load(url);

				target = '#content';
				source = '#content'
				
				$.post(url, pars, function(data){
					$(target).html($(source, data).html());
					PAGE.onload();
					log('form');
				});
				
				return false;
			});
			*/
		};
	};
	
	this.pageLoad = function() {
		
//		PAGE.historyInit();
		
		PAGE.onload();
		
	};
	
	this.historyInit = function(){
		if (typeof userInfo == 'undefined') {
			$.history.init(function(hash){
		        if(hash == "") {
		            window.location.hash = '#' + window.location.pathname;
		        } else {
	        		PAGE.load(hash, null, null, null, null, null, 'no');
		        }
		    },
		    {unescape: ",/"});
		};
	};
	
	this.load = function(url, pars, target, source, callback, reurl, history) {
		if (!target) target = '#content';
		if (!source) source = '#content';
		if (!callback) callback = 'void(0);';
		if (!reurl) reurl = 'no';
		if (!history) history = 'yes';

		if (url.indexOf(window.location.hostname) != -1) {
			url = (url.substr(url.indexOf(window.location.hostname) + window.location.hostname.length));
		}
		
		if (reurl == 'yes') url = '/ajax' + url + '/' + source;
		
		if (history == 'yes') {
			gatrack(url);
			$.history.load(url);
			return false;
		}
		if (PAGE.load_func_starter == 'yes') PAGE.throbber(target);
		$.post(url, pars, function(data){
			if (window.location.hash != '#' + window.location.pathname || PAGE.load_func_starter == 'yes') {
				$('#interactive').html($('#interactive', data).html());
				$(target).html($(source, data).html());
				PAGE.onload();
			} else {
				PAGE.load_func_starter = 'yes';
			}
//			log('a');
		});

	};
	
	this.pagePath = window.location.pathname;

	this.block = function() {
		$('#systemWorking').fadeIn();
	};
	this.unblock = function() {
		$('#systemWorking').fadeOut();
	};
	this.throbber = function(id) {
//		$(id).html('<center style="padding-top: 50px;"><img src="' + ROOT + 'themes/images/cms/throbber.gif"/></center>');
		$(id).css({
			'position': 'relative'
		});
		$('<div style="position: absolute; top: 10px; left: 350px;"><img src="' + ROOT + 'themes/images/cms/throbber.gif"/></div>').appendTo(id);
	}
};
var PAGE = new cPage();

PAGE.init();

$(function(){
	PAGE.pageLoad();
});

var gatrack = function(url) {
	if (typeof _gaq == 'undefined') {} else {_gaq.push(['_trackPageview', url]);}
	void(0);
};

window.onload = function(event) {
    resize();
}

window.onresize = function(event) {
	resize();
}

function resize(event) {
	if ($(window).height() < 650 && $(window).width() < 980) {
        //document.getElementById('flashMovie').style.height = '650px';
		//document.getElementById('flashMovie').style.width = '980px';
		//$('#flashMovie').css('overflow', 'auto');
		// $('#content').css('overflow', 'auto');
		//$('#page').css('overflow', 'auto');
		// $('#content').css('width', '980px');
		// $('#content').css('height', '650px');
		$('#page').css('width', '980px');
		$('#page').css('height', '650px');
    } else if ($(window).height() < 650 && $(window).width() >= 980) {
		//document.getElementById('flashMovie').style.height = '650px';
		//document.getElementById('flashMovie').style.width = '100%';
		//$('#flashMovie').css('overflow', 'auto');
		// $('#content').css('overflow', 'auto');
		//$('#page').css('overflow', 'auto');
		$('#page').css('width', '100%');
		$('#page').css('height', '650px');
	} else if ($(window).height() >= 650 && $(window).width() < 980) {
		//document.getElementById('flashMovie').style.height = '100%';
		//document.getElementById('flashMovie').style.width = '980px';
		//$('#flashMovie').css('overflow', 'auto');
		// $('#content').css('overflow', 'auto');
		//$('#page').css('overflow', 'auto');
		$('#page').css('width', '980px');
		$('#page').css('height', '100%');
	} else {
		//document.getElementById('flashMovie').style.height = '100%';
		//document.getElementById('flashMovie').style.width = '100%';
		//$('#flashMovie').css('overflow', 'hidden');
		// $('#content').css('overflow', 'hidden');
		//$('#page').css('overflow', 'hidden');
		$('#page').css('width', '100%');
		$('#page').css('height', '100%');
	}
};

//window.fbAsyncInit = function() {
//	FB.init({
//		appId   : 'appid',
//		status  : false, // check login status
//		cookie  : true, // enable cookies to allow the server to access the session
//		xfbml   : true // parse XFBML
//	});
//}
