$(document).ready(function() {

  $(".slideshow_content").cycle({ 
  fx:     'fade',
  speed: 	'slow',
  prev:   '.prev', 
  next:	'.next',
  pager:	'#slideshow_pager',   
  timeout: 10000
  });

  $("#newsletter_form").submit(function() {  
    dataString = $("#newsletter_form").serialize(); 
    input = $("#newsletter_email");
    
    $('#newsletter_submit').attr("disabled", "true");
    input.val(txt_prosze_czekac);

    $.ajax({  
      type: "POST",  
      url: "includes/newsletter_dodaj.php",  
      data: dataString+'&language='+language,
      dataType: "html",  
     
      success: function(data) {  
        $.prompt(data); 
        $('#newsletter_submit').removeAttr("disabled");
        input.val(txt_newsletter_email);      
      }  
    });  
    return false;
  });
  
  $("#footer_kontakt_form").submit(function() {  
    dataString = $("#footer_kontakt_form").serialize(); 
    div_loader = $("#footer_kontakt_loader");
    div_loader.html('<img src="images/ajax_loader.gif" alt="" />');
    
    $('#footer_kontakt_submit').attr("disabled", "true");

    $.ajax({  
      type: "POST",  
      url: "includes/kontakt_wyslij.php",  
      data: dataString+'&language='+language,
      dataType: "html",  
     
      success: function(data) {  
        $.prompt(data); 
        $('#footer_kontakt_submit').removeAttr("disabled");
        div_loader.html('');    
      }  
    });  
    return false;
  });  

  $("#szukana_fraza_input").click(function() {
    if($.trim($(this).val())==txt_szukana_fraza) $(this).val(''); 
   
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_szukana_fraza); 
    }); 
  }); 

  $("#newsletter_email").click(function() {
    if($.trim($(this).val())==txt_newsletter_email) $(this).val(''); 
    
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_newsletter_email); 
    }); 
  });

  $("#footer_kontakt_imie_input").click(function() {
    if($.trim($(this).val())==txt_kontakt_imie) $(this).val(''); 
    
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_kontakt_imie); 
    }); 
  });

  $("#footer_kontakt_email_input").click(function() {
    if($.trim($(this).val())==txt_kontakt_email) $(this).val(''); 
    
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_kontakt_email); 
    }); 
  });

  $("#footer_kontakt_telefon_input").click(function() {
    if($.trim($(this).val())==txt_kontakt_telefon) $(this).val(''); 
    
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_kontakt_telefon); 
    }); 
  });  

  $("#footer_kontakt_tresc_input").click(function() {
    if($.trim($(this).val())==txt_kontakt_tresc) $(this).val(''); 
    
    $(this).focusout(function() {
      if($.trim($(this).val())=='') $(this).val(txt_kontakt_tresc); 
    }); 
  }); 
  
 //Tabs
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$("#tabs_content_top").addClass("tab1");

	$(".tab_content:first").show(); //Show first tab content

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$("#tabs_content_top").removeClass();
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
    
    $("#tabs_content_top").addClass(activeTab.replace("#", ""));
    
		return false;
	});
	
  //Language select
  $('#language_btn').click(function() {
    $('#language_select_container').slideToggle('fast');
  });
  
  $('#language_select_container').mouseleave(function() {
    $(this).slideToggle('fast');
  });  

  $('a.lightbox').lightBox(); 

  //Tooltip
  $.fn.ezpz_tooltip.positions.topLeft = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
  	contentInfo['left'] = 320;
  	contentInfo['top'] = targetInfo['top']-200;
  
  	return contentInfo;
  };

  //Tooltip - produkty
  $('.produkt_siatka_img').click(function() {
    tooltip_id_prod=$(this).attr('id').replace('p_', '');
  });  
    
   $(".produkt_siatka_img").ezpz_tooltip({
    contentPosition: 'topLeft', 
    contentId: 'tooltip_container',
    
    /*showContent: function(content) {
		  content.slideToggle('fast');
    },
    
    hideContent: function(content) {
		  content.stop(true, true).slideToggle('fast');
    },*/
    
  	beforeShow: function(content){  
     
      $.ajax({  
        type: "GET",  
        url: "includes/produkty_pobierz_szczegoly.php",  
        data: 'id='+tooltip_id_prod+'&language='+language,
        dataType: "html",  
             
        success: function(data) {  
          $("#tooltip_ajax_content").html(data); 
          $('a.lightbox').lightBox();   
        }  
      });   
  	}
  }); 

  //Tooltip - obiekty referencyjne
/*
  $('.obiekt_img').click(function() {
    tooltip_id_obiektu=$(this).attr('id').replace('o_', '');
  });  
    
   $(".obiekt_img").ezpz_tooltip({
    contentPosition: 'topLeft', 
    contentId: 'tooltip_container',
    
    /*showContent: function(content) {
		  content.slideToggle('fast');
    },
    
    hideContent: function(content) {
		  content.stop(true, true).slideToggle('fast');
    },*/
/*    
  	beforeShow: function(content){  
     
      $.ajax({  
        type: "GET",  
        url: "includes/obiekty_ref_pobierz_szczegoly.php",  
        data: 'id='+tooltip_id_obiektu+'&language='+language,
        dataType: "html",  
             
        success: function(data) {  
          $("#tooltip_ajax_content").html(data); 
          $('a.lightbox').lightBox();   
        }  
      });   
  	}
  });  
*/  
  $('#tooltip_container').mouseleave(function() {
    $(this).toggle();
  });   	

  $('#region').change(function() {
    var id = $(this).val();
    var country = $('#country');
    var dealerzy_container = $('#dealerzy_container');
    
    country.html('<option value="">loading...</option>');
    dealerzy_container.slideUp();

    $.ajax({  
      type: "GET",  
      url: "includes/pobierz_kraje.php",  
      data: 'id='+id,
      dataType: "html",  
           
      success: function(data) {  
        country.html(data);   
      }  
    }); 
  });
  
  $('#country').change(function() {
    var id = $(this).val();
    var dealerzy_container = $('#dealerzy_container');
    
    dealerzy_container.slideUp();
    dealerzy_container.html('loading...');

    $.ajax({  
      type: "GET",  
      url: "includes/pobierz_dealerow.php",  
      data: 'id='+id,
      dataType: "html",  
           
      success: function(data) {  
      dealerzy_container.slideDown();
        dealerzy_container.html(data);   
      }  
    }); 
  });  

  $('.zwin_btn').click(function() {
    if($(this).attr('src')=='images/zwin_btn.jpg')
      $(this).attr('src', 'images/rozwin_btn.jpg');
    else
      $(this).attr('src', 'images/zwin_btn.jpg');
    
    $('#zwin_content').slideToggle('slow');
  })  
  

    		
})

