//// -------------------------------------------------------------------------------
		$(document).ready(function(){

			
// linki w nowym oknie			
			$('a[rel="external"]').click( function() {
        		window.open( $(this).attr('href') );
        		return false;});
				
				$('a[rel="external"]').filter(function() {
         return this.hostname && this.hostname !== location.hostname;
        }).addClass('externalLink');
//----------------------------------------------------------------------------------------------------------------------------------

// link blur		
			$("a").focus(function() {
  			$(this).blur();
			});
//----------------------------------------------------------------------------------------------------------------------------------
	
// logo scroll
			$.easing.custom = function (x, t, b, c, d) {
			var s = 1.70158; 
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;}
	
		
			 $("#chained").scrollable({size: 5, clickable: false, easing: 'custom', speed: 1000}).autoscroll({steps: 1, interval: 10000, easing: 'custom', speed: 1000}).		circular().mousewheel( {steps: 1});
//----------------------------------------------------------------------------------------------------------------------------------
 
 
//starpage tabs
 			$("#maszyny-taby ul").tabs("#panes > div", {effect: 'fade', fadeOutSpeed: 400}).history();
//----------------------------------------------------------------------------------------------------------------------------------
 
//accordion
			$('ul.accordion').accordion();
//----------------------------------------------------------------------------------------------------------------------------------

//fancybox
			//galeria maszyny 
			$("#tab2 a").fancybox();
			
			//galeria aktualnosci
			$(".aktualnosci_item .galeria a").fancybox();
			
			$("a.fancy").fancybox();			

			$("a.kariera_form").fancybox({'width':640,'height':400,'scrolling': 'no','autoScale':false,'transitionIn':'fade','transitionOut':'fade','hideOnOverlayClick':false,'type':'iframe'});

//----------------------------------------------------------------------------------------------------------------------------------

// formularz kontaktowy

			$("#ajax-contact-form").submit(function(){

			var str = $(this).serialize();

  				 $.ajax({
  				 type: "POST",
 				 url: "/inc/email/contact.php",
 				 data: str,
  				success: function(msg){
    
			$("#note").ajaxComplete(function(event, request, settings){

			if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
			{
			result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';

			$("#fields").hide();
			}
			else
			{
			result = msg;
			}

			$(this).html(result);

			});

			}

			 });

			return false;

			});

// formularz kontaktowy

			$("#ajax-kariera-form").submit(function(){

			var str = $(this).serialize();

  				 $.ajax({
  				 type: "POST",
 				 url: "/inc/email/contact.php",
 				 data: str,
  				success: function(msg){
    
			$("#note").ajaxComplete(function(event, request, settings){

			if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
			{
			result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';

			$("#fields").hide();
			}
			else
			{
			result = msg;
			}

			$(this).html(result);

			});

			}

			 });

			return false;

			});
//----------------------------------------------------------------------------------------------------------------------------------

// hover dla elemnetow logoscrolla
			$("div.items div.scroll_item").hover(function() { //On hover...

				var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
			$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
			$(this).find("span").stop().fadeTo('normal', 0 , function() {
				$(this).hide() //Hide the image after fade
				});
			} , function() { //on hover out...
		//Fade the image to full opacity 
				$(this).find("span").stop().fadeTo('normal', 1).show();
			});
//----------------------------------------------------------------------------------------------------------------------------------


// dodawanie ikon dla zalącznikow

	// pdf 
	$("a[href$='.pdf']").addClass("pdf");
	 
	// txt (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("txt");

	// zip (zip, rar)
	$("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
	
	// Add email icons to email links
	//$("a[href^='mailto:']").addClass("email");

	// external link 
	//$('a').filter(function() {
		///Compare the anchor tag's host name with location's host name
	  //  return this.hostname && this.hostname !== location.hostname;
	 // }).addClass("external");


// samepage scroll


// Animated Scrolling for Same-Page Links
// @see http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links

$.fn.smoothScroll = function(options) {
  var opts = $.extend({}, $.fn.smoothScroll.defaults, options),
      locationPath = filterPath(location.pathname),
      scrollElem = scrollableElement('html', 'body');
      
  this.each(function() {
    var link = this,
        $link = $(this),
        hostMatch = ((location.hostname === link.hostname) || !link.hostname),
        pathMatch = (filterPath(link.pathname) || locationPath) === locationPath,
        thisHash = link.hash && link.hash.replace('#',''),
        scrollTargetExists = thisHash && !!$('#' + thisHash).length;

    if (hostMatch && pathMatch && scrollTargetExists) {
      var include = true,

          exclude = opts.exclude,
          elCounter = 0,
          el = exclude.length,

          excludeWithin = opts.excludeWithin,
          ewlCounter = 0,
          ewl = excludeWithin.length;
       
      while (include && elCounter < el) {
        if ($link.is(exclude[elCounter++])) {
          include = false;
        }
      }
      while (include && ewlCounter < ewl) {
        if ($link.parents(excludeWithin[ewlCounter++] + ':first').length) {
          include = false;
        }
      }

      if (include) {
        $link.data('scrollTarget', '#' + thisHash);
      }
    }

  });

  
  this.die('click.smoothscroll').live('click.smoothscroll', function(event) {
    var scrollTargetId = $(this).data('scrollTarget');
    if (scrollTargetId) {
      event.preventDefault();
       
      var scrollTargetOffset = $(scrollTargetId).offset().top;

      $(scrollElem).animate({scrollTop: scrollTargetOffset + opts.offset}, 400, function() {
        // location.hash = target;
      });
    }
  });
  return this;
  
  // private functions
  
  // don't pass window or document
  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i < argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop() > 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop() > 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }
  
  function filterPath(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'');
  }
  
  function debug($obj) {
    if (window.console && window.console.log) {
      window.console.log($obj);
    }
  }
};

// default options
$.fn.smoothScroll.defaults = {
  exclude: [],
  excludeWithin:[],
  offset: 0
};







//----------------------------------------------------------------------------------------------------------------------------------
		});
//// ------------------------------------------------------------------------------	





//// ------------------------------------------------------------------------------	PLUG INS START

// -------------------------------------------------------------------------------	
// -------------------------------------------------------------------------------	
(function($){ 
     $.fn.extend({  
         accordion: function() {       
            return this.each(function() {
				if($(this).data('accordiated'))
					return false;									
				$.each($(this).find('ul, li>div'), function(){
					$(this).data('accordiated', true);
					$(this).hide();
				});
				$.each($(this).find('a:not(.foo)'), function(){
					$(this).click(function(e){
						activate(e.target);
						return void(0);
					});
				});
				
				var active = false;
				if(location.hash)
					active = $(this).find('a[href=' + location.hash + ']')[0];
				else if($(this).find('li.current'))
					active = $(this).find('li.current a')[0]; 
				
				if(active){
					activate(active, 'toggle','parents');
					$(active).parents().show();
				}
				
				function activate(el,effect,parents){
					$(el)[(parents || 'parent')]('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
					$(el).siblings('ul, div')[(effect || 'slideToggle')]((!effect)?'fast':null);
				}
				
            });
        } 
    }); 
})(jQuery);



// -------------------------------------------------------------------------------	
// -------------------------------------------------------------------------------	

/* Plugin: safe_mail
 * Author: Michael D. Risser <MDRISSER AT the domain called GMAIL which is a dot COM>
 * Date: October 2007
 *
 * Description:
 *		With the proliferation of spammers out there, scrapping email addresses off of web sites,
 *		this plugin for jQuery makes it easy to hide email address from spam bots.
 *		
 *		The plugin is far from perfect, but it works, although I plan to expand on it as time permits.
 *		Usage is pretty straight forward, as shown below. The only caveat is that you need an element to
 *		append the mailto link to. You can simply place an empty div or span where you want the email link to
 *		appear, and access it using the id you have provided. For example:
 *			<p>Here is a bunch of text in a paragraph, where I want an <span id='email_link'></span> to
 *			appear. Since the plugin appends to an element, I've included an empty span tag where I want
 *			the email address to appear.</p>
 * Usage:
 *		To use the email address as the link text:
 *			$('#email_link').safe_mail("john.doe", "domain", "com");
 *			Ouput: <a href="mailto:john.doe@domain.com">john.doe@domain.com</a>
 *
 *		To use some other text as the link text:
 *			$('#email_link').safe_mail("john.doe", "domain", "com", "This is my email link text");
 *			Ouput: <a href="mailto:john.doe@domain.com">This is my email link text</a>
 */

jQuery.fn.safe_mail = function(username, domain_name, domain_ext, link_text) {
	if(link_text) {
		link_txt = link_text;
	} else {
		link_txt = "link"	
	}
	
	// If no link text(link_txt) is specified, or if the user explicitally sets link_txt to "link"
	if(link_txt == "link") {
		// Use the link its self as the link text
		mail_link = "<a class=tooltip title=WYŚLIJ-WIADOMOŚĆ" + " href" + "=" + "'mail" + "to" + ":" + username + "@" + domain_name + "." + domain_ext +"'>" + username + "@" + domain_name + "." + domain_ext +"</a>";
	} else {
		// Otherwise use the user provided link text
		mail_link = "<a class=tooltip title=WYŚLIJ-WIADOMOŚĆ" + " href" + "=" + "'mail" + "to" + ":" + username + "@" + domain_name + "." + domain_ext +"'>" + link_txt +"</a>";
	}
	
	$(this).append(mail_link);
};






// -------------------------------------------------------------------------------	
// -------------------------------------------------------------------------------			
/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").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")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
// -------------------------------------------------------------------------------	
// -------------------------------------------------------------------------------	


//// ------------------------------------------------------------------------------	PLUG INS END


// starting the script on page load
/*
$(document).ready(function(){						 

	// Set the transparent pixel
	jQuery.ifixpng('/blank.gif');
	jQuery('#pasek_banery_start').ifixpng();
});		
		
*/
