/*
	name: Sklep Centrum Swiatla
	encoding: UTF-8
	author(s): Dawid Horodecki
	Copyright Enzo Sp. z o.o., http://enzo.pl
*/

/*	Show and Hide
	==================================== */

var ShowHide = {
	init: function() {
		this.show_hide();
		this.open_hash();
	},
	
	/* Show element (remove class) if there is URL hash */
	
	open_hash: function() {
		loc = location.hash;
		if (loc && $(loc+'.hide').length) {
			$(loc).removeClass('js');
		}
	},
	
	/* Show or hide element */
	
	show_hide: function() {
		if ($('.show-hide').length && $('.link').length) {
			$('.show-hide .link').bind('click', function() {
				hsh = $(this).attr('href');
				
				if ($(hsh).hasClass('.hide.js')) {
					$(hsh).removeClass('js');
				} else {
					$(hsh).addClass('js');
				}
				
				return false;
			});
		}
	}
};

/*	On load
	==================================== */

var OnLoad = {
	init: function() {
		this.over();
		this.onjs();
		this.onlyjs();
		this.lightb();
		this.carousel();
	},
	
	/* Label over input */
	
	over: function() {
		$('.over').addClass('js').find('input').focus(function() {
			if (this.value === '') {
				$(this).parent().find('label').hide();
			}
		}).blur(function() {
			if (this.value === '') {
				$(this).parent().find('label').show();
			}
		});
	},
	
	/* Hide elements if JS is on */
	
	onjs: function() {
		$('.hide').addClass('js');
	},
	
	/* Remove class if JS is on */
	
	onlyjs: function() {
		$('.only-js').removeClass('only-js');
	},
	
	/* Turn on LightBox if JS is on */
	
	lightb: function() {
		if (jQuery().lightBox) {
			$('a[rel=lightbox]').lightBox({
				imageLoading: '/_skiny/shoper_blue/img/lightbox-ico-loading.gif',
				imageBtnClose: '/_skiny/shoper_blue/img/lightbox-btn-close.gif',
				imageBtnPrev: '/_skiny/shoper_blue/img/lightbox-btn-prev.gif',
				imageBtnNext: '/_skiny/shoper_blue/img/lightbox-btn-next.gif',
				imageBlank: '/_skiny/shoper_blue/img/lightbox-blank.gif'
			});
		}
	},
	
	carousel: function() {
		$('#carousel').jcarousel({
			scroll: 1,
			buttonNextHTML: '<p class="promo-list-next">Następny</p>',
			buttonPrevHTML: '<p class="promo-list-prev">Poprzedni</p>'
		});
	}
};

/*	Checkout
	==================================== */

var Checkout = {
	init: function() {
		/* on load */
		
		if ($('#radio1:checked').length) {
			Checkout.registerCart('hide');
		}
		if ($('#radio2:checked').length) {
			Checkout.registerCart('show');
		}
		
		$('#radio1:radio').change(function() {
			Checkout.registerCart('hide');
		});
		
		$('#radio2:radio').change(function() {
			Checkout.registerCart('show')
		});
		
		/* delivery address */
		
		$('#inputChangeAddress').change(function() {
			Checkout.showForm($('#delivery'));
			return false;
		});
		
		$('#delivery_address').change(function() {
			Checkout.showForm($('#cart-data2-address'));
			return false;
		});
	},
	
	registerCart: function(what) {
		if (what == 'show') {
			$('#cart-data1').show();
			$('#zaloz_konto').attr('disabled', 'false');
			$('#register-add-fields').show();
		} else {
			$('#cart-data1').hide();
			$('#zaloz_konto').attr('disabled', 'disabled');
			$('#register-add-fields').hide();
		}
	},
	
	showForm: function($id) {
		if ($id.attr('style') == 'display: none;') {
			$id.show();
		} else {
			$id.hide();
		}
	}
};

/*	Document ready
	==================================== */

$(document).ready(function() {
	OnLoad.init();
	ShowHide.init();
	//Checkout.init();
});