var shouldBeOn = false;

function activeOff()
{
	$(".active").stop().css("background-position", "0 0");	
}

function activeOn()
{
	$(".active").stop().css("background-position", "0 -20px");
}

function wysun()
{
	$("#fly-menu2").stop().css("padding-top", "29px");
	$("#fly-menu2").stop().animate({height:279},200);	
}
function wsun()
{
	if(!shouldBeOn)
	{
		
		$("#fly-menu2").stop().animate({height:0},100);	
		$("#fly-menu2").animate({paddingTop:'0'},100);
	}
}

$(document).ready(function() {

	
	var className = $("body").attr("class");
	var idName = $("body").attr("id");
	var currentActive = "";
	var currentLanguage = "pl";
	var currentlyHovered = "";
	var hoveredMenu = "";
	var flyMenu_on = false;
	
	
	if(className.search("page-id-4") >= 0)
		currentActive = "homepage";
	else if(className.search("page-id-6") >= 0)
		currentActive = "firma";
	else if(className.search("blog") >= 0 || className.search("single-post") >= 0)
		currentActive = "blog";
	else if(className.search("page-id-16") >= 0 || className.search("page-id-18") >= 0 || className.search("page-id-20") >= 0 || className.search("page-id-23") >= 0 || className.search("page-id-25") >= 0 || className.search("page-id-27") >= 0 || className.search("page-id-31") >= 0 || className.search("page-id-33") >= 0)
		currentActive = "oferta";
	else if(className.search("page-id-8") >= 0)
		currentActive = "klienci";
	else if(className.search("page-id-10") >= 0)
		currentActive = "kariera";
	else if(className.search("page-id-12") >= 0)
		currentActive = "kontakt";
	
	if(className.search("page-id-330") >= 0)
		currentActive = "";
	
	if(idName.search("body-en") >= 0)
		currentLanguage = "en";

	
	if(currentLanguage == "pl")
		{
			switch(currentActive) {
				case "homepage":
					$("#home-pl").css("background-position", "0 -20px");
					$("#home-pl").addClass("active");
					break;
				case "firma":
					$("#firma-pl").css("background-position", "0 -20px");
					$("#firma-pl").addClass("active");
					break;
				case "oferta":
					$("#oferta-pl").css("background-position", "0 -20px");
					$("#oferta-pl").addClass("active");
					break;
				case "klienci":
					$("#klienci-pl").css("background-position", "0 -20px");
					$("#klienci-pl").addClass("active");
					break;
				case "blog":
					$("#blog-pl").css("background-position", "0 -20px");
					$("#blog-pl").addClass("active");
					break;
				case "kariera":
					$("#kariera-pl").css("background-position", "0 -20px");
					$("#kariera-pl").addClass("active");
					break;
				case "kontakt":
					$("#kontakt-pl").css("background-position", "0 -20px");
					$("#kontakt-pl").addClass("active");
					break;	
			}
		}
		else
		{
			switch(currentActive) {
				case "homepage":
					$("#home-en").css("background-position", "0 -20px");
					$("#home-en").addClass("active");
					break;
				case "firma":
					$("#firma-en").css("background-position", "0 -20px");
					$("#firma-en").addClass("active");
					break;
				case "oferta":
					$("#oferta-en").css("background-position", "0 -20px");
					$("#oferta-en").addClass("active");
					break;
				case "klienci":
					$("#klienci-en").css("background-position", "0 -20px");
					$("#klienci-en").addClass("active");
					break;
				case "kariera":
					$("#kariera-en").css("background-position", "0 -20px");
					$("#kariera-en").addClass("active");
					break;
				case "kontakt":
					$("#kontakt-en").css("background-position", "0 -20px");
					$("#kontakt-en").addClass("active");
					break;	
			}
		}
	
	
	
	$("#fly-menu2").stop().css("height", "0px");	
	$("#fly-menu2").stop().css("overflow", "hidden");
	$("#fly-menu2").stop().css("padding-top", "0px");
	$("#fly-menu2").stop().css("display", "inline");
	
	$(".active").stop().css("background-position", "0 -20px");
	var className;
	var isActive;
	$(".menu-item").hover(function() {
		
		className = $(this).attr("class");
		if(className.search("active") >= 0)
			isActive = true;
		else
			isActive = false;
		
		if(!isActive)
		{
			$(".active").stop().css("background-position", "0 0");
			//$(".active").stop().css("margin-left", "-3px");
			//$(".active").stop().animate({marginLeft:0}, 300)
			$(this).stop().css("background-position", "0 -20px");
			$(this).stop().css("margin-left", "-3px");
			$(this).stop().animate({marginLeft:0}, 300);
		}
		
	}, function() {
		
		if(!isActive)
		{
			$(this).stop().css("background-position", "0 0");
			$(this).stop().css("margin-left", "-3px");
			$(this).stop().animate({marginLeft:0}, 300);
			$(".active").stop().css("background-position", "0 -20px");
			//$(".active").stop().css("margin-left", "-3px");
			//$(".active").stop().animate({marginLeft:0}, 300)
		}
		
	});
	
	$(".menu-item").click(function() {
		$(".active").stop().css("background-position", "0 0");
		$(".active").removeClass("active");
		$(this).stop().css("background-position", "0 -20px");
		$(this).stop().css("margin-left", "-3px");
		$(this).stop().animate({marginLeft:0}, 300);
		$(this).addClass("active");
	});
	
	$("#oferta-pl").hover(function() {
		setTimeout('wysun()',100);
	}, function() {
		setTimeout('wsun()',100);
	});
	
	$("#oferta-en").hover(function() {
		setTimeout('wysun()',100);
	}, function() {
		setTimeout('wsun()',100);
	});
	
	
	$("#fly-menu2").hover(function() {
		shouldBeOn = true;
		
		$(".active").stop().css("background-position", "0 0");
		$("#oferta-pl").stop().css("margin-left", "0px");
		$("#oferta-pl").stop().css("background-position", "0 -20px");
		$("#oferta-en").stop().css("margin-left", "0px");
		$("#oferta-en").stop().css("background-position", "0 -20px");
	}, function() {
		shouldBeOn = false;
		setTimeout('wsun()',100);
		$("#oferta-pl").stop().css("background-position", "0 0px");
		$("#oferta-en").stop().css("background-position", "0 0px");
		$(".active").stop().css("background-position", "0 -20px");
	});


	
	$("#top-nav li ul#fly-menu").hover(function() {
		
		flyMenu_on = true;
		
		if(currentLanguage == "pl")
		{
			switch(currentActive) {
				case "homepage":
					if(currentlyHovered != "glowna")
						$("#top-nav li.glowna a").css('backgroundPosition', '-662px 0');
					break;
				case "firma":
					if(currentlyHovered != "firma")
						$("#top-nav li.firma a").css('backgroundPosition', '-804px 0');
					break;
				case "oferta":
					if(currentlyHovered != "oferta" && hoveredMenu != "fly-menu")
						$("#top-nav li.oferta a").css('backgroundPosition', '-880px 0');
					break;
				case "klienci":
					if(currentlyHovered != "klienci")
						$("#top-nav li.klienci a").css('backgroundPosition', '-964px 0');
					break;
				case "blog":
					if(currentlyHovered != "blog")
						$("#top-nav li.blog a").css('backgroundPosition', '-1049px 0');
					break;
				case "kariera":
					if(currentlyHovered != "kariera")
						$("#top-nav li.kariera a").css('backgroundPosition', '-1116px 0');
					break;
				case "kontakt":
					if(currentlyHovered != "kontakt")
						$("#top-nav li.kontakt a").css('backgroundPosition', '-1208px 0');
					break;	
			}
		}
		else
		{
			switch(currentActive) {
				case "homepage":
					if(currentlyHovered != "glowna")
						$("#top-nav li.glowna a").css('backgroundPosition', '-662px 0');
					break;
				case "firma":
					if(currentlyHovered != "firma")
						$("#top-nav li.firma a").css('backgroundPosition', '-741px 0');
					break;
				case "oferta":
					if(currentlyHovered != "oferta" && hoveredMenu != "fly-menu")
						$("#top-nav li.oferta a").css('backgroundPosition', '-848px 0');
					break;
				case "klienci":
					if(currentlyHovered != "klienci")
						$("#top-nav li.klienci a").css('backgroundPosition', '-984px 0');
					break;
				case "blog":
					if(currentlyHovered != "blog")
						$("#top-nav li.blog a").css('backgroundPosition', '-1075px 0');
					break;
				case "kariera":
					if(currentlyHovered != "kariera")
						$("#top-nav li.kariera a").css('backgroundPosition', '-1135px 0');
					break;
				case "kontakt":
					if(currentlyHovered != "kontakt")
						$("#top-nav li.kontakt a").css('backgroundPosition', '-1230px 0');
					break;	
			}
		}
	}, function() {
		
		flyMenu_on = false;
		
		if(currentLanguage == "pl")
		{
			switch(currentActive) {
				case "homepage":
					$("#top-nav li.glowna a").css('backgroundPosition', '0 0');
					break;
				case "firma":
					$("#top-nav li.firma a").css('backgroundPosition', '-153px 0');
					break;
				case "oferta":
					$("#top-nav li.oferta a").css('backgroundPosition', '-229px 0');
					break;
				case "klienci":
					$("#top-nav li.klienci a").css('backgroundPosition', '-313px 0');
					break;
				case "blog":
					$("#top-nav li.blog a").css('backgroundPosition', '-398px 0');
					break;
				case "kariera":
					$("#top-nav li.kariera a").css('backgroundPosition', '-465px 0');
					break;
				case "kontakt":
					$("#top-nav li.kontakt a").css('backgroundPosition', '-557px 0');
					break;
			}
		}
		else
		{
			switch(currentActive)
			{
				case "homepage":
					$("#top-nav li.glowna a").css('backgroundPosition', '0 0');
					break;
				case "firma":
					$("#top-nav li.firma a").css('backgroundPosition', '-79px 0');
					break;
				case "oferta":
					$("#top-nav li.oferta a").css('backgroundPosition', '-186px 0');
					break;
				case "klienci":
					$("#top-nav li.klienci a").css('backgroundPosition', '-322px 0');
					break;
				case "blog":
					$("#top-nav li.blog a").css('backgroundPosition', '-413px 0');
					break;
				case "kariera":
					$("#top-nav li.kariera a").css('backgroundPosition', '-473px 0');
					break;
				case "kontakt":
					$("#top-nav li.kontakt a").css('backgroundPosition', '-568px 0');
					break;
			}	
		}
	});
	
		
$("#top-nav li a").hover(function() {
	
	currentlyHovered = $(this).parent().attr("class");
	
	if(currentlyHovered == "firma")
		$(this).css('z-index', '101');
	if(currentlyHovered == "glowna")
		$(this).css('margin-left', '4');
	
	hoveredMenu =  $(this).parent().parent().attr("id");
	
	
	if(currentLanguage == "pl")
	{
		switch(currentActive) {
			case "homepage":
				if(currentlyHovered != "glowna")
					$("#top-nav li.glowna a").css('backgroundPosition', '-662px 0');
				break;
			case "firma":
				if(currentlyHovered != "firma")
					$("#top-nav li.firma a").css('backgroundPosition', '-804px 0');
				break;
			case "oferta":
				if(currentlyHovered != "oferta" && hoveredMenu != "fly-menu")
					$("#top-nav li.oferta a").css('backgroundPosition', '-880px 0');
				break;
			case "klienci":
				if(currentlyHovered != "klienci")
					$("#top-nav li.klienci a").css('backgroundPosition', '-964px 0');
				break;
			case "blog":
				if(currentlyHovered != "blog")
					$("#top-nav li.blog a").css('backgroundPosition', '-1049px 0');
				break;
			case "kariera":
				if(currentlyHovered != "kariera")
					$("#top-nav li.kariera a").css('backgroundPosition', '-1116px 0');
				break;
			case "kontakt":
				if(currentlyHovered != "kontakt")
					$("#top-nav li.kontakt a").css('backgroundPosition', '-1208px 0');
				break;	
		}
	}
	else
	{
		switch(currentActive) {
			case "homepage":
				if(currentlyHovered != "glowna")
					$("#top-nav li.glowna a").css('backgroundPosition', '-662px 0');
				break;
			case "firma":
				if(currentlyHovered != "firma")
					$("#top-nav li.firma a").css('backgroundPosition', '-741px 0');
				break;
			case "oferta":
				if(currentlyHovered != "oferta" && hoveredMenu != "fly-menu")
					$("#top-nav li.oferta a").css('backgroundPosition', '-848px 0');
				break;
			case "klienci":
				if(currentlyHovered != "klienci")
					$("#top-nav li.klienci a").css('backgroundPosition', '-984px 0');
				break;
			case "blog":
				if(currentlyHovered != "blog")
					$("#top-nav li.blog a").css('backgroundPosition', '-1075px 0');
				break;
			case "kariera":
				if(currentlyHovered != "kariera")
					$("#top-nav li.kariera a").css('backgroundPosition', '-1135px 0');
				break;
			case "kontakt":
				if(currentlyHovered != "kontakt")
					$("#top-nav li.kontakt a").css('backgroundPosition', '-1230px 0');
				break;	
		}
	}
	
}, function() {
	
	if(currentlyHovered == "firma")
		$(this).css('z-index', '99');
	if(currentlyHovered == "glowna")
		$(this).css('margin-left', '-4');
	
	if(currentLanguage == "pl")
	{
		switch(currentActive) {
			case "homepage":
				$("#top-nav li.glowna a").css('backgroundPosition', '0 0');
				break;
			case "firma":
				$("#top-nav li.firma a").css('backgroundPosition', '-153px 0');
				break;
			case "oferta":
				$("#top-nav li.oferta a").css('backgroundPosition', '-229px 0');
				break;
			case "klienci":
				$("#top-nav li.klienci a").css('backgroundPosition', '-313px 0');
				break;
			case "blog":
				$("#top-nav li.blog a").css('backgroundPosition', '-398px 0');
				break;
			case "kariera":
				$("#top-nav li.kariera a").css('backgroundPosition', '-465px 0');
				break;
			case "kontakt":
				$("#top-nav li.kontakt a").css('backgroundPosition', '-557px 0');
				break;
		}
	}
	else
	{
		switch(currentActive)
		{
			case "homepage":
				$("#top-nav li.glowna a").css('backgroundPosition', '0 0');
				break;
			case "firma":
				$("#top-nav li.firma a").css('backgroundPosition', '-79px 0');
				break;
			case "oferta":
				$("#top-nav li.oferta a").css('backgroundPosition', '-186px 0');
				break;
			case "klienci":
				$("#top-nav li.klienci a").css('backgroundPosition', '-322px 0');
				break;
			case "blog":
				$("#top-nav li.blog a").css('backgroundPosition', '-413px 0');
				break;
			case "kariera":
				$("#top-nav li.kariera a").css('backgroundPosition', '-473px 0');
				break;
			case "kontakt":
				$("#top-nav li.kontakt a").css('backgroundPosition', '-568px 0');
				break;
		}	
	}

});




// cufon
Cufon.replace('div.side-nav h2, .cufon', {
	hover: true,
	textShadow: '1px 1px #fff',
	fontFamily: 'Rounded'
});
Cufon.replace('div.side-nav-oferta h2', {
hover: true,
	fontFamily: 'Rounded'
}); 
Cufon.replace('#kontakt-form h2.cufon' ,  {
	hover: true,
	fontFamily: 'Rounded'
});
Cufon.replace('div.txt h1' ,  {
	hover: true,
	fontFamily: 'Rounded'
});
Cufon.replace('div.txt h2' ,  {
	hover: true,
	fontFamily: 'Rounded'
});
Cufon.replace('div.txt h3' ,  {
	hover: true,
	fontFamily: 'Rounded'
});



// divs clickable

$("div.side-nav").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});

// clearing form fields values
	jQuery.fn.cleardefault = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};
jQuery("input, textarea").cleardefault();



// top panel slide out

   $('#slide-link').click(function() {
      if($('#top-panel').hasClass('open')) {
         $('#top-panel').animate({
            top : -95
         }, {
            queue : false
         });
         $('#top-panel').removeClass('open');
      } else {
         $('#top-panel').animate({
            top : -30
         }, {
            queue : false
         });
         $('#top-panel').addClass('open');
      }
      return false;
   });


		$('#fly-menu').each(function () {
		$(this).parent().eq(0).hoverIntent({
			timeout: 100,
			over: function () {
			var current = $('#fly-menu:eq(0)', this);
			current.slideDown(300);
			$('a.oferta').addClass('open');
			},
			out: function () {
			var current = $('#fly-menu:eq(0)', this);
			current.slideUp(300);
			$('a.oferta').removeClass('open');
			}
			});
		});

		

// moving links

 $('ul#top-nav li a.parent,div.slide a, input.wpcf7-submit, a.moveit, form#commentform input#submit').hover(function() {
   $(this).stop().animate({ left: 4 }, 'fast');
  }, function() {
   $(this).stop().animate({ left: 0 }, 'fast');
  });

 $('a.moveit2').hover(function() {
   $(this).stop().animate({ left: 324 }, 'fast');
  }, function() {
   $(this).stop().animate({ left: 320 }, 'fast');
  });
  
  
 $('#fly-menu').hover(function() {
   $('a.oferta').stop().animate({ left: 4 }, 'fast');
  }, function() {
   $('a.oferta').stop().animate({ left: 0 }, 'fast');
  });
  
 $('.column5 a').hover(function() {
   $(this).stop().animate({ top: -5 }, 'fast');
  }, function() {
   $(this).stop().animate({ top: 0 }, 'fast');
  });
  
  
 $('a.open').hover(function() {
   $(this).stop()
  });
  
//fb

var fb_active = false;
var g_active = false;

	$("#facebook-right").click(
	function right(){
		if(!fb_active)
		{
			$(this).animate({ right: "0" }, {queue:false, duration:"slow"} );
			$(this).addClass('open');
			fb_active = true;
		}
		else
		{
			$(this).animate({ right: "-253" }, {queue:false, duration:"slow"} );
			$(this).removeClass('open');
			fb_active = false;
		}
	});


//google
	$("#google-right").click(
	function right(){
		if(!g_active)
		{
			$(this).animate({ right: "0" }, {queue:false, duration:"slow"} );
			$(this).addClass('open');
			g_active = true;
		}
		else
		{
			$(this).animate({ right: "-82" }, {queue:false, duration:"slow"} );
			$(this).removeClass('open');
			g_active = false;
		}
	});



// slider

	$('#slider ul.wrap').anythingSlider({
	   buildStartStop			: false,
	   easing					: "easeInOutExpo",
	   autoPlay					: true,
	   delay						: 7000,
	   autoPlayLocked			: true,
	   resumeDelay				: 10000,
	 	navigationFormatter	: function(index, panel){ 
	   					return ['A', 'B', 'C', 'D', 'E', 'F', 'G'][index - 1];
	   					}
	 }); 
	 
if(screen.width<=1024){
	$('span.arrow').css('display','none');
	$('div.anythingSlider').css('padding','0');
	}
	
	

	
	
		

	  
});



// tooltip script written by Alen Grakalic (http://cssglobe.com)

this.tooltip = function(){	
		xOffset = -15;
		yOffset = 10;		
	$("a.tooltip, ul#qtranslate-chooser li a, li.cat-item a").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.show("fast");
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip, ul#qtranslate-chooser li a, li.cat-item a").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});

var map;
var latlng;
var latlng2;
var coordInfoWindow;

function initializeMap() {
    // Just some canned map for now
    latlng = new google.maps.LatLng(52.258790,20.961630);
    var myOptions = {
        zoom: 16,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.HYBRID
    };
	
	map =  new google.maps.Map($('#mapa')[0], myOptions);
	
	var marker = new google.maps.Marker({
        position: latlng, 
        map: map,
		title:"Adequate - Agencja Interaktywna"
    }); 
	
	coordInfoWindow = new google.maps.InfoWindow({height:'300px'});
	
    coordInfoWindow.setContent('<span style="color:black; font-family:Arial; text-shadow:black 1px; font-size:12px; height:300px; "><span style="position:relative; display:block; font-size:16px; font-weight: bold; color:#1155cc; margin-bottom:7px;">Adequate Sp. z o.o.</span>Powązkowska 15<br />01-797 Warszawa<br />22 326 32 70<br /><a href="#"><span style="color:#1155cc;">adequate.pl</span></a></span>');
    coordInfoWindow.setPosition(latlng);
    coordInfoWindow.open(map);
	
	return map;
}

$(document).ready(function(){
	var map = null;
    map = initializeMap();
	
});


// mapa rozwijana
jQuery(function($){
	
	var map_active = false;
	
    $("#addContent, #addContent2").click(function(e){  
        if(!map_active)
		{
			$("a#addContent").css("display","block");
			
			$("#mapa").animate({height: 600}, 1000, function() {
			
			//map = initializeMap('druga');
   			//google.maps.event.trigger(map, 'resize');
				
			});
			$('html, body').animate({
                     scrollTop: $(document).height()
                 },
                 1500);

			
			map_active = true;
		}
		else
		{
			$("a#addContent").css("display","none");
			$("#mapa").animate({height: 0}, 1000);
			$(this).removeClass('open');
			map_active = false;
		}
    });
});

function podmienMapy()
{
	$("#mapa").css('position', 'relative');
	$("#mapa").css('height', '1');
	$("#mapa").css('top', '0');
	$("#mapa").css('left', '0');
	$("#mapa").css('display', 'inline');
	$("#mapa").animate({height:0});
}
