// JavaScript Document

function switch_product_img(divName, totalImgs) {
			for (var i=1; i<=totalImgs; i++) {
				var showDivName = 'photo_' + i;
				var showObj = document.getElementById(showDivName);
				if (showDivName == divName)
					showObj.style.display = 'block';
				else
					showObj.style.display = 'none';
				}
}

$(document).ready(function() {
						   
	Cufon.replace('#slog1');
						   
	$(window).load(function() {
		$('.galKlienci').nivoSlider({
			effect:'random', //Specify sets like: 'fold,fade,sliceDown'
			slices:10,
			animSpeed:500,
			pauseTime:3000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:false, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:false, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:false, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	});
	
//	if ($('.refBox').length != 0){
//	$(window).load(function() {
//		$('.refBox').nivoSlider({
//			effect:'random', //Specify sets like: 'fold,fade,sliceDown'
//			slices:10,
//			animSpeed:500,
//			pauseTime:3000,
//			startSlide:0, //Set starting Slide (0 index)
//			directionNav:false, //Next & Prev
//			directionNavHide:true, //Only show on hover
//			controlNav:false, //1,2,3...
//			controlNavThumbs:false, //Use thumbnails for Control Nav
//			controlNavThumbsFromRel:false, //Use image rel for thumbs
//			controlNavThumbsSearch: '.jpg', //Replace this with...
//			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
//			keyboardNav:false, //Use left & right arrows
//			pauseOnHover:true, //Stop animation while hovering
//			manualAdvance:false, //Force manual transitions
//			captionOpacity:0.8, //Universal caption opacity
//			beforeChange: function(){},
//			afterChange: function(){},
//			slideshowEnd: function(){} //Triggers after all slides have been shown
//		});
//	});
//	
//	//$("a[rel^='relferencja']").prettyPhoto({theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square / facebook */});
//	
//	}
	
	if ($('.fillIMGbox').length != 0){
	
	
	//$("a[rel^='relferencja']").prettyPhoto({theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square / facebook */});
	
	}
	
	
	
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square / facebook */});
	
	$('.blink').blink();
	$('.current').blink();
	$('.folioLoader').hide();
	$('#showr').hide();
	//$("#slog1").hide();
	//$("#slog2").hide();
	
	$('a#backtotop').click(function(){
		 $('html, body').animate({scrollTop: '0px'}, 'fast');
		 return false;
	});
	

	$("#showr").click(function () {
	  $(".columnF").show("1000", function () {
		/* use callee so don't have to name the function */
		$(this).next(".columnF").show("2000", arguments.callee);
	  });
	  $('#showr').hide();
	  $('#showrH').show();
	  return false;
	});
	
	$("#showrH").click(function () {
	  $(".columnF").hide("1000", function () {
		/* use callee so don't have to name the function */
		$(this).next(".columnF").hide("2000", arguments.callee);
	  });
	  $('#showrH').hide();
	  $('#showr').show();
	  return false;
	});
	
	/*$('.galKlienci img').hide();
	$('.galKlienci img').hide().each(function(index){
		var $li = $(this);

			setTimeout(function() {
				$li.fadeTo("slow", 0.5);
			}, index * 200);
	});
	
	$(".galKlienci img").hover(
	  function () {
		$(this).fadeTo("fast", 1);
	  },
	  function () {
		$(this).fadeTo("fast", 0.5);
	  }
	);*/
	
	/*$('.galgaleryFull img').hide();
	$('.galgaleryFull img').hide().each(function(index){
		var $li = $(this);

			setTimeout(function() {
				$li.fadeTo("slow", 0.5);
			}, index * 200);
	});*/
	
	$(".galgaleryFull img").hover(
	  function () {
		//$(this).parent("a").find("span").fadeTo("fast", 1);
	  },
	  function () {
		//$(this).parent("a").find("span").fadeTo("fast", 0.5);
	  }
	);
	
	$(".panoramaCennik .cwierc").fadeTo("fast", 0.8);
	$(".panoramaCennik .cwierc").hover(
	  function () {
		$(this).fadeTo("fast", 1);
	  },
	  function () {
		$(this).fadeTo("fast", 0.8);
	  }
	);
	
	
	

	
	
	
//	$("#slog1").fadeIn(1000).animate({"padding-left":0}, 1200, function() {
//		$("#slog2").fadeIn(1000);
//	});
	 
	
	$("#topnav li").prepend('<span></span>'); //Throws an empty span tag right before the a tag

	$("#topnav li").each(function() { //For each list item...
		var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
		$(this).find('span').show().html(linkText); //Add the text in the <span> tag
	}); 

	$("#topnav li").hover(function() {	//On hover...
		$(this).find('span').stop().animate({
			marginTop: "-30" //Find the <span> tag and move it up 40 pixels
		}, 150);
	} , function() { //On hover out...
		$(this).find('span').stop().animate({
			marginTop: "0"  //Move the <span> back to its original state (0px)
		}, 150);
	});
	
	$('.offerBoxLi .info').jScrollPane(
						{
							showArrows:true, 
							scrollbarWidth: 13,
							reinitialiseOnImageLoad: true
						}
					);
//	$('.galgaleryFull').jScrollPane();

//	
//	$('#slider').s3Slider({
//            timeOut: 7000
//    });
//	
//	$('#sliderA').s3Slider({
//            timeOut: 8000
//    });
//	
//	$('#sliderB').s3Slider({
//            timeOut: 9000
//    });
	
//	$(".FullImgBox").hover(
//	  function () {
//		$(this).animate({
//			height: '240px'
//		  }, 200);
//	  },
//	  function () {
//		$(this).animate({
//			height: '200px'
//		  }, 300);
//	  }
//	);	
	
	
	/*$(".galgaleryFull img").click(function () {
		
		$('.FullImgBox img').fadeOut(50);
		var image = $(this).attr("id");
		var tytul = $(this).attr("title");
		var opis = $(this).attr("alt");
		$(".logDiv").html('<div class="podgladBox"><a href="#">ZOOM</a></div><strong>' + tytul + '</strong>' + '<br/>' + opis);
		//$('.FullImgBox img').attr({src: 'portfolio/' + image});
		
		var image1 = $('.FullImgBox img').attr('src', 'portfolio/' + image).load(function(response, status, xhr){
        	$('.FullImgBox img').fadeIn(100);
			
		  if (status == "error") {
			var msg = "Wystapil blad skryptu: ";
			$(".FullImgBox").text('');
			$(".FullImgBox").text(msg + xhr.status + " " + xhr.statusText);
		  } else {
			  $('.FullImgBox img').show();
		  }
        // Your other custom code
		});
		
		
		
		
		return false;
	});*/
	
	$('.faQm li a').click(function(){
			return false;
	});
	
	//$('.topBoxes .columTextBox').equalHeights();
	//$('.topBoxes .fixCollH').last().css('borderRightWidth', '0px');
	
	$(".galgaleryFull fillIMGbox:odd").css({"margin-right":"0px"});
	$(".galgaleryFull fillIMGbox:odd").css({"padding-right":"0px"});
	$(".galgaleryFull fillIMGbox:even").addClass("odstepLine");
	
	$('.galgaleryFull img').hide();
	
	$('.galgaleryFull img').onImagesLoaded(function(_img){
		$(_img).fadeIn("slow");
	});
	
	$('.switch').first().show();
	
	$(".butTG").click(function () {
		var dispDiv = $(this).attr("rel");
				
		//if($("#"+dispDiv).is(':hidden')) {
			$('.switch').css({"display":"none"})
		//}
		$("#"+dispDiv).show();
		
		return false;
	
	});
	
	$(".mapframe").hover(
	  function () {
		$(this).find("iframe").fadeIn(function() {
        // Animation complete
      });
	  }, 
	  function () {
		$(this).find("iframe").fadeOut();
	  }
	);
	
	
	$('#kontaktSubmit').click(function() {
		$('#kontaktForm').submit();
		$("#kontaktForm").hide();
		$(".formLog").hide();
		$('.formLoader').show();
		return false;
		
	});
	
    $('#kontaktForm').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '.formLog', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function(msg){ 
             
			if (msg == 'ok') {
                 //$('.errorBox').text(msg);
				 $(".formLog").hide();
				 $('.formLoader').hide();
				 
				 //$(".sendOK").show();
				 clearForm('#kontaktForm');
				 $("#kontaktForm").show();
				 //$('.errorBox').fadeIn();
               } else {

		$('.formLoader').hide();
		$(".formLog").show();
		$(".formLog").html(msg);
		$("#kontaktForm").show();
		}
			
        } 
    });
	
	
	function clearForm(form) {
	  // iterate over all of the inputs for the form
	  // element that was passed in
	  $(':input', form).each(function() {
		var type = this.type;
		var tag = this.tagName.toLowerCase(); // normalize case
		// it's ok to reset the value attr of text inputs,
		// password inputs, and textareas
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = "";
		// checkboxes and radios need to have their checked state cleared
		// but should *not* have their 'value' changed
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		// select elements need to have their 'selectedIndex' property set to -1
		// (this works for both single and multiple select elements)
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};

	$('#slog1').css({opacity:0});
	$("#slog1").animate({opacity:1, "padding-left":0}, 1200, function() {
		$("#slog2").animate({opacity:1}, 600);
	});
	var int = setInterval(changeText, 5000);	
	
	function changeText(){
		var $activeText = $("#slog1");	
		var $activeText2 = $("#slog2");
		$activeText2.animate({opacity:0}, 200);
		$activeText.animate({opacity:0}, 300);
		$activeText.animate({"padding-left": "80"});
		$("#slog1").animate({opacity:1, "padding-left":0}, 1200, function() {
			$("#slog2").animate({opacity:1}, 600);
		});
	}
	
	
		
	
	
	var counter = $(".box .inBox").length;
	
	function siedemAnimation(){
		
		var cur = $(".box .start").index();
		var licznik = $(".box .start").index();
		
		licznik = licznik+1;
		
		var nextItem = cur+1;
		
		//$('.start h2 span').text(licznik);
		
		if (licznik+1 <= counter){
		//$('.inBox').eq(cur).hide();
		$('.inBox').eq(cur).removeClass('start');
		$('.inBox').eq(nextItem).addClass('start');
		} else {
			$('.inBox').last().removeClass('start');
			$('.inBox').first().addClass('start');
			//$('.inBox').first().show();
		}

	}
	
	var intX = setInterval(siedemAnimation, 5000);
	
	
});
