function positionImageNews() {
	jQuery(document).ready(function(){
		var layouts = jQuery('.col3-layout');
		if (layouts.length==1) {
			var cases = jQuery(layouts[0]).find('.right_content .people-case');
			if (cases.length>0) {
				for (var k=0;k<cases.length;k++) {
					if (typeof cases[k]._initTM == 'undefined') {
						cases[k]._initTM = true;
						if (k==0) {
							var txEls;
							txEls = jQuery(cases[0]).parent('.csc-default');
							if (txEls.length>0) {
								var leftFlex = jQuery(layouts[0]).find('.main_content .csc-default');
								if (leftFlex.length>0) {
									txEls[0].style.marginTop = jQuery(leftFlex[0]).height().toString()+'px';
								}
							}
						}
						cases[k].style.visibility = 'visible';
					}
				}
			}
		}
	});
}

function clickoff(el) {
	var ln = el.getAttribute('href').toString();
	if (ln && ln.substr(ln.length-1)=='#')
		return false;
	return true;
}

function positionImageNewsForPlugin(cUid) {
	jQuery(document).ready(function(){
		var c = document.getElementById('c'+cUid.toString());
		if (!c) return;
		var els = jQuery('.main_container .main_content').children('.csc-default');
		var rightEls = jQuery('.main_container .right_content').children('.csc-default');
		if ((rightEls.length>0) && (els.length>0)) {
			if (rightEls[0].id == c.id) {
				if (typeof c._initPostitionImg == 'undefined') {
					c._initPostitionImg = true;
					setTimeout(function(){
						jQuery(c).css({'margin-top':jQuery(els[0]).height()});
					},50);
				}
			}
		}
		setTimeout(function(){
			var casePeoples = jQuery(c).find('.people-case');
			for (var k=0;k<casePeoples.length;k++) {
				casePeoples[k].style.visibility = 'visible';
			}
		},75);
	});
}

function initCheckoutListener() {
	jQuery(document).ready(function(){
		executeCheckoutListener();
	});
}

function registerCheckobxListener() {
	setTimeout(function(){
		executeCheckoutListener();
	},100);
}
function regEnableField(el) {
	regFieldAction(el, true);
}
function regDisableField(el) {
	regFieldAction(el, false);
}
function regFieldAction(el, type) {
	var els; var k;
	els = el.getElementsByTagName('input');
	for (k=0;k<els.length;k++) els[k].disabled = (type)?'':'disabled';
	els = el.getElementsByTagName('select');
	for (k=0;k<els.length;k++) els[k].disabled = (type)?'':'disabled';
	els = el.getElementsByTagName('textarea');
	for (k=0;k<els.length;k++) els[k].disabled = (type)?'':'disabled';
}
function executeCheckoutListener() {
	var c1 = document.getElementById('form_1');
	//var c2 = document.getElementById('form_2');
	var c3 = document.getElementById('form_3');
	var f = document.getElementById('content_form');
	
	if (c1.checked || c3.checked) {
			
		var els = jQuery(f).find('.actform');
		var testOK;
		for (var k=0;k<els.length;k++) {
			if (((c1.checked && jQuery(els[k]).hasClass('actform1'))
				//|| (c2.checked && jQuery(els[k]).hasClass('actform2'))
				|| (c3.checked && jQuery(els[k]).hasClass('actform3')))
				&& (!c3.checked || !jQuery(els[k]).hasClass('nonform3'))) {
				els[k].style.display = '';
				regEnableField(els[k]);
			} else {
				els[k].style.display = 'none';
				regDisableField(els[k]);
			}
		}
		
		f.style.display = '';
		$("#twoje_dane_osobowe_container").validator({effect:'wall', lang: 'pl'});
	} else {
		f.style.display = 'none';
	}
}

function addRoundedImagesInit() {
	addRoundedImages('.csc-textpic-single-image img');
	addRoundedImages('.news-single-img img');
	addRoundedImages('.random-single img');
	addRoundedImages('.dolacz img');
	addRoundedImages('.people-case img');
}

function initLeftBoxLink(param) {
	return;
	jQuery(document).ready(function(){
		var els = jQuery(param+' a');
		if (els.length) {
			var tempHref = els[0].getAttribute('href');
			els[0].setAttribute('href', tempHref+'#list');
		}
	});
}

function initLabelify(params) {
	jQuery("input:text").labelify();
}

function initUrlWithListHash() {
	jQuery(document).ready(function(){
		var els = jQuery('.main_content .sortBox .btn_2');
		if (els.length) {
			jQuery(els[0]).click();
		}
	});
}

function addRoundedImages(pathSelector) {
	jQuery(document).ready(function(){
		$(pathSelector).one('load',function () {
		  var img = $(this);
		  if (typeof img._initTM != 'undefined')
		  	return;
		  img._initTM = true;
		  var img_width = img.width();
		  var img_height = img.height();
		 
		  // build wrapper
		  var wrapper = $('<div class="rounded_wrapper"></div>');
		  wrapper.width(img_width);
		  wrapper.height(img_height);
		 
		  // move CSS properties from img to wrapper
		  wrapper.css('float', img.css('float'));
		  img.css('float', 'none')
		 
		  wrapper.css('margin-right', img.css('margin-right'));
		  img.css('margin-right', '0')
		 
		  wrapper.css('margin-left', img.css('margin-left'));
		  img.css('margin-left', '0')
		 
		  wrapper.css('margin-bottom', img.css('margin-bottom'));
		  img.css('margin-bottom', '0')
		 
		  wrapper.css('margin-top', img.css('margin-top'));
		  img.css('margin-top', '0')
		 
		  wrapper.css('display', 'block');
		  img.css('display', 'block')
		 
		  // IE6 fix (when image height or width is odd)
		  if ($.browser.msie && $.browser.version == '6.0')
		  {
		    if(img_width % 2 != 0)
		    {
		      wrapper.addClass('ie6_width')
		    }
		    if(img_height % 2 != 0)
		    {
		      wrapper.addClass('ie6_height')      
		    }
		  }
		 
		  // wrap image
		  img.wrap(wrapper);
		 
		  // add rounded corners
		  img.after('<div class="tl"></div>');
		  img.after('<div class="tr"></div>');
		  img.after('<div class="bl"></div>');
		  img.after('<div class="br"></div>');
		}).each(function(){
		  if(this.complete) $(this).trigger("load");
		});
	});
}

function _initAnimateSzkoleniaOtwarte() {
	jQuery(document).ready(function(){
		animateSzkoleniaOtwarte();
	});
}

function animateSzkoleniaOtwarte() {
	var els = jQuery('div.animateimg');
	var sumLeft = 0;
	var marginLeft = 0;
	var marginTop = 0;
	var ulLeftHeight = 0;
	var ulRightHeight = 0;
	for (var i=0;i<els.length;i++) {
		marginLeft = 0;
		marginTop = 0;
		if (jQuery(els[i]).hasClass('item-left')) {
			if (i%3) {
				marginLeft = (i%3) * (230+6);
			} else {
				marginLeft = 6;
			}
			//marginTop = Math.floor(i/3)*(153+6);
			marginTop = 0;
			sumLeft++;
		} else {
			marginTop = (i-sumLeft)*(153+6);
			marginLeft = 0;
		}
		
		jQuery(els[i]).css({
			'position'		: 'absolute',
			'margin-left'	: marginLeft,
			'margin-top'	: marginTop
		});
		
		initAnimatedImage(els[i],{
			'_init'		: false,
			'width'		: 230,
			'height'	: 153,
			'maxWidth'	: 270,
			'maxHeight'	: 180
		});
	}
	ulLeftHeight = Math.ceil(sumLeft/3)*(153+6);
	ulRightHeight = (i-sumLeft)*(153+6);
	//document.getElementById('traingin-left-container').style.height = ulLeftHeight.toString()+'px';
	document.getElementById('traingin-right-container').style.height = ulRightHeight.toString()+'px';
}

function _initAnimatedImages() {
	animatedImages();
}

function animatedImages() {
	var imgs = jQuery('div.main_content div.photo_content div.small_image');
	for (var i=0;i<imgs.length;i++) {
		initAnimatedImage(imgs[i]);
	}
}
function initAnimatedImage(img, specialConf) {
	if (typeof img._tmAnimatedImage == 'undefined') {
		if (typeof specialConf == 'undefined') {
			specialConf = {
				'_init'		: false,
				'width'		: 125,
				'height'	: 81,
				'maxWidth'	: 160,
				'maxHeight'	: 104
			};
		}
		img._tmAnimatedImage = specialConf;
		animatedImage(img);
	}
}

function animatedImage(img) {
	img._animatedZoomIn = tmAnimZoomIn;
	img._animatedZoomOut = tmAnimZoomOut;
	img._animatedInit = tmAnimInit;
	
	img._noActive = false;
	if (!img.getElementsByTagName('a').length) {
		img._noActive = true;
		return;
	}
	
	img.onmouseover = function(){
		this._animatedZoomIn();
	};
	img.onmouseout = function(){
		this._animatedZoomOut();
	};
}
function tmAnimInit() {
	var el = this;
	var jEl = jQuery(el);
	if (!this._tmAnimatedImage._init) {
		this._tmAnimatedImage.width = jEl.width();
		this._tmAnimatedImage.height = jEl.height();
		this._tmAnimatedImage.marginLeft = parseInt(jEl.css("margin-left"));
		this._tmAnimatedImage.marginTop = parseInt(jEl.css("margin-top"));
		this._tmAnimatedImage.maxMarginLeft = this._tmAnimatedImage.marginLeft - (Math.round(this._tmAnimatedImage.maxWidth - this._tmAnimatedImage.width) / 2);
		this._tmAnimatedImage.maxMarginTop = this._tmAnimatedImage.marginTop - (Math.round(this._tmAnimatedImage.maxHeight - this._tmAnimatedImage.height) / 2);
		this._tmAnimatedImage.image = jEl.find('img.imageanimated_small');
		if (this._tmAnimatedImage.image.length!=1) {
			throw('not found image');
		}
		this._tmAnimatedImage.image = this._tmAnimatedImage.image[0];
		this._tmAnimatedImage._init = true;
	}
}
function tmAnimZoomIn() {
	this._animatedInit();
	
	var destCss = {
		'width'			: this._tmAnimatedImage.maxWidth,
		'height'		: this._tmAnimatedImage.maxHeight,
		'margin-left'	: this._tmAnimatedImage.maxMarginLeft,
		'margin-top'	: this._tmAnimatedImage.maxMarginTop
	};
	var descCssImg = {
		'width'			: this._tmAnimatedImage.maxWidth,
		'height'		: this._tmAnimatedImage.maxHeight
	};
	var absCss = {
		'z-index'		: 100
	};
	var el = this;
	jQuery(el).css(absCss);
	jQuery(el).stop().animate(destCss, 200, 'easeOutQuad');
	jQuery(el._tmAnimatedImage.image).stop().animate(descCssImg, 200, 'easeOutQuad');
	
	continueOpacityStartEffect(jQuery(el));
}
function tmAnimZoomOut() {
	this._animatedInit();
	
	var destCss = {
		'width'			: this._tmAnimatedImage.width,
		'height'		: this._tmAnimatedImage.height,
		'margin-left'	: this._tmAnimatedImage.marginLeft,
		'margin-top'	: this._tmAnimatedImage.marginTop
	};
	var descCssImg = {
		'width'			: this._tmAnimatedImage.width,
		'height'		: this._tmAnimatedImage.height
	};
	var absCss = {
		'z-index'		: 1
	};
	var el = this;
	jQuery(el).css(absCss);
	jQuery(el).stop().animate(destCss, 200, 'easeOutQuad');
	jQuery(el._tmAnimatedImage.image).stop().animate(descCssImg, 200, 'easeOutQuad');
	
	continueOpacityStartEffect(jQuery(el));
}
function continueOpacityStartEffect(obj) {
	if (obj.css('opacity')<1) {
		obj.animate({opacity:1});
	}
}
function initShowImages(img, afterTime) {
	var f = function() {
		_initShowImages(img);
	};
	setTimeout(f, afterTime);
}
function _initShowImages(img) {
	//if (img._noActive) {
	//	jQuery(img).animate({'opacity':0.3},500);
	//} else {
		jQuery(img).animate({'opacity':1},500);
	//}
}
function initTabContentTM(num) {
	var tabs = jQuery('.flex-tab-slideshow .main_content .tab_single');
	if (tabs.length && tabs[num-1]) {
		var tab = tabs[num-1];
		//if ((typeof tab._isInit == 'undefined')) {
			//tab._isInit = true;
			var temp = new Array(0,1,2,5,4,3);
			var imgs = jQuery(tab).find('div.small_image_visibility');
			var imgsLarge = jQuery(tab).find('div.large_image_visibility');
			var indexNum;
			var timeOut;
			for (var k=0;k<temp.length;k++) {
				indexNum = temp[k];
				if (typeof imgs[indexNum] == 'undefined')
					continue;
				//imgs[k].style.visibility = 'visible';
				timeOut = (k*300);
				jQuery(imgs[indexNum]).css({'opacity':0,'visibility':'visible'});
				initShowImages(imgs[indexNum], timeOut);
			}
			if (imgsLarge.length) {
				jQuery(imgsLarge[0]).css({'opacity':0,'visibility':'visible'});
				initShowImages(imgsLarge[0], Math.round(timeOut / 2));
			}
		//}
	}
}
function initTabAniatedTMSingle() {
	var k; var els;
	els = jQuery('.main_content .tab_single .small_image_visibility');
	for (k=0;k<els.length;k++) {
		els[k].style.visibility = 'hidden';
	}
	els = jQuery('.main_content .tab_single .large_image_visibility');
	for (k=0;k<els.length;k++) {
		els[k].style.visibility = 'hidden';
	}
	
	initTabContentTM(this._tabIndex+1);
}
function initTabAnimatedTM(tabObj) {
	var els = tabObj.find('li'); 
	for (var k=0;k<els.length;k++) {
		els[k]._tabIndex = k;
		els[k].onclick = initTabAniatedTMSingle;
		if (jQuery(els[k]).hasClass('current')) {
			els[k].onclick();
		}
	}
}
function sliderTMSliderAnim(bannerId,timeout) {
	var c = document.getElementById(bannerId);
	var nextNum = c._cur+1;
	if (nextNum>=c._items.length)
		nextNum = 0;
	
	//c._items[c._cur].style.display = 'none';
	//c._items[nextNum].style.display = 'block';
	
	jQuery(c._items[c._cur]).stop().fadeOut("slow");
	jQuery(c._items[nextNum]).stop().fadeIn("slow");
	
	//c._items[c._cur].style.display = 'none';
	//c.items[nextNum].style.display = 'block';
	
	//jQuery(c._items[c._cur]).stop().hide("slow");
	//jQuery(c._items[nextNum]).stop().show("slow");
	
	addRoundedImages(jQuery(c._items[nextNum]).find('img'));
	
	c._cur = nextNum;
	setTimeout(function(){
		sliderTMSliderAnim(bannerId,timeout);
	},timeout);
}
function initTMSliderBanner(bannerId, itemClass,timeout) {
	jQuery(document).ready(function(){
		var c = document.getElementById(bannerId);
		if (!c) return;
		c._items = jQuery(c).find('.'+itemClass);
		c._cur = 0;
		addRoundedImages(jQuery(c._items[c._cur]).find('img'));
		if (!c._items.length) return;
		setTimeout(function(){
			sliderTMSliderAnim(bannerId,timeout);
		},timeout);
	});
}

function findAndClickLink(el) {
	var els = jQuery(el).parent('div').find('a');
	if (!els.length)
		return false;
	window.location = els[0].href;
	return false;
}

jQuery(document).ready(function(){
	jQuery("div.imgbigone div.imgsmalltwo:nth-child(2)").addClass("first");
	jQuery("div.partner-list div.partner-list-item:nth-child(3n)").addClass("last");
	//zalaczniki - otwierane w nowych oknach
	attachemntsNewWindow();
});

if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
	viewport = document.querySelector("meta[name=viewport]");
	viewport.setAttribute('content', 'width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;');
}
