/* Jeżeli nie ma konsoli to wyświetlaj alerty */
if ( typeof(console) != 'object' ) {
 console = {
  log:function(msg) {
    if (JSDEBUG) alert(msg);
	},
  info:function(msg) {
  	if (JSDEBUG) alert(msg);
	}
 }
}

/*
	Debug messages (via console and alert) should be printed
	only if variable JSDEBUG is set to (boolean) true.
*/
if ( typeof(JSDEBUG) == "undefined" ) {
  JSDEBUG = false;
}
JSDEBUG = false;

/* google maps */
function pokazPunkt(name, city, street, x, y) {
    var mapa = new GMap2(document.getElementById("map_canvas"));

            mapa.setCenter(new GLatLng(x,y), 15);

            // dodanie mozliwosci skalowania
            var customUI = mapa.getDefaultUI();
            customUI.controls.scalecontrol = false;
            mapa.setUI(customUI);

            // dodajemy w tym miejscu marker
            var ikona = new GIcon();
            ikona.image='http://maps.google.com/mapfiles/kml/pal3/icon52.png';
            ikona.shadow='';
            ikona.iconSize=new GSize(32,32);
            ikona.iconAnchor=new GPoint(16,16);
            ikona.infoWindowAnchor=new GPoint(16,16);

            adres = city + (street?', '+street:'');

            var marker = new GMarker(new GLatLng(x,y),{icon: ikona, title: adres});
            mapa.addOverlay(marker);
            // i otwieramy dymek z adresem
            marker.openInfoWindowHtml('<strong>' + name + '</strong><br/>' + adres);
}

				function pokazAdres(punkt)
                    {
                        if (!punkt)
                        {
                            // wyśrodkowujemy miasto, adresu nie znaleźliśmy
                            geo.getLatLng(city, pokazMiasto);
                        }
                        else
                        {
                        	adres = city + (street?', '+street:'');
                            // centrujemy na znalezionym punkcie
                            if (GBrowserIsCompatible()) {
                                var mapa = new GMap2(document.getElementById("map_canvas"));

                                mapa.setCenter(punkt, 15);

                                // dodanie mozliwosci skalowania
                                var customUI = mapa.getDefaultUI();
                                customUI.controls.scalecontrol = false;
                                mapa.setUI(customUI);

                                // dodajemy w tym miejscu marker
                                var ikona = new GIcon();
                                ikona.image='http://maps.google.com/mapfiles/kml/pal3/icon52.png';
                                ikona.shadow='';
                                ikona.iconSize=new GSize(32,32);
                                ikona.iconAnchor=new GPoint(16,16);
                                ikona.infoWindowAnchor=new GPoint(16,16);

                                var marker = new GMarker(punkt,{icon: ikona, title: name});
                                mapa.addOverlay(marker);

                                // i otwieramy dymek z adresem
                                marker.openInfoWindowHtml('<strong>'+name+'</strong><br/>'+adres);

                            }
                        }
                    }
                    function pokazMiasto(punkt) {
                        if (!punkt)
                        {
                            // nie ma też takiego miasta, cos jest nie tak
                        }
                        else
                        {
                            // centrujemy na znalezionym punkcie
                            if (GBrowserIsCompatible()) {
                                var mapa = new GMap2(document.getElementById("map_canvas"));

                                mapa.setCenter(punkt, 15);

                                // dodanie mozliwosci skalowania
                                var customUI = mapa.getDefaultUI();
                                customUI.controls.scalecontrol = false;
                                mapa.setUI(customUI);


                                // dodajemy w tym miejscu marker
                                var ikona = new GIcon();
                                ikona.image='http://maps.google.com/mapfiles/kml/pal3/icon52.png';
                                ikona.shadow='';
                                ikona.iconSize=new GSize(32,32);
                                ikona.iconAnchor=new GPoint(16,16);
                                ikona.infoWindowAnchor=new GPoint(16,16);

                                var marker = new GMarker(punkt,{icon: ikona, title: name});
                                mapa.addOverlay(marker);
                            }

                        }
                    }


function pokazMiejsce(name, city, street, x, y, country) {
	if( ( x > 0 || y > 0 ) ) { //  wyswietlamy zgodnie z koordynatami
	    pokazPunkt(name, city, street, x, y);
	}
	else { // na podstawie adresu
		adres = country + ', ' + city + (street?', '+street:'');
		geo.getLatLng(adres, pokazAdres);
	}
}


/*
	Dopasowanie szerokości menu głównego do szerokości layoutu
*/

function rebuildMenu() {
  var mainMenu = {};

  $('#mainMenu').each( function() {
		mainMenu.width = $(this).width();
		mainMenu.height = $(this).height();
  });

  mainMenu.item = [];
  mainMenu.items = 0;
  mainMenu.itemsTotalWidth = 0;
  $('#mainMenu > li > a').each( function() {
  	var currIndex = mainMenu.item.length;
  	var currElem;

  	$(this).css( {'padding':'0'} );
  	$(this).parent().css( {'padding':'0'} );

    currElem = mainMenu.item[ currIndex ];
    currElem = {
			elem:this,
			width:$(this).width(),
			height:$(this).height()
		};

		var paddingTop = Math.floor( (mainMenu.height - currElem.height) / 2 );
		var paddingBottom = mainMenu.height - currElem.height - paddingTop;

    $( currElem.elem ).css( {'padding-top': paddingTop+'px', 'padding-bottom': paddingBottom+'px'} )

    mainMenu.itemsTotalWidth += currElem.width;
    mainMenu.items = currIndex+1;
    mainMenu.item[ currIndex ] = currElem;
	});

	if ( mainMenu.items > 0 ) {
		var paddingLeft = Math.floor( (mainMenu.width-mainMenu.itemsTotalWidth) / (2*mainMenu.items) );
		var paddingRight = paddingLeft;

	  for( var i=0; i<(mainMenu.items-1) ; i++  ) {
			$( mainMenu.item[ i ].elem ).css( {'padding-left': paddingLeft+'px', 'padding-right': paddingRight+'px'} )
			mainMenu.itemsTotalWidth += paddingLeft+paddingRight;
		}
    
		var menuFreeSpace = mainMenu.width-mainMenu.itemsTotalWidth;
		
		if ( menuFreeSpace != 0 ) {
			if ( menuFreeSpace % 2 == 0 ) {
        paddingLeft = menuFreeSpace / 2;
				paddingRight = paddingLeft;
			} else {
        paddingLeft = Math.floor( menuFreeSpace / 2 );
				paddingRight = menuFreeSpace - paddingLeft;
			}
			
			paddingLeft = paddingLeft>2?paddingLeft-2:paddingLeft;
			paddingRight = paddingRight>2?paddingRight-2:paddingRight;

			$( mainMenu.item[ i ].elem ).css( {'padding-left': paddingLeft+'px', 'padding-right': paddingRight+'px'} )
			mainMenu.itemsTotalWidth += paddingLeft+paddingRight;
		}
	}
}

/* Main menu - WAI */

jQuery.fn.fixHoverMainMenu = function(){
	$(this)	.bind('keyup', function(){ $(this).addClass('hover'); })
			.find('ul li:last-child a')
			.bind('keydown', function(){$(this).parent().parent().parent().removeClass('hover')});

	if ($.browser.msie && $.browser.version <'7')
			$(this)	.bind('mouseenter', function(){ $(this).addClass('hover'); })
					.bind('mouseleave', function(){ $(this).removeClass('hover'); });
		
	}

/* Zakłądki na stronie głównej */
function tabMainPage() {
	$('#tabItemsContent li.active').hide();

	$('#tabItems tr td a').click(function() {
	  $('#tabItems tr td.active').each(function() {
	  	$(this).removeClass('active');
	  	$('#' + this.id + 'Content').hide();
		});
		$(this).parent('td').addClass('active');
		$(this).parent('td.active').each(function() {
		  $('#' + this.id + 'Content').show();
		});
		return false;
	});

	$('#tabItems tr td.active a').trigger('click');
}


/**/
function toggleProduktAddInfo() {
  $('.productListWrapper	 a.addInfo').click( function() {
    var pl = $('.productListWrapper .productList');
		
		
	$('.addInfo').toggleClass('hide');

    pl.each( function() {
      if ( this.visible == true ) {
			  this.visible = false;
			} else {
			  this.visible = true;
			}

      if ( this.visible ) {
			  $('.productListWrapper a.addInfo span.hide').show();
			  $('.productListWrapper a.addInfo span.show').hide();
			  $('.productListWrapper .item div.addInfo').show();
			} else {
    		$('.productListWrapper a.addInfo span.hide').hide();
			  $('.productListWrapper a.addInfo span.show').show();
			  $('.productListWrapper .item div.addInfo').hide();
			}
		});

		return false;
	});

	$('.productListWrapper .productList').attr({'visible':true});
	$('.productListWrapper a.addInfo').trigger('click');
}


/*
	Zakładki ze zdjęciami / mechanizm przełączający
*/
$.fn.tabPhoto = function() {
	if ( this.length ) {
	 	this.tabs();

	  var $topTab = $('ul.topTab', this).parent();
	  var $tabPhoto = $('ul.tabPhoto', this).parent();

		this.each( function() {
			if ( $topTab.length ) {
			  $topTab.bind('tabsselect', function(event, ui) {
			    $('li.ui-tabs-selected a', ui.panel).each( function() {
	          var id = this.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1');
	          var subid = this.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$2').replace(/^_(.+)$/, '$1');
						switchPrice(id);
		     		switchInfo(id);
		     		switchCode(id);
		     		switchAdditionalDocumetnsInfo(id);
					});
		    });
			} else if ( $tabPhoto.length ) {
			  $tabPhoto.bind('tabsselect', function(event, ui) {
					var id = ui.tab.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1');
					switchPrice(id);
	     		switchInfo(id);
	     		switchCode(id);
	     		switchAdditionalDocumetnsInfo(id);
				});
			}
		});

		if ( $tabPhoto.length ) {
		  var tmp = $('ul.tabPhoto li.defaultProduct a');
		  var selectedTabName = '';

		  if ( tmp.length ) {
		    var selectedId = tmp[0].hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1$2');
				selectedTabName = tmp[0].hash.replace(/^(.+)-([0-9]+)(_[0-9]+)?$/, '$1');
		    switchPhoto(selectedId, selectedTabName);
			} else {
			  var selectedId = $('ul.tabPhoto:first li:first a')[0].hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1');
			}

	    switchPrice(selectedId);
	 		switchInfo(selectedId);
	 		switchCode(selectedId);
	 		switchAdditionalDocumetnsInfo(selectedId);
		}
	
	}
}


$.fn.pictogramTooltip = function() {
	var allElem = $(this).clone();

	for ( i=0 ; i<allElem.length ; ++i ) {
	 allElem.eq(i).insertBefore( this.eq(i).parent('dt').next('dd').children('p') );
	}

	$(this).mouseover( function() {
	  $(this).parent('dt').nextAll('dd').removeClass('visible');
	  $(this).parent('dt').nextAll('dd').hide();

		$(this).parent('dt').next('dd').css({'left':($(this).position().left-1) + 'px'}).each( function() {
		  $(this).addClass('visible');
		});

	  $(this).parent('dt').next('dd').mouseout( function() {
	    $(this).removeClass('visible');
	    $(this).hide();
		});
  	$(this).parent('dt').next('dd').show();
	});
}

$.fn.colorThumbnail = function() {
	for (var i=0 ; i<this.length ; ++i) {
	  this.eq(i).mouseover( function(){
      $(this).after('<div class="colorTooltip"><img src="' + $(this).attr('longdesc') + '" /></div>');

      $(this).next('div.colorTooltip').mouseout( function(){
  	    $(this).remove();
			})
		});
	}
}


function switchPhoto(id, tabName) {
	$('#productPhoto ul.tabPhoto > li > a').each( function() {
	  var cid = this.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1$2');
	  var cName = this.hash.replace(/^(.+)-([0-9]+)(_[0-9]+)?$/, '$1');

	  if ( tabName ) {
	    if ( cName == tabName ) {
	      if ( id == cid ) {
			    $(this).parents('.topTabContainer').each(function() {
			      $('.topTab > li > a[href=#' + this.id + ']').trigger('click');
					});
					$(this).trigger('click');
				}
			}
		} else {
      if ( id == cid ) {
		    $(this).parents('.topTabContainer').each(function() {
		      $('.topTab > li > a[href=#' + this.id + ']').trigger('click');
				});
				$(this).trigger('click');
			}
		}
	});

}

function switchPrice(id) {
  $('#produktPrice dd').hide();
  var currId = id.replace(/^([0-9]+)(_[0-9]+)?$/, '$1');

  var currPrice = $("#produktPrice-" + currId);

  if ( currPrice.length ) {
		$("#produktPrice-" + currId).show();
	} else {
	  $("#produktPrice-" + "default").show();
	}
}

function switchInfo(id) {
  $('#productStatus dd').hide();
  var currId = id.replace(/^([0-9]+)(_[0-9]+)?$/, '$1');

  var currPrice = $("#productStatus-" + currId);

  if ( currPrice.length ) {
		$("#productStatus-" + currId).show();
	} else {
	  $("#productStatus-" + "default").show();
	}
}

function switchAdditionalDocumetnsInfo(id) {
  $('dl.additionalDocuments dt span.wymiaryiwagaopakowania').parent().next('dd').find('div.contentWrapper div.contentBody').hide();
  var currId = id.replace(/^([0-9]+)(_[0-9]+)?$/, '$1');

  var currWariant = $("#wariant-" + currId);
  
  if ( currWariant.length ) {
		$("#wariant-" + currId).show();
	} else {
	  $("#wariant-" + "default").show();
	}
}

function switchCode(id) {
  $('#productCode span').hide();
  var currId = id.replace(/^([0-9]+)(_[0-9]+)?$/, '$1');

  var currProdCode = $("#productCode-" + currId);

  if ( currProdCode.length ) {
		$("#productCode-" + currId).show();
	} else {
	  $("#productCode-" + "default").show();
	}
}

$.fn.colorTooltip = function() {
	if ( this.length ) {
	  this.each( function() {
//*
			$('dt > img, dt > a',this).mouseover( function() {
				$(this).parent('dt').next('dd').show();
			});

			$('dt > img, dt > a',this).mouseout( function() {
     		$(this).parent('dt').next('dd').hide();
			});
// */

			$('dt > a',this).click( function() {
			  var id= this.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$1');
        var subid = this.hash.replace(/^.+-([0-9]+)(_[0-9]+)?$/, '$2').replace(/^_(.+)$/, '$1');
				
				var photoId = id+(subid==''?'':'_'+subid);
				var selectedTabName = this.hash.replace(/^(.+)-([0-9]+)(_[0-9]+)?$/, '$1');


/*
				console.log('selectedTabName: ', selectedTabName);
				console.log('hash: ', this.hash);
        console.log('id: ', id);
				console.log('subid: ', subid);
*/

				if ( selectedTabName ) {
					switchPhoto(photoId, selectedTabName);
				} else {
					switchPhoto(photoId);
				}
     		switchPrice(id);
     		switchInfo(id);
     		switchCode(id);
     		switchAdditionalDocumetnsInfo(id);

				return false;
			});
		});
	}
}


//  only for DEBUG:
function viewViaHttp() {
	if ( (location.protocol == 'file:') ) {
	  var loc = location.href.replace(/^file:.+\/Workspace\/(.+)/, 'http://dominikw.siec/$1');
	  location.href = loc;
	}
}

$.fn.fixHR = function() {
 this.wrap('<div class="hr"></div>');
}

$.fn.pricelist = function() {
	if ( this.length ) {
	  var pl = this[0];

		pl.withThumbnails = true;

		$('.viewSwitch', pl).click( function() {
		  var altVal = $(this).attr('rel');
		  $(this).attr('rel', $(this).text() );
		  $(this).text(altVal);

			if ( pl.withThumbnails ) {
			  $('.photo', pl).css({'display':'none'});
			  pl.withThumbnails = false;
			} else {
			  $('.photo', pl).css({'display':''});
			  pl.withThumbnails = true;
			}

			this.blur();
			return false;
		});
	}
	//        $('.photo', this.parent('div.pricelist)).css({'display':'none'});
}



$.fn.vacancyList = function() {
	if ( this.length ) {
	  var vl = this[0];

	  $('dd', vl).hide();

    $('dt > a', vl).click( function() {

      $(this).parent('dt').next('dd').toggle();
    });
	}
}


function toolTip() {
	var x = $('body').append('<div id="colorTooltip">');

//	if (JSDEBUG) console.log( x );
}

function showProductsInCollection( products ) {
	if ( JSDEBUG ) console.log( 'showProductsInCollection: In');
	var productsArr = eval( '(' + products + ')' );

/*
	if ($('.mebleWAranzacji .rowSet')[0])
	$('.mebleWAranzacji .rowSet').each(function(){
		$(this).replaceWith($(this).children());
	})
*/


	if ( (productsArr instanceof Array) && productsArr.length ) {
	  $("div.mebleWAranzacji").show();
	  $("div.mebleWAranzacji div.itemWrapper").hide();


		for (var i=0 ; i<productsArr.length ; i++) {	  
      $("div.mebleWAranzacji div#aranzacja_" + productsArr[i]).show();
		}

		msg = productsArr;
	} else {
	  $("div.mebleWAranzacji").hide();
	  msg = products;
	}

/*
  $(".mebleWAranzacji .itemWrapper:visible").each(function(){
  		if ($(this).is('.mebleWAranzacji .rowSet div')) return;
   		var th = $(this);
		if (th.next(':visible')[0]) th = th.add(th.next(':visible')); else return;
		if (th.next(':visible')[0]) th = th.add(th.next(':visible')); else return;
		if (th.next(':visible')[0]) th = th.add(th.next(':visible')); else return;
		if (th.next(':visible')[0]) th = th.add(th.next(':visible')); else return;
		th.wrapAll('<div class="rowSet"></div>');
   	});
*/

  if (JSDEBUG) console.log( 'showProductsInCollection:', msg);
}


$.fn.printButton = function() {
	this.click( function() {
	  window.print();

	  return false;
	});
}

//*

// */
$.fn.clipboard = function() {
	this.click( function() {
	  var action = undefined;

	  if ( $(this).hasClass('addTo') ) {
	    action = "add";
		} else if ( $(this).hasClass('addToClipboard') ) {
		  action = "add2";
		} else if ( $(this).hasClass('removeFrom') ) {
		  action = "remove";
		}

		if ( action == "add" ) {
			$.ajax({
				type: "GET",
    		url: this.href,
				aelem: this,
				success: function(data, textStatus) {
					$(this.aelem).parent().removeClass('addTo').addClass('alreadyAdded');

				  $('p.clipboard #clipboardQty').html(data);

			    return false;
				}
			});
		} else if ( action == "add2" ) {
			$.ajax({
				type: "GET",
				url: this.href,
				aelem: this,
				success: function(data, textStatus) {
				  $('p.clipboard #clipboardQty').html(data);

				  $(this.aelem).remove();

			    return false;
				}
			});
		} else if ( action == "remove" ) {
			$.ajax({
				type: "GET",
				url: this.href,
				aelem: this,
				success: function(data, textStatus) {
				  $('p.clipboard #clipboardQty').html(data);

				  $(this.aelem).parents("div.itemWrapper").remove();

			    return false;
				}
			});
		}

		return false;
	})
}


//*

$.fn.printClipboard = function() {
	$(this).parents('.productListWrapper').find('.buttons a.printSelected').click( function() {
	  window.print();
	  
	  return false;
	});
	
	this.each( function() {
	  if ( this.checked === true ) {
			$(this).parents('div.itemWrapper').addClass('print');
	  } else {
	    this.checked = false;
	  	$(this).parents('div.itemWrapper').removeClass('print');
		}
	});
			
  this.click( function() {
    var result = false;

    if ( !$(this).parents('div.itemWrapper').hasClass('print') ) {
    	result = true;
			$(this).parents('div.itemWrapper').addClass('print');
			this.checked = result;
		} else {
     	result = false;
      $(this).parents('div.itemWrapper').removeClass('print');
      this.checked = result;
		}
		
		return;
  });
}

// */
$.fn.comparator = function() {
	this.click( function() {
	  this.checked = false;

		$.ajax({
			type: "GET",
			celem: this,
			url: this.value,
			success: function(data, textStatus) {
			  if ( data == "true" ) {
			    this.celem.checked = true;
				} else {
				  this.celem.checked = false;
				}
  	    return true;
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
			  this.celem.checked = false;
  	    return true;
			}
		});

		return false;
	});
}

$.fn.comparator2 = function() {
	this.click( function() {
	   
	   var parentClass = $(this).parent().attr('class');

		$.ajax({
			type: "GET",
			url: this.href,
			aelem: this,
			success: function(data, textStatus) {
			  if ( data == "false" ) {

  	    		$('table.comparator td.'+parentClass).remove();
  	    		var id = parentClass.substring(8);
			  	if ($('input#pid'+id,top.document)[0]) $('input#pid'+id,parent.document)[0].checked = false;			  
				} else {

				  
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
  	    return false;
			}
		});

		return false;
	});
}


$.fn.saveSelected = function() {
    a = this;
	this.click( function() {
	   a.fadeTo('fast',0.5);
		$.ajax({
			type: "GET",
			url: this.href,
			aelem: this,
			success: function(data, textStatus) {
  	    		a.fadeTo('slow',1);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
  	         return false;
			}
		});

		return false;
	});
}


$.fn.jumpOnSelectChange = function() {
	if ( this.length ) {
		// Zabezpieczenie się przed wywołaniem na nieodpowiednim p ulldown-ie.
		if ( $(this).hasClass('jumpOnChange') ) {
	    $(this).change( function() {
		  	if ( this.value != "" ) {
					window.location.href = this.value;
				}
			});
		}
	}
}



/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$.fn.alignProducts = function() {
		var allDivs = this.find("div.item div");
		var allBlocks = {};
		var x;

		for ( var i=0 ; i<allDivs.length ; i++ ) {
		  var m = allDivs[i].className.match(/(^| )(itemBlock-)([^ ]+)/);
		  if ( m && m[3] ) {
				if(m[3] in allBlocks){
        	allBlocks[ m[3] ] = Math.max( $(allDivs[i]).height(), allBlocks[ m[3] ] );
				} else {
        	allBlocks[ m[3] ] = $(allDivs[i]).height();
				}
			}
		}

		for(var i in allBlocks) {
			$('.itemBlock-'+i, this).height( allBlocks[i] );
		}
};

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$(window).resize( function(){
  rebuildMenu();
});

$(document).ready(function(){
	// Dopasowanie szerokości menu do szerokości layout-u
  rebuildMenu();

	// Zakładki na stronie głównej
  tabMainPage();

	// Pokazywanie/ukrywanie rozszerzonej informacji o produkcie
  toggleProduktAddInfo();

	// Przełączanie zakładek ze zdjęciami, aktualizacja ceny i statusu produktu
	if ($('#productPhoto')[0]) {
		$('#productPhoto ul.topTab').parent().tabPhoto();
		$('#productPhoto ul.tabPhoto').parent().tabPhoto();
	}

	$('a.external').click(function(){$(this).attr('target','_blank');});
	$('#content dl.pictogramsWithTooltip dt img').pictogramTooltip();

	$('#content dl.colorListWithTooltip').colorTooltip();

	/* Main menu - WAI */
	$('#mainMenu > li').fixHoverMainMenu();


	// wyszukiwarka
	var searchResetControl=0;
	var searchDefaultQueryText = $(".searchSimple input[name=query]").val();
	$(".searchSimple input[name=query]").bind("focus click", function(){ if (!searchResetControl) { $(this).val(""); searchResetControl=1; } })
	.bind("blur", function(){ if (!$(this).val()) { $(this).val(searchDefaultQueryText); searchResetControl=0; } });
	$(".searchSimple form").submit(function(){ if (!searchResetControl && searchDefaultQueryText == $(".searchSimple input[name=query]").val()) $(".searchSimple input[name=query]").val(''); return true; });

	// newsletter
	var newsletterResetControl=0;
	var newsletterDefaultText = $("#newsletter input[type=text]").val();
	$("#newsletter input[type=text]").bind("focus click", function(){ if (!newsletterResetControl) { $(this).val(""); newsletterResetControl=1; } })
	.bind("blur", function(){ if (!$(this).val()) { $(this).val(newsletterDefaultText); newsletterResetControl=0; } });


  // Języki
	$('li.langSwitch > a').bind('focus', function(){$(this).parent().addClass('hover');});
	$('li.langSwitch ul li:last-child a').blur(function(){$(this).parent().parent().parent().removeClass('hover');});

	// Naprawa HR
  $('hr').fixHR();

	// dodawanie do schowka
	$('div.itemWrapper div.item div.clipboardWrapper a.addTo,div.itemWrapper div.item div.clipboardWrapper a').clipboard();
	$('.printAndClipboardLinkButtons a.addToClipboard').clipboard();

    $('.buttons a.saveSelected').saveSelected();

	// dodawanie do porownania
	$('div.itemWrapper div.item fieldset input[type="checkbox"].selectToCompare').comparator();
	// dodawanie do porownania
	$('div.comparator a.removeFrom').comparator2();
	
	// drukowanie schowka
	$('div.itemWrapper div.item fieldset input[type="checkbox"].selectToPrint').printClipboard();

  // Cennik
  $('div.pricelist').pricelist();

	// Lista wakatów
	$('dl.vacancyList').vacancyList();

  $('a.linkButton.print').printButton();
    
  $('#content select.jumpOnChange').jumpOnSelectChange();

  $('#content div.itemWrapper').alignProducts();
});
