function Eshop() {

	var self = this;

	/** CART **/
	self.initCartBtns = function(selector) {

		$('#cartPopWindow a.closeBtn, #cartPopWindow a.closeBtnIco').live('click', function() {
			$('#cartPopWindow').remove();
			$(selector).removeAttr('disabled'); //doubleclick  protection 
			return false;
		});
		
		$(selector).click(function() {
			$(selector).removeAttr('disabled');	//doubleclick  protection														 
			$(this).attr('disabled', 'disabled'); //doubleclick  protection	
			
			$('#cartPopWindow').remove(); //remove other cart popup
			
			var holder = $(this).parents('.formWrap');
			
			/*id*/
			var itemId = holder.find('input[name=item]').val();
			/*variant*/			
			var itemVariant = holder.find('input[name=variant]:checked').val();
			if(!itemVariant) {itemVariant = holder.find('input[name=variant]:first').val()}
			/*count*/
			var itemCount = holder.find('input[name=pocet]').val();	
			if (!itemCount) {itemCount = 1;}
							
			var popWindow = $('<div id="cartPopWindow"><div class="wrap"/></div>')
			popWindow.hide();

			$('body').append(popWindow);
			var pos = $(this).offset();			
			var cssObj = {
				'left' : pos.left - popWindow.width() + $(this).width() + 36,
				'top' : pos.top - 45
			}		
			$(popWindow).css(cssObj);
			
			if ($.browser.msie && $.browser.version.substr(0,1)<9) {
				popWindow.show();
			} else {
				popWindow.fadeIn('fast');
			}
			//ajax

			system.ajaxRequest(
					[ "komponenta", php.compId],
					"eshop_kosik_fe_action_popup",
					[
					 	["id_zbozi", itemId],
					 	["id_verze", itemVariant],
					 	["pocet", itemCount]						
					],
					{fce : function (xmldata) {
								$("#cartPopWindow .wrap").html(xmldata);
								kosikBox.reloadBox();
								return false;
							}
					}
			);
			return false;
		});

	};

	self.showFacebox = function(xmldata) {
		$.facebox(xmldata);		
		self.initAjaxForms();
	};

	self.initAjaxForms = function() {
		$("form.ajax").live('submit', function() {
			var formId = $(this).attr("id");
			var formName = formId.split("--")[1];
			var data = new Array();
			$(this).find(":input").each(function() {
				data[$(this).attr("name")] = $(this).val();
			});
			system.ajaxRequest(
				[ "komponenta", php.compId],
				"actionProcessForm",
				[
					["formName", formName],
					["data", data]
				],
				{ fce : self.updateForm, param : formId }
			);
			return false;
		});
	};

	self.updateForm = function(xmldata, formId) {
		if (system.isEmpty(xmldata)) {
			return false;
		}
		$("#" + formId + "Container").html(xmldata);
		return true;
	};

}

var eshop = new Eshop();

$(document).ready( function() {
	eshop.initCartBtns('.buyBtn, .buyBtnSmall, .buyBtnLarge');
	eshop.initAjaxForms();

	$('.catListImg').imgAlign();	
	$('.prodListItem .img').imgAlign();	
	
});		

