var MAPA_ZAZNACZONY = 2;


function drukuj() {
	window.open('?print=1','_blank','toolbar=yes, location=no, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=715, height=500')
}


function inputShowHideText(jQueryObject) {
	jQueryObject.each(function(i) {
		$(this).attr('defaultValue', $(this).val());
		$(this).blur(function() {
			if (this.value=='') this.value = this.defaultValue;
		});
		$(this).focus(function() {
			if (this.value == this.defaultValue) this.value = '';
		});
 	});
}


function menu(lang, flash, aktual) {
	if ($('#InvestorRelations').length) return;
	
	var flashvars = {
		xmlLink: CMS_URL + 'tpl/cache/menu_'+lang+'.xml',
		swfLink: flash,
		aktual: aktual
	};
/*	var params = {};
	var attributes = {};
	
	swfobject.embedSWF(CMS_URL + "tpl/swf/kruszwica_top.swf", "FlashNav", "799", "225", "9.0.0", "", flashvars, params, attributes);*/

	var so = new SWFObject(CMS_URL + "tpl/swf/kruszwica_top.swf", "flashNav", "799", "225", "8", "");
	so.addParam("flashVars", "xmlLink=" + CMS_URL + 'tpl/cache/menu_'+lang+'.xml' + '&swfLink=' + flash + '&aktual=' + aktual);
	so.write("FlashNav");
}


function fixHeights() {
	lc = 0;
	mc = 0;
	rc = 0;

	$('#Main .LeftCol .CommonBoxWrap').css('height', '');
	$('#Main .MiddleCol .CommonBoxWrap').css('height', '');
	$('#Main .RightCol .CommonBoxWrap').css('height', '');
	
	if ($('#Main .LeftCol .CommonBoxWrap').length) {
		lc = $('#Main .LeftCol .CommonBoxWrap')[0].offsetHeight;
	}
	if ($('#Main .MiddleCol .CommonBoxWrap').length) {
		mc = $('#Main .MiddleCol .CommonBoxWrap')[0].offsetHeight;
	}
	if ($('#Main .RightCol .CommonBoxWrap').length) {
		rc = $('#Main .RightCol .CommonBoxWrap')[0].offsetHeight;
	}
	
	max = Math.max(Math.max(mc, rc), lc);
	
	$('#Main .LeftCol .CommonBoxWrap').css('height', max);
	$('#Main .MiddleCol .CommonBoxWrap').css('height', max);
	$('#Main .RightCol .CommonBoxWrap').css('height', max);	
}


function fixHeightsRel() {
	lc = 0;
	rc = 0;

	$('#Left .ContentBox').css('height', '');
	$('#Right .ContentBox').css('height', '');
	
	var lc = 0;
	$('#Left .ContentBox').each(function() {
		lc += this.offsetHeight;
	});
	
	if ($('#Right').length) {
		rc = $('#Right')[0].offsetHeight;
	}
	
	if (lc > rc ) {
		$('#Right .ContentBox').css('height', lc - 3);	
	}
	else {
		last = rc - (lc - $('#Left .ContentBox:last-child')[0].offsetHeight) - 56;
		$('#Left .ContentBox:last-child .newsBox').css('height', last);
	}	
}


$(document).ready(function() {
	if ($("#checkbox").length > 0) {
		$("#checkbox").checkbox({checked: CMS_URL + "tpl/img/bg-checkbox-ch.gif", unchecked: CMS_URL + "tpl/img/bg-checkbox.jpg"});
		$("#inne_doswiadczenie").checkbox({checked: CMS_URL + "tpl/img/bg-checkbox-ch.gif", unchecked: CMS_URL + "tpl/img/bg-checkbox.jpg"});
		$("#cssCheckbox").cssCheckbox();
		if (typeof($().prettyCheckboxes)=='function') {
			$('input[type=checkbox],input[type=radio]').prettyCheckboxes();
		}

	  	$('#myselectbox1').selectbox();
		$('#myselectbox2').selectbox();
	    $('#myselectbox3').selectbox();
	}
	
	fixHeights();
	
	setInterval(function() {
		fixHeights()
	}, 3000);

	$('a.lightbox').lightBox();
	$('a.lightBox').lightBox();
	

	if ($('#InvestorRelations').length) {
		setInterval(function() {
			fixHeightsRel();
		}, 3000);
		fixHeightsRel();
	}
	

	$('#InvestorRelations #Header').click(function() {
		parts = document.location.pathname.split('/');
		document.location.pathname = ('/'+parts[1]+'/'+parts[2]);
	});
	
	// target do stron zewnetrznych
	$('a[@href^=http]').not('a[@href^=http://www.ztkruszwica.pl/]').not('a[@href^=http://ztkruszwica.pl/]').not('a[@href^=http://www.kruszwica.pl/]').not('a[@href^=http://www.kruszwica.pl/]').not('a[@href^=http://www.ztkruszwica.com.pl/]').not('a[@href^=http://kruszwica.goldensubmarine.com/]').not('a[@href^=http://ztkruszwica.com.pl/]').attr('target', '_blank');
	
	
	submitNewsletter = function() {	
		$('#newsletterResult').load(CMS_URL + CMS_LANG + '/newsletter-save?action=save1&grupaId=1&email=' + $('#NewsletterEmail').val());
		$('#newsletterResult').html('');
		$('#newsletterResult').show();
		$('#newsletterForm').hide();
		setTimeout(function() {
			$('#newsletterForm').show();
			$('#newsletterResult').hide();
		}, 5000);
		return false;
	};
	
	$('#newsletterForm').submit(submitNewsletter);

	inputShowHideText($('#NewsletterEmail, #search'));
	
	if ($('.Stock ul.Quotation').length > 0) {
		$('.Stock ul.Quotation').liScroll();
		$('.Stock ul.newsticker').css('width', '730px');
	}

	$('#Nav > li').hover(function() {
		if (!$(this).find('.active').length) {
			$('#Nav > li > ul').hide();
			$(this).find('ul').fadeIn('fast');
		}
	}, function () {
		$(this).find('ul').hide();
		if ($('#Nav > li > ul:visible').length == 0) {
			$('#Nav > li > ul.active').fadeIn('fast');
		}
	});
	
	
	submitNewsletter2 = function() {	
		message = $.get(CMS_URL + CMS_LANG + '/newsletter-save?action=save1&grupaId=2&email=' + $('#email').val(), function(data) {
			alert(data.replace(/<br \/>/g, "\n").replace('<br />', "\n").split('>')[1].split('<')[0]);
		});
		return false;
	};
	
	$('#newsletterForm2').submit(submitNewsletter2);
	
	$('table[align=center]').css('margin', 'auto');
	$('div.BoxRelChanges a').click(function(){
		var this_rel = $(this).attr('rel');
		if (!$(this).hasClass('active'))
		{
			$('div.BoxRelChanges a').removeClass('active');
			$(this).addClass('active');
			$('div.FlashStock').hide();
			$('#'+this_rel).show();
		}
		return false;
	});
});
  
