hash_test = "";
function pageload(hash, target, source, callback, reurl, history) {
	if (!target) target = '.tabs-box';
	if (!source) source = '.tabs-box';
	if (!callback) callback = 'void(0);';
	if (!reurl) reurl = 'yes';
	if (!history) history = 'yes';
	if(hash) {
		if ( hash != PAGE.hash_test) {
			PAGE.hash_test = hash;
			PAGE.load(hash, target, source,  callback, reurl, 'no');
		};
	} else {
		$("#load").empty();
	}
}

var cPage = function() {

	this.init = function() {

		if (typeof $.ifixpng != 'undefined') $('*').ifixpng(ROOT + 'themes/images/blank.gif');

		if (HTMLinfo.page_name == 'spiz' && typeof userInfo == 'undefined') {
			var so = new SWFObject(ROOT + "swf/crocodille_spiz.swf", "flash", "680", "544", "9.0.0", "#f9f9f9");
			so.addParam("wmode", "window");
			so.addParam("bgcolor", "#f9f9f9");
			so.addParam("scale", "showall");
			so.addVariable("com", ROOT + "com.php");
   			so.write("flash");
   			$('#content').css({
   				'padding': '0px',
   				'width': '680px'
   			});
		}

		$.historyInit(pageload);

		PAGE.postLoad();
	};

	this.load = function(url, target, source, callback, reurl, history) {

		if (!target) target = '.tabs-box';
		if (!source) source = '.tabs-box';
		if (!callback) callback = 'void(0);';
		if (!reurl) reurl = 'yes';
		if (!history) history = 'yes';

		reurl = 'no';

		if (url.indexOf(window.location.hostname) != -1) {
			url = (url.substr(url.indexOf(window.location.hostname) + window.location.hostname.length));
		}

		if (history != 'no') {
			url = url.replace(/^.*#/, '');
			$.historyLoad(url, target, source, callback, reurl, history);
			return false;
		}

		if (typeof pageTracker != 'undefined') {pageTracker._trackPageview(url);}

		if (reurl == 'yes') url = '/ajax' + url + '/' + source;

		PAGE.throbber(target);

		$('.tabs li a').each(function(){
			href = $(this).attr('href');
			re = /.html/gi;
			_href = href.replace(re, '');
			_url = url.replace(re, '');
			if (_url.indexOf(_href) != -1) {
				$('.tabs li').removeClass('ac');
				$(this).parent().addClass('ac');
			}
		});

		$.post(url, function(data){
				if (reurl == 'yes') {
					$(target).html(data);
				} else {
					$(target).html($(data).find(source).html());
				}
				$('#breadcrumbs').html($(data).find('#breadcrumbs').html());
				PAGE.postLoad();
				eval(callback);
		});
		void(0);
	};


	this.postLoad = function(){
		if (typeof userInfo == 'undefined') {
			$('.tabs li a').each(function(){
				hsh = window.location.hash;
				if (hsh == '') {
					PAGE.hash_test = ROOT + HTMLinfo.page_name + '.html';
					window.location.hash = '#' + PAGE.hash_test;
				}
			});
			$('.tabs li a[class!="noajax"], .tabs-box a.ajax').unbind('click').bind('click', function(){
				url = $(this).attr('href');
				PAGE.load(url, null, null, null, 'no', 'yes');
				return false;
			});
			$('#slider-reklama').innerfade({
	            animationtype: 'fade',
	            speed: 1000,
	            timeout: 3000,
	            type: 'sequence',
	            containerheight: '330px'
	        });

			$('.gallery a, a.lightbox').lightBox({
				imageLoading:			'/themes/images/lightbox/lightbox-ico-loading.gif',
				imageBtnPrev:			'/themes/images/lightbox/lightbox-btn-prev.gif',
				imageBtnNext:			'/themes/images/lightbox/lightbox-btn-next.gif',
				imageBtnClose:			'/themes/images/lightbox/lightbox-btn-close.gif',
				imageBlank:				'/themes/images/lightbox/lightbox-blank.gif'
			});

			$('.toggle_container').hide();
			  $('h2.trigger').click(function(){
			    $(this).next('.toggle_container').slideToggle('slow,');
			  });
			  $('h2.trigger').hover(
			    function () {
			      $(this).css({'cursor':'pointer'});
			    },
			    function () {
			      $(this).css({'cursor':''});
			    }
			  );
			//$('h2.trigger:first').trigger('click');

			$('input:checkbox:not([safari])').checkbox();
			$('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});
			$('input:radio').checkbox();

			PAGE.hook_tree();

			if (typeof $.fn.validate != 'undefined') {
				$('form.registration, form.form_your_opinion, form.concernes, form.validate, form.materials, form.orders').validate({
					errorElement: "span",
					focusCleanup: true,
					onkeyup: false,
					focusInvalid: false,
					errorPlacement: function(error, element) {
						//element.val('test')
						error.appendTo( element.parent("td"));
   					},
   					highlight: function(element, errorClass) {
   						setTimeout(function(){$(element).parent("td").find('span.error').fadeOut();}, 5000);
	   					/*$(element).fadeOut(1000, function() {
	       					$(element).fadeIn(1000);
       						$(element).parent("td").find('span.error').hide();
	     				});*/
	  				}
				});
			}

	        /* mapa */
	        $(".map a").each(function()
	        	{
	        	$(this).bind("click",function()
	        		{
	        		var div_class="."+$(this).attr("class")+"_title";
	        		var $title_div=$(div_class+":first");
	        		var $close_div=$(div_class+":first .title_content .title_close");
	        		if($title_div.css("display")=="none")
	        			{
	        			$title_div.css("display","block");
	 					$close_div.bind("click",function()
	 						{
	 						$title_div.css("display","none");
	 						$close_div.unbind();
	 						})
	        			}
	        		return false;
	        		})
	        	});

	        /*******/


		}
		$.getScript(ROOT + 'js/cufon-config.js');
	};

	this.hook_tree = function() {
		  $('.stitek1').click(function() { $('.pop-up:not([class$=item1])').fadeOut('slow', function() { $('.item1').fadeIn('slow'); }); return false; });
		  $('.stitek2').click(function() { $('.pop-up:not([class$=item2])').fadeOut('slow', function() { $('.item2').fadeIn('slow'); }); return false; });
		  $('.stitek3').click(function() { $('.pop-up:not([class$=item3])').fadeOut('slow', function() { $('.item3').fadeIn('slow'); }); return false; });
		  $('.stitek4').click(function() { $('.pop-up:not([class$=item4])').fadeOut('slow', function() { $('.item4').fadeIn('slow'); }); return false; });
		  $('.stitek5').click(function() { $('.pop-up:not([class$=item5])').fadeOut('slow', function() { $('.item5').fadeIn('slow'); }); return false; });
		  $('.stitek6').click(function() { $('.pop-up:not([class$=item6])').fadeOut('slow', function() { $('.item6').fadeIn('slow'); }); return false; });
		  $('.stitek7').click(function() { $('.pop-up:not([class$=item7])').fadeOut('slow', function() { $('.item7').fadeIn('slow'); }); return false; });
		  $('.stitek8').click(function() { $('.pop-up:not([class$=item8])').fadeOut('slow', function() { $('.item8').fadeIn('slow'); }); return false; });
		  $('.stitek9').click(function() { $('.pop-up:not([class$=item9])').fadeOut('slow', function() { $('.item9').fadeIn('slow'); }); return false; });
		  $('.stitek10').click(function() { $('.pop-up:not([class$=item10])').fadeOut('slow', function() { $('.item10').fadeIn('slow'); }); return false; });
		  $('.stitek11').click(function() { $('.pop-up:not([class$=item11])').fadeOut('slow', function() { $('.item11').fadeIn('slow'); }); return false; });
		  $('.stitek12').click(function() { $('.pop-up:not([class$=item12])').fadeOut('slow', function() { $('.item12').fadeIn('slow'); }); return false; });
		  $('.vize').click(function() { $('.pop-up:not([class$=item20])').fadeOut('slow', function() { $('.item20').fadeIn('slow'); }); return false; });
		  $('.poslani').click(function() { $('.pop-up:not([class$=item21])').fadeOut('slow', function() { $('.item21').fadeIn('slow'); }); return false; });
		  $('.item-close').click(function() {
		    $(this).parent().fadeOut('slow');
		    return false;
		  });
	};

	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/throbber.gif" style="background: transparent;"/></center>');
	}
};
var PAGE = new cPage();

$(function(){
	PAGE.init();
});
