//Grab the href, open it in a window and cancel the click action

 $(document).ready(function(){
   $("#main-in a[href^='http']").click(function(){
     window.open(this.href);
     return false;
   }).attr("title", "Otevřít v novém okně").addClass("ext");

   // Contact form
   /*$.get('token.php', function(txt) {
     $('#indexform form p').append('<input type="hidden" name="ts" value="'+txt+'" />');
   });*/
  
   // Vine image 
   $("a.vineimg").fancybox({
     'margin' : 50,
     'padding' : 50,
     'titleShow' : 'false'
   });
   
   // Photogallery 
   $(".photoItem a").fancybox({
     'titleShow' : 'false'
   });
   
   /* Vyhledavani - zmeny selectu pri zmene */
   // Vyber zeme
   $('#fZeme').change(function() {
     var zemeVal = $('#fZeme').val();
     $.ajax({
       type: "POST",
       dataType: "html",
       url: "/ajax.php",
       data: "action=select-country&zeme="+zemeVal,
       success: function(data) {
         $('#fOblast').html(data);
       }
     });
     $.ajax({
       type: "POST",
       dataType: "html",
       url: "/ajax.php",
       data: "action=select-country-vineculture&zeme="+zemeVal,
       success: function(data) {
         $('#fVinarstvi').html(data);
       }
     });
   });
   
   // Vyber oblasti
   $('#fOblast').change(function() {
     var oblastVal = $('#fOblast').val();
     var zemeVal = $('#fZeme').val();
     if (oblastVal == '') {
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "/ajax.php",
         data: "action=select-country-vineculture&zeme="+zemeVal,
         success: function(data) {
           $('#fVinarstvi').html(data);
         }
       });
     } else {
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "/ajax.php",
         data: "action=select-area&oblast="+oblastVal,
         success: function(data) {
           $('#fVinarstvi').html(data);
         }
       });
       $.ajax({
         type: "POST",
         dataType: "html",
         url: "/ajax.php",
         data: "action=select-area-country&oblast="+oblastVal,
         success: function(data) {
           $('#fZeme').html(data);
         }
       });
     }
   });
   
   // Vyber vinarstvi
   $('#fVinarstvi').change(function() {
     var vinarVal = $('#fVinarstvi').val();
     $.ajax({
       type: "POST",
       dataType: "html",
       url: "/ajax.php",
       data: "action=select-vineculture-country&vinarstvi="+vinarVal,
       success: function(data) {
         $('#fZeme').html(data);
       }
     });
     $.ajax({
       type: "POST",
       dataType: "html",
       url: "/ajax.php",
       data: "action=select-vineculture-area&vinarstvi="+vinarVal,
       success: function(data) {
         $('#fOblast').html(data);
       }
     });
   });
   
   // Obchod
   var options = { 
     target:        '#shopbox'   // target element(s) to be updated with server response 
     //beforeSubmit:  showRequest,  // pre-submit callback 
     //success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind to the form's submit event 
    $('.shop form').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
        
        	$.fancybox(
		'<p>Zboží bylo přidáno do košíku.</p><p class="shop-buy"><a href="#" onclick="$.fancybox.close();return false;">Pokračovat v nákupu</a> <a href="/nakupni-kosik">Zobrazit košík</a></p>',
		{
        		'autoDimensions'	: false,
			'width'         		: 350,
			'height'        		: 'auto',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		}
	);

        
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 

});
