$(document).ready(function()	{ 
  /*  menu */
  $("div.menu li:last-child").addClass("noborder"); 
        
	/* photogallery */
	$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'facebook' 
		});
    
  /* news*/
   $(".news_info:last-child").addClass("noborder"); 
   $('div.hide').hide();
   $('a.onclick').click(function() {
    $(this).prev().slideToggle('fast');
		if ($(this).html()=="[+]") {
			 $(this).html("[-]");
			 return false;
			 }
		if ($(this).html()=="[-]") $(this).html("[+]");
		return false;
  });
  
/* UI */
/* reg mail */
$("#email").focus(function() {this.value='';	return false;})
$("#name").focus(function() {this.value='';	return false;})
$("#input").focus(function() {this.value='';	return false;})

$("button#cancel_reg_mail").click(function() {window.location.replace("?delete_reg_email=1");})

/* notice */
$("#dialog").dialog({
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
		
/* basket */
    if ($('#invoceanddelivery').is(':checked')) { $("table#delivery").hide();}
    $('#invoceanddelivery').click(function() {
          $("table#delivery").slideToggle('fast');
      });

		
/* kontatky */

  $('div.contact').show();
  $('div.hide_contact').hide();
 
  $('div.contact h2').click(function() {
    $('.show_subdata').hide();
    
    var lan = $(this).parent().find('.google_lat').text();    
    var lng = $(this).parent().find('.google_lng').text();
    $(this).parent().find('img.smallmap').attr('src','http://maps.google.com/maps/api/staticmap?center='+lan+','+lng+'&zoom=14&size=300x200&maptype=roadmap&markers=color:blue|label:C|'+lan+','+lng+'&sensor=false');  
    
    $(this).next().next().slideToggle('fast');    
		$('div.contact').children('div.hide_contact').hide();
    $('div.contact').removeClass("border-top-bottom");
		//alert($(this).html().toLowerCase());
		   
		if ($(this).next().hasClass("plus")) {
         
		    $('div.contact').children('a.onclick_contact').removeClass('x');
		    $('div.contact').children('a.onclick_contact').addClass('plus');
        $(this).next().addClass('x');
        $(this).next().removeClass('plus');
			  $(this).next().parents("div.contact").addClass("border-top-bottom");
			  return false;			 
			 }
		 
		if ($(this).next().hasClass("x")) {
       
        $(this).next().addClass('plus');
        $(this).next().removeClass('x');
        $(this).next().parents("div.contact").removeClass("border-top-bottom");
      }
      
		return false;
  });

    $('a.onclick_contact').click(function() {
   var lan = $(this).parent().find('.google_lat').text();    
    var lng = $(this).parent().find('.google_lng').text();
    $(this).parent().find('img.smallmap').attr('src','http://maps.google.com/maps/api/staticmap?center='+lan+','+lng+'&zoom=14&size=300x200&maptype=roadmap&markers=color:blue|label:C|'+lan+','+lng+'&sensor=false');  
      $('.show_subdata').hide();
    $(this).next().slideToggle('fast');    
		$('div.contact').children('div.hide_contact').hide();
    $('div.contact').removeClass("border-top-bottom");
		//alert($(this).html().toLowerCase());
		   
		if ($(this).hasClass("plus")) {
		    $('div.contact').children('a.onclick_contact').removeClass('x');
		    $('div.contact').children('a.onclick_contact').addClass('plus');
        $(this).addClass('x');
        $(this).removeClass('plus');
			  $(this).parents("div.contact").addClass("border-top-bottom");
			  return false;			 
			 }
		 
		if ($(this).hasClass("x")) {
       
        $(this).addClass('plus');
        $(this).removeClass('x');
        $(this).parents("div.contact").removeClass("border-top-bottom");
      }
      
		return false;
  });

   if ($('div.contact').length)  initialize();
  
});

  

 function initialize() {
    var latlng = new google.maps.LatLng(49.8174920, 15.4729620);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    
    
     $('.contact').each(function() {
      var lan = $('.google_lat',this).text();    
      var lng = $('.google_lng',this).text();
      var text =  $('.address',this).html();
      var name =  $('h2',this).text();
      var image = 'http://www.origine.cz/icon/onebit_05.png';
      var shadow = '/images/shadow.png';
      
      var contentString = '<div class="popup" >'+
        '<h1 class="firstHeading">'+name+'</h1>'+
        '<div id="bodyContent">'+
        '<p>'+text+'</p>'+
        '</div>';
      var infowindow = new google.maps.InfoWindow({
        content: contentString

      });
      
       
      var myLatLng =  new google.maps.LatLng(lan,lng);
     
      var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image,
        shadow: shadow
      });
       google.maps.event.addListener(marker, 'click', function() {
         infowindow.open(map,marker);
      })  
       
    });
       
  }

