/*
* cStore
*/
$(document).ready(function () {
/**
* IEFix < 8
*
* dodaje clear div'a(
) po elemencie z clasa "clear"
*/
if( $.browser.msie == true && parseInt(jQuery.browser.version) < 8 )
{
try {
$('.clear').each( function () {
try {$(this).append('
');}
catch(err) { }
});
}
catch(err) { }
}
/**
* Automatycznie czyszczenie inputa z zapamientanym stanem podstawowym
*/
$('input.autoClearInput').each( function (k,e){
$(e).attr('data-valuedefault', $(e).attr('value') );
$(e).blur(function () {
if( $(this).val() == undefined || $(this).val() == '' ) $(this).val( $(this).attr('data-valuedefault') );
});
$(e).focus( function () {
if( $(this).val() == $(this).attr('data-valuedefault') ) $(this).val( '' );
});
});
/**
* LightBox/PopUp bind
*/
if( typeof gallery_type != 'undefined' && gallery_type == 'lighbox' )
{
var lightboxArr = new Array()
$('a[rel^=gallery]').each(function()
{
if( jQuery.inArray($(this).attr('rel'),lightboxArr) < 0 )
{
lightboxArr.push($(this).attr('rel'));
}
});
$('a[rel^=gallery]').click(function () {return false;});
$.each(lightboxArr,function(){
$('a[rel^='+this+']').lightBox();
});
}
else
{
$('a[rel^=gallery]').click(function() {
var link_zdj=$(this).attr('href');
var i=0;
$('a[rel^=gallery]').each(function()
{
if($(this).attr('href')==link_zdj) {
return false;
}else{
i++;
}
});
zdj = window.open('pokaz_zdjecie.php?id_prod='+product_id.toString()+'&img='+ i.toString() , 'Zdj�cie', 'screenY=0,screenX=0,left=0,top=0,width=200,height=200,status=no,scrollbars=yes,resizable=yes,menubar=no');
zdj.focus();
return false;
});
}
/**
* Cech wpywajace na modyfikacje ceny
*/
if( $('.show_product_options').length > 0 ) {
change_prices();
$('.show_product_options').change(function(){
change_prices();
});
}
/**
* Inicjalizacja modulu filtrow
*/
filters_init();
if ($('#filter_form').length) {
PokazWybraneFiltry();
}
$("#ms div.wybrany_filtr").live("click", function() {
var id = $(this).attr("data-checkbox_id");
var name = $(this).attr("data-checkbox_name");
if (id == 'usun_wszystkie_filtry')
{
$("#filter_form input[type='checkbox']").attr('checked', false);
$("#filter_form div.wybrany_filtr").remove();
$("#filter_form .filter_option.filters_price input[name='price_from']").val('');
$("#filter_form .filter_option.filters_price input[name='price_to']").val('');
ZastosujFiltry();
}
else if (id == 'usun_przedzial_cenowy') {
$("#filter_form .filter_option.filters_price input[name='price_from']").val('');
$("#filter_form .filter_option.filters_price input[name='price_to']").val('');
$("#filter_form div.wybrany_filtr_cena").remove();
ZastosujFiltry();
}
else {
$("#filter_form input[name='"+name+"']").attr('checked', false);
$(this).remove();
ZastosujFiltry();
}
});
$("#ms div.filter_submit").live('click', function() {
//console.log("Submit GO!");
ZastosujFiltry();
});
$('#ms div#filtr_szukaj_producenta').live('keyup', function() {
SzukajFiltrProducenta();
});
$( "#ms .filter_option.filter_option_producent" ).live('mouseenter', function() {
//$('div#filtr_szukaj_producenta').focus();
});
$("#ms div.filters_header").live('click', function() {
$("div.mbox_filtry_container").toggleClass('mobile');
});
$("#ms div.filters_run_button").live('click', function() {
//console.log("Submit GO!");
ZastosujFiltry();
});
/**
* Inicjalizacja "podpowiadacza" do szukaj
*/
$("input.autocomplete").each( function () {
$(this).autocomplete('smartsearch.php', {
minChars: 2,
max: 50,
width: $(this).width(),
selectFirst: false
} );
});
/**
* Inicjalizacja ToolTip'a
*/
ToolTip.init();
$('.ajc_close').click(function(){
$('.ajax_cart').hide();
});
$('.shopcart_link').click(function(){
$('.ajax_cart').show();
});
/*facebook bok*/
var th_var=0;
th_left=$("#fb_main").css('right'); //$("#fb_main").offset();
$("#fb_button").click(function(){
if(th_var==0){
$("#fb_main").animate({
right: '0'
}, 500,function(){
th_var=1;
});
}else{
$("#fb_main").animate({
right: ''+th_left+'' /*'+th_left+'*/
}, 500,function(){
th_var=0;
});
}
});
});
/*
$(window).load(function(){
$('#rotator').cycle({
fx: 'fade',
time: 5500,
pager: '#rotator_pagi'
});
});
*/
var ToolTip = {
text: '',
toolTipOver: false,
hide: function (obj) {
obj.attr('title', ToolTip.text);
$('#tooltip2').css('display', 'none');
},
show: function (obj, e) {
$('#tooltip2').css('display', 'block');
ToolTip.text = obj.attr('title');
if( ToolTip.text.length == 0 ) return;
obj.attr('title', '');
$('#tooltip2content').html(ToolTip.text);
$('#tooltip2').css('display', 'block');
$('#tooltip2').css('left', e.pageX - $('#tooltip2').get(0).offsetWidth - 5 + 'px');
$('#tooltip2').css('top', e.pageY - $('#tooltip2').get(0).offsetHeight - 5 + 'px');
},
init: function() {
$('.tt_rollover').hover(function(e) {
var handle = $(this);
$(this).css('cursor', 'default');
ToolTip.show(handle, e);
}, function() {
ToolTip.hide($(this));
});
}
};
/**
* Modyfikuje ceny na podstawie wybranych cech
*/
function change_prices() {
var tmp_price_add=0;
var tmp_price_set=0;
jQuery('select.show_product_options option:selected').each( function(){
str=jQuery(this).html().replace(/\s| /g,'').match(/\(.*\)/g)+'';
if(str=='null') return;
is_add=str.search(/\+/);
str=str.match(/\d+\.?\d*/g)+'';
number=parseFloat(str.replace(/,/g,'.'));
if(number>0){
if(is_add>0)
tmp_price_add+=number;
else
tmp_price_set=number;
}
});
//je�eli ustawiono cene w cechach powi�zanych
if(tmp_price_set>0){
//jezeli produkt ma cen� promocyjn�
if(prom_price>0) {
vat_value=((show_product_tax*(tmp_price_set+tmp_price_add))/(show_product_tax+100)).toFixed(2);
netto=(tmp_price_set+tmp_price_add-vat_value);
netto=parseFloat(netto.toFixed(2));
jQuery('#prom_price').html((tmp_price_set+tmp_price_add).toString().replace(/\./g,','));
jQuery('#prom_price_net').html(netto.toString().replace(/\./g,','));
jQuery('#prom_price_formated').html((tmp_price_set+tmp_price_add).number_format());
jQuery('#prom_price_formated_net').html(netto.number_format());
jQuery('#price_formated').html((tmp_price_set+tmp_price_add).number_format());
} else {
vat_value=((show_product_tax*(tmp_price_set+tmp_price_add))/(show_product_tax+100)).toFixed(2);
netto=(tmp_price_set+tmp_price_add-vat_value);
netto=parseFloat(netto.toFixed(2));
jQuery('#price').html((tmp_price_set+tmp_price_add).toString().replace(/\./g,','));
jQuery('#price_net').html(netto.toString().replace(/\./g,','));
jQuery('#price_formated').html((tmp_price_set+tmp_price_add).number_format());
jQuery('#price_formated_net').html(netto.number_format());
}
} else if(tmp_price_set==0) {
//jezeli produkt ma cen� promocyjn�
if(prom_price>0){
vat_value=((show_product_tax*(prom_price+tmp_price_add))/(show_product_tax+100)).toFixed(2);
netto=(prom_price+tmp_price_add-vat_value);
netto=parseFloat(netto.toFixed(2));
jQuery('#prom_price').html((prom_price+tmp_price_add).toString().replace(/\./g,','));
jQuery('#prom_price_net').html(netto.toString().replace(/\./g,','));
jQuery('#prom_price_formated').html((prom_price+tmp_price_add).number_format());
jQuery('#prom_price_formated_net').html(netto.number_format());
jQuery('#price_formated').html((price+tmp_price_add).number_format());
} else {
vat_value=((show_product_tax*(price+tmp_price_add))/(show_product_tax+100)).toFixed(2);
netto=(price+tmp_price_add-vat_value);
netto=parseFloat(netto.toFixed(2));
jQuery('#price').html((price+tmp_price_add).toString().replace(/\./g,','));
jQuery('#price_net').html(netto.toString().replace(/\./g,','));
jQuery('#price_formated').html((price+tmp_price_add).number_format());
jQuery('#price_formated_net').html(netto.number_format());
}
}
}
/**
* Obsluga filtrow
*/
function filters_init()
{
$('#ms div.filters div.filter_option div.option p, #ms #filter_form .special_promotions').live('click', function () {
if ($(this).find("input[type='checkbox']:checked").length) {
$(this).removeClass("unchecked").addClass("checked");
} else {
$(this).removeClass("checked").addClass("unchecked");
}
});
$('#ms div.filters div.filter_option div.option p').live('click', function () {
if ($("#filter_form input[type='checkbox']:checked").length > 0 ) {
$("div.filters_run_button > span").html(' ('+$("#filter_form input[type='checkbox']:checked").length+')');
} else {
$("div.filters_run_button > span").html('');
}
if ($(this).closest("div.options_list").find("p.checked").length > 0 ) {
$(this).closest(".filter_option_cnt").find("div.label > span > span").html(" ("+$(this).closest("div.options_list").find("p.checked").length+")");
console.log($(this).closest("div.options_list").find("p.checked").length);
} else {
$(this).closest(".filter_option_cnt").find("div.label > span > span").html("");
console.log(0);
}
});
$('#ms .filters .filter_option .label').live('click', function () {
$("#ms div.filters div.filter_option").removeClass("rolled").addClass("unrolled");
});
$('#ms div.filters div.filter_option.rolled div.label').live('click', function () {
$(this).closest('div.filter_option').removeClass("rolled").addClass("unrolled");
});
$('#ms div.filters div.filter_option.unrolled div.label').live('click', function () {
//$(this).removeClass("unrolled").addClass("rolled");
$(this).closest('div.filter_option').removeClass("unrolled").addClass("rolled");
});
$(document).click(function (e)
{
var container = $("div.filter_option");
// if the target of the click isn't the container nor a descendant of the container
if (!container.is(e.target) && container.has(e.target).length === 0)
{
$("div.filters div.filter_option").removeClass("rolled").addClass("unrolled");
}
});
$("#ms #filter_form div.special_promotions label").live('click', function() {
if ($("div.mbox_filtry_container").hasClass("mobile")) {
} else {
$("#filter_form").submit();
}
});
}
function SzukajFiltrProducenta() {
var f = $('div#filtr_szukaj_producenta').text();
var p = '';
$( "div#filtr_szukaj_producenta" ).parents().find("div.option").find("div.options_list.options_list_producent p").each(function( index ) {
p = $(this).find("span").html();
var re = new RegExp(f, 'ig');
if (!p.match(re)) {
$(this).hide();
} else {
$(this).show();
}
});
}
function ZastosujFiltry() {
$("#ms").css("opacity",".3");
var s = $("#filter_form").serialize();
var f = $('div#filtr_szukaj_producenta').text();
$("div.mbox_filtry_container").removeClass('mobile');
//history.replaceState( {} , 'foo', "index.php?"+s );
$.get( "/convert_url.php?"+s+"&time="+$.now(), function( canonical ) {
//console.log(canonical);
history.replaceState( {} , 'foo', "/"+canonical );
console.log("S: "+s+" CANONICAL: /"+canonical);
});
$.ajax({
url: "index.php?wnetrze_ajax=1&"+s,
type: "GET",
//contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function(data) {
$("#ms").html(data).css("opacity","1");
PokazWybraneFiltry();
if (f.length > 0) {
ga('send', 'event', 'FiltrowanieProduktow', 'Szukanie producenta na liście', f+' / kat: '+$("#filter_form input[name='podkat']").val());
}
ga('send', 'event', 'FiltrowanieProduktow', 'Filtrowanie kategorii', $("#filter_form input[name='podkat']").val());
}
});
}
function PokazWybraneFiltry() {
var price_from = $("#filter_form .filter_option.filters_price input[name='price_from']").val();
var price_to = $("#filter_form .filter_option.filters_price input[name='price_to']").val();
//console.log(price_to);
$("#filter_form #nicebutton, #nicebutton2").html("");
if ($("#filter_form .filter_option input[type='checkbox']:checked").length >1 ) {
$("#filter_form #nicebutton, #nicebutton2").append("Wyczyść filtry
");
}
if (price_from > 0 || price_to > 0) {
$("#filter_form #nicebutton, #nicebutton2").append("Cena: "+price_from+"-"+price_to+" zł
");
}
if ($("#filter_form .filter_option input[type='checkbox']:checked").length > 0 ) {
$("div.filters_run_button > span").html(' ('+$("#filter_form input[type='checkbox']:checked").length+')');
}
$("#filter_form .filter_option input[type='checkbox']:checked").each(function() {
var txt = $(this).parent("p").find("span").text();
var id = $(this).attr("id");
var name = $(this).attr("name");
$("#filter_form #nicebutton, #nicebutton2").append(""+txt+"
");
});
}
//coś z ps.js
function equalHeights(strObj){
var numHeight = 0;
$(strObj).each(function(){
if($(this).height() > numHeight){
numHeight = $(this).height();
}
});
$(strObj).each(function(){
$(strObj).height(numHeight);
});
}