/* Created by webszok.net */

function HandleError(error)
{
	alert('Error: '+error);
}

// nowe okno
function popup_scrolls(url, name, width, height)
{
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/2;
	
	win = window.open(url, name, 'width='+width+',height='+height+',left='+x+',top='+y+',toolbar=0,menubar=0,scrollbars=1,resizable=0');
	win.focus();
}

// mruganie
var doBlink = function(obj,start,finish) { jQuery(obj).fadeOut(400).fadeIn(400); if(start!=finish) { start=start+1; doBlink(obj,start,finish); } } 
$(document).ready(function(){
  doBlink(".blink_new",1,200);
});

// form szukarki
function szukaj() {	
	var sz = document.getElementById("query").value;
	if(sz.length < 4){
		alert('Szukany text musi zawierać conajmniej 4 znaki.');
	return false;
	
	} else if (sz == 'Szukaj...' || sz == 'Suche...' || sz == 'Search...'){
		alert('Wpisz szukaną frazę.');
	return false;
	}
	else{
		document.search.submit();
	return true;
	}
}


$(document).ready(function(){

// corner
  var itisie = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE") != -1);
  if (itisie != true) {
    $("#contact_form input, #contact_form textarea").corner("5px");
  }

// gallery init
  $("a[rel='gallery-1']").colorbox();
  $("a[rel='gallery-2']").colorbox();
  $(".konfiguratorpopup, .button, .eskleppopup").colorbox({width:"95%", height:"95%", iframe:true});

});


$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 10, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 50, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);

});


