/* use to load functions after loading page - jquery util*/
$(document).ready(function() {
  //$("#homePageTitle").remove();

	showHideRealisations('internet', 0);
	showHideRealisations('poligrafia', 0);
	showHideRealisations('inne', 0);
	$('.lightbox').lightbox();
	
	$('div.selectCont').bind("mouseleave", function() {
		$(this).parent().children('div.selectCont').hide();
		$(this).parent().children('div.selectContWind').show();
	});
	$('textarea').bind("mouseover", function() {
		$('div.selectCont').hide();
		$('div.selectContWind').show();
	});
	$('div.selectContWind').bind("mouseenter", function() {
		$(this).parent().children('div.selectContWind').hide();
		$(this).parent().children('div.selectCont').show();
	});
	
	//fixes PNG backgrounds, insert elements into the array
	var pngArray = new Array('div.priceIco', 'div.mainPageGreenRealisation', 'div.ramka_szara_tlo');
	for(i=0; i<=pngArray.length; i++) {
		if(pngArray[i]) {
			var pathTemp = $(pngArray[i]).css('background-image');
			if(pathTemp != 'none' && pathTemp) {
				
				var pathSearchIndex = pathTemp.search(/images\/index/);
				
				var imagePath = pathTemp.slice(pathSearchIndex, pathTemp.indexOf(')'));
				
				$(pngArray[i]).attr('style', 'background-image: url(\''+imagePath.replace(/"/, '')+'\');');
				$(pngArray[i]).ifixpng();
			}
		}
		
	}
	
	//fixes all the rest PNG img
	$('img[@src$=.png]').ifixpng();
	
	$('a.mails').each(function(i) {
		var email = $(this).html();
		var replaced = email.replace(/ymaspy/,".");
		$(this).html(replaced);
		$(this).attr('href', 'mailto:'+replaced);
	});
	
}
);

function showHideRealisations(divRealizations, iIndex) {
	var notFadedOut = true;
	var wait = false;
	$('div#' + divRealizations + '_realizations div.realisation').each(function(index) {
		if($(this).css('opacity') != 1) {
			wait = true;
		}
	});
	if (!wait) {
		//pager
		if ($('div#' + divRealizations + '_pager div a:eq(' + iIndex + ')').hasClass('first')) {
			$('div#' + divRealizations + '_pager div a:eq(' + iIndex + ')').addClass('first_checked');
		}
		else {
			$('div#' + divRealizations + '_pager div a:eq(' + iIndex + ')').addClass('checked');
		}
		$('div#' + divRealizations + '_pager div a:lt(' + iIndex + ')').removeClass('checked').removeClass('first_checked');
		$('div#' + divRealizations + '_pager div a:gt(' + iIndex + ')').removeClass('checked').removeClass('first_checked');
		
		//content
		$('div#' + divRealizations + '_realizations div.realisationWaiting').remove();
		$('div#' + divRealizations + '_realizations div.realisation').each(function(index){
			if ($(this).css('display') == 'block') {
				$(this).fadeOut('slow', function(){
					$('div#' + divRealizations + '_realizations div.realisation:eq(' + iIndex + ')').fadeIn('slow');
				});
				notFadedOut = false;
			}
		});
		if (notFadedOut) {
			$('div#' + divRealizations + '_realizations div.realisation:eq(' + iIndex + ')').fadeIn('slow');
		}
	}
}

function showHideSelect(id) {
	$('div#'+id+' div.selectContWind, div#'+id+' div.selectCont').toggle();
}

function insertemail(){
	$('div#kontakt_email').html('<strong>E-mail:</strong> <a href="mailto:biuro@vert.pl">biuro@vert.pl</a>');
}

function insertToHtmlSelect(obj) {
	//removes active
	$(obj).parent().parent().find('div.selectCont a.box').removeClass('active');
	$(obj).addClass('active');
	$(obj).parent().parent().find("input[type='hidden']").val($(obj).html());
	$(obj).parent().parent().find('div.selectContWind div.centerCont, div.selectCont div.centerCont').html($(obj).html());
	$(obj).parent().parent().find('div.selectContWind').show();
	$(obj).parent().parent().find('div.selectCont').hide();
}

function disableAnimation(){
	 $.ajax({
	   type: "GET",
	   url: "http://www.vert.pl/index/index/disableanim/noreturn/true",
	   data: "",
	   success: function(msg){
	   }
	 });

}