// JavaScript Document

(function($) {
/**
 * @author Alexander Farkas
 * v. 1.22
 */
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = $.curCSS;
		$.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			fx.start = [start[0],start[2]];
			var end = toArray(fx.end);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

$(document).ready(function() {

lightbox_start();

var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

	if (Browser.Version() > 8) $("#new_img").rotate({ 
	   bind: 
		 { 
			mouseover : function() { 
				$(this).rotate({animateTo:17})
			},
			mouseout : function() { 
				$(this).rotate({animateTo:0})
			}
		 } 
	   
	});
	
	$('#nav a li')
		.mouseover(function(){
			if($(this).parent().attr('class') != 'active')
			{
				$(this).css( {color: "#000"} );
				$(this).stop().animate({backgroundPosition:"(-180px 0)"}, {duration:500});
			}
		})
		.mouseout(function(){
			if($(this).parent().attr('class') != 'active')
			{
				$(this).stop().animate({backgroundPosition:"(-350px 0)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 0",color: "#FFF"}); }})
			}
		});
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 2500 );
});


//Validacja formularza kontaktowego
function send_form()
{
	var error = false;
	document.getElementById('error_1').innerHTML = "*";
	document.getElementById('error_2').innerHTML = "*";
	document.getElementById('error_3').innerHTML = "*";
	
	if(document.getElementById('imie').value == '') 
	{
		document.getElementById('error_1').innerHTML = "Wypełnij pole";
		error = true;
	}
	if(document.getElementById('email').value == '')
	{
		document.getElementById('error_2').innerHTML = "Wypełnij pole";
		error = true;
	}
	if(document.getElementById('info').value == '')	
	{
		document.getElementById('error_3').innerHTML = "Wypełnij pole";
		error = true;
	}
	
	if(!error) document.forms['kontakt'].submit();
}

