var j = jQuery.noConflict();	
	
var maxHeight = 0;

var o = {
	init: function(){		
		this.setHeight('.products-grid li');
		this.add.span('.cart');
		//this.fancybox.init(); PK - chwilowo wylaczone, wywalalo wyswietlanie rozmiarów
		this.flash.init();
		this.slider.init();
		this.slideBasket();
        this.popup.init();
		//this.accordion();
		this.fading();
	},
	slideBasket: function() {
		if (j('#messages_product_view .success-msg').length > 0) {
			//j('.block-cart-inside').show();
	 			j('.block-cart-inside').delay(1000).slideDown(600, function() {
	 				j('.block-cart-inside').delay(4000).slideUp(600, function() {
					});
				});

		}
	},
	cookie: {
			create: function (name, value, days) {
				if (days) {
					var date = new Date();
					date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
					var expires = '; expires=' + date.toGMTString();
				} else {
					var expires = '';
				}
				document.cookie = name + '=' + value + expires + '; path=/'
			},
			erase: function (name) {
				o.cookie.create(name, '', -1);
			},
			read: function (name) {
				var nameEQ = name + '=';
				var ca = document.cookie.split(';');
				for (var i = 0; i < ca.length; i++) {
					var c = ca[i];
					while (c.charAt(0) == ' ') {
						c = c.substring(1, c.length)
					}
					if (c.indexOf(nameEQ) == 0) {
						return c.substring(nameEQ.length, c.length)
					}
				}
				return null
			}
		},
		popup: {
			init: function(){
				o.popup.counter.start();
				o.popup.close();
			},
			session: {
				start: function(){
					o.cookie.create('popup_session', 'true', 365);
				},
				end: function(){
					window.onbeforeunload = function(){
						o.cookie.erase('popup_session');
					}
				}
			},
			counter: {
				start: function(){
					var c = o.cookie.read('popup_counter');
					
					if (c == null){
						c = 1;
                        j('.popup').css('display','block');
						o.cookie.create('popup_counter', c, 365);
					} else if (c == 1){
						c++;
                        j('.popup').css('display','none');
						o.cookie.create('popup_counter', c, 365);
					} else if (c > 2){
						
					}
				}
			},
			close: function(){
				var div = j('.popup');
				div.find('.close').click(function(){
					div.addClass('hidden');
                    j('.popup').css('display','none');
					return false;
				});
			}
		},
	setHeight: function(column) {
	    //Get all the element with class = col
	    column = j(column);
	    //Loop all the column
	    column.each(function() {       
	        //Store the highest value
	        if(j(this).height() > maxHeight) {
	            maxHeight = j(this).height();;
	        }
	    });
	    //Set the height
	    column.height(maxHeight);
	},
	add: {
		span: function(e){
			j(e).append(j('<span />').addClass('helper'));
		}
	},
	fancybox: {
		data: {
			titleShow: false,
			hideOnContentClick: true,
			centerOnScroll: true,
			overlayShow: false,
			padding: 0
		},
		init: function(){
			j('.zoom').fancybox();
		}
	},
	slider: {
		data: {
			paginationClass: 'sliderBullets',
			play: 15000,
			hoverPause: true,
			animationStart: function(){
				j('.item').find('object').remove();
			},
			animationComplete: function(current) {
				var src = j('.i'+current).find('input').val();
				o.flash.create(src, 'i'+current);
			}
		},
		init: function(){
			j('.slider').slides(o.slider.data);
		}
	},
	fading: function(){
		var container = j('.sliderSupport'),
			slide = container.find('.item'),
			name = 'current';
		setInterval(function(){
			var current = slide.filter('.'+name),
				next = current.next('.item');
			current.fadeOut(function(){
				current.removeClass(name);
				if (!next.length){
					slide.eq(0).fadeIn().addClass(name);
				} else {
					next.fadeIn().addClass(name);
				}	
			});
			
		}, 5000);
	},
	accordion: function(){
		var list = j('.narrow-list10'), current = list.find('.current');
		
		list.find('dt').click(function(){
			var t = j(this), dd = t.next('dd'), all = t.parents('dl').find('dd');
			all.slideUp();
			dd.slideDown();	
			return false;
		});
		
		if (current.length){
			list.find('dd').hide();
			current.parents('dd').show();	
		}
	},
	flash: {
		data: {
			quality: 8,
			bgcolor: '#fff',
			wmode: 'opaque',
			play: true
		},
		create: function(swf, id){
			o.flash.data.swf = swf;
			o.flash.data.width = 1000;
			o.flash.data.height = 385;
			o.flash.data.FlashVars = 'urlLink2=http://www.51015kids.eu/bizuteria-2y1909.html&urlLink=http://www.unicef.pl/';
			j('#'+id).flash(o.flash.data);
		},
		init: function(){
			var src1 = j('.i1').find('input').val(),
				src2 = j('.i2').find('input').val();
			o.flash.create(src1, 'i1');
			o.flash.create(src2, 'i2');
		}
	}
}

j(document).ready(function() {	
	o.init();
	j("a#single_image").fancybox();
	j("a#inline").fancybox();
});	


	var mazowieckie = 'mazowieckie',
		z_pomorskie = 'zachodniopomorskie',
		pomorskie = 'pomorskie',
		w_mazurskie = 'warmińsko-mazurskie',
		podlaskie = 'podlaskie',
		lubuskie = 'lubuskie',
		wielkopolskie = 'wielkopolskie',
		k_pomorskie = 'kujawsko-pomorskie',
		lubelskie = 'lubelskie',
		swietokrzyskie = 'świętokrzyskie',
		lodzkie = 'łódzkie',
		dolnoslaskie = 'dolnośląskie',
		opolskie = 'opolskie',
		slaskie = 'śląskie',
		malopolskie = 'małopolskie',
		podkarpackie = 'podkarpackie';
		
	function listaSklepow(state){
		var mapa = j('div#flashmapa');
		j.ajax({
			type: 'get',
			url: '/media/xml/shops.xml',
			dataType: 'xml',
			beforeSend: function(){
				var mapshops = mapa.next('.mapshops');
				if (mapshops.length)
					mapshops.remove();
				mapa.after(j('<div />').addClass('box mapshops loader'));
			},
			success: function(data){
				var xml = j.xml2json(data),
					mapshops = mapa.next('.mapshops'),
					shops = xml.shop,
					arr = [];
				mapshops.removeClass('loader');
				for (var i in shops){
					var shop = shops[i];
					if (typeof shop != 'function'){
						var voivodeship = shop.address.voivodeship;
						if (voivodeship == state){
							var	mpk = shop.mpk,
								ch = shop.ch,
								phone = shop.phone,
								address = shop.address,
								city = address.city,
								street = address.street,
								postcode = address.postcode,
								header = ch.length ? ch+' - '+city : city;
							arr.push('<div class="shop">');
							arr.push('<h4>'+header+'</h4>');
							arr.push('<p class="address">Adres: '+street+', '+postcode+'</p>');
							arr.push('<p class="phone">Telefon: '+phone+'</p>');
						//	arr.push('<p class="mpk">MPK: '+mpk+'</p>');
							arr.push('</div>');				
						}
					}
				}
				var html = arr.join('');
				mapshops.html(html);
			}
		});

	}

