/*--------rozwijany kontakt------*/

GetContact = function() {
  $("#contact").load('?page_id=4 #single-page', function() {
  		GetForm();
  		if($('#map').length) {load_map(52.20453,20.995216,13);}
  });
    
  $('#m-kontakt a').click(function() {
      if($(this).hasClass('selected')){
        $(this).removeClass('selected');
        $("#contact").hide();
      }else{					
  			$("#contact").show();	
        $(this).addClass('selected');    
  		}
  		return false;
  });
}

GetContactEN = function() {
  $("#contact").load('?page_id=4&lang=en #single-page', function() {
  		GetForm();
  		if($('#map').length) {load_map(52.20453,20.995216,13);}
  });
    
  $('#m-kontakt a').click(function() {
      if($(this).hasClass('selected')){
        $(this).removeClass('selected');
        $("#contact").hide();
      }else{					
  			$("#contact").show();	
        $(this).addClass('selected');    
  		}
  		return false;
  });
}

/*----------formularz------------*/

GetForm = function() {
  	if ($("#email").attr("value") == '') {
		$('#l-email').addClass('show');
		$('#email').bind('blur',
		function() {
			if (this.value == '')
			$('#l-email').show();
		});

		$('#email').focus(function() {
			$('#l-email').hide();
		});
	} else {
		$('#l-email').hide();
	}

  if ($("#email2").attr("value") == '') {
		$('#l-email2').addClass('show');
		$('#email2').bind('blur',
		function() {
			if (this.value == '')
			$('#l-email2').show();
		});

		$('#email2').focus(function() {
			$('#l-email2').hide();
		});
	} else {
		$('#l-email2').hide();
	}
    
    if ($("#msg").attr("value") == '') {
		$('#l-msg').addClass('show');
		$('#msg').bind('blur',
		function() {
			if (this.value == '')
			$('#l-msg').show();
		});

		$('#msg').focus(function() {
			$('#l-msg').hide();
		});
	} else {
		$('#l-msg').hide();
	}
  
  	if ($("#name").attr("value") == '') {
		$('#l-name').addClass('show');
		$('#name').bind('blur',
		function() {
			if (this.value == '')
			$('#l-name').show();
		});

		$('#name').focus(function() {
			$('#l-name').hide();
		});
	} else {
		$('#l-name').hide();
	}

	$('label.show').bind('click',
	function() {
		$(this).hide();
	}); 	
}	

/*-----zespol - hovery-----*/

GetHover = function() {

$("#team-list li").hover(
    function () {
      $(this).find("a.foto-mini").addClass('hover2');
      $(this).find("a.name").addClass('hover');
      }, 
      function () {
      $(this).find("a.foto-mini").removeClass('hover2');
      $(this).find("a.name").removeClass('hover');
      }
    );
}

/*----------google map--------------*/


var map ;

function createMarker(point, number , icon ) 
{  
	var marker = new GMarker(point,icon);  
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(number);
	});

	return marker;
}

function load_map(lat, lng, zoom) {
	if (GBrowserIsCompatible()) {

		
    	var map = new GMap2(document.getElementById("map"),
								{ size:new GSize(279,207),
								     draggableCursor:"move",
								     draggingCursor:"crosshair"
								} 
							);   

    	map.enableScrollWheelZoom(); 
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
		
		    	map.setCenter(new GLatLng(lat, lng), zoom); 

   
		map.hideControls();  
		GEvent.addListener(map, "mouseover", function(){map.showControls();});  
		GEvent.addListener(map, "mouseout", function(){map.hideControls();});  
		
				
		var point = new GLatLng(lat, lng); 


		var icon = new GIcon();  				

        icon.image = "wp-content/themes/enzo/images/marker.png";
				icon.iconSize = new GSize(42, 32);
				icon.iconAnchor = new GPoint(21, 32);
			//	icon.infoWindowAnchor = new GPoint(12, 2);
			//	icon.infoShadowAnchor = new GPoint(25, 18);
               
		var marker	=	createMarker (point, 'Kancelaria Korolko', icon );
		map.setCenter(point, zoom);
		map.addOverlay(marker);
	}
}


function GUload(lat, lng, zoom, marker) 
{ 
    if (GBrowserIsCompatible()) 
	{ 
    	 map = new GMap2(document.getElementById("map")); 
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
      	map.setCenter(new GLatLng(lat, lng), zoom);
		
		if (marker)
		{
			var point = new GLatLng(lat, lng);  
			var marker = new GMarker(point); 
			map.addOverlay(marker);
		}
    } 
}

/*---------------listy numerowane----------------*/

GetList = function() {
		$("div.text ol li").each(function(){
  		var t = $(this).html(); 
  		$(this).html('<p>'+t+'</p>');
  		$(this).addClass('color');
		});
}

/*---------------menu boczne----------------*/

GetMenu = function() {
    
    $('.s-uslugi ul ul').hide();
    
    $('.s-uslugi .selected').find('ul').show();
    
    $('.s-uslugi .current_page_parent').find('ul').show();

    /*$(".s-uslugi li.d-0 > a").bind('click', function() {
           if ($(this).parent().hasClass('selected')) {
                   $(this).parent().removeClass('selected');
                   $(this).parent().find('ul').slideUp('');
           } else {
                   $('.s-uslugi .selected').removeClass('selected').find('ul').slideUp('fast'); 
                   $('.s-uslugi .current_page_parent').find('ul').slideUp('fast'); 
                   $(this).parent().find('ul').slideDown('');
                   $(this).parent().addClass('selected'); 
           }
            return false;
    });*/
}

/*--------------Cufon-----------------*/

GetCufon = function() {
    
  Cufon.replace('#intro-wrap .text');
			
	Cufon.replace('#intro h2', {
		textShadow: '#0a3445 2px 2px 1px'
  });
  
  Cufon.replace('#single-page h2, #single-page div.text.uslugi-text');
  Cufon.replace('div.text blockquote');
  Cufon.replace('#sub h2');
  Cufon.replace('.s-uslugi li.d-0 > a');
  Cufon.replace('div.text h3');
}

/*-------------------------------*/

  
$(document).ready(function() {

    GetCufon();
    
    //$('#team-list').jScrollHorizontalPane({scrollbarHeight:20, scrollbarMargin:0, showArrows:true});
    
    //$('#team-list').jcarousel();
    
    $('.page-template-main_page-php #uslugi').jcarousel();
    
    GetMenu();
    
    if($.browser.opera || $.browser.webkit){
      $('#search-btn').addClass('opera');
      $('#newsletter-btn').addClass('opera');
    }    
    
      $("#more a.more").bind('click', function() {
             if ($(this).hasClass('show')) {
                     $(this).removeClass('show');
                     $('#more-list').slideUp('slow');
             } else {
                     $('#more-list').slideDown('slow');
                     $(this).addClass('show'); 
             }
             return false;
      });

    
    GetForm();
    
    GetHover();  
    
    GetList();
    
  	if($('#map').length) {load_map(52.20453,20.995216,13);}
 
});
