function start_ajax_form(id_html_wrapper){
	$(".ajax-form-submit").live("click", function(){
		form = $(".ajaxer").find("form");
		form_data = form.serializeArray();
		url = form.attr("action");
		fx = function(data){
			$(".ajaxer").html(data.html);
			return false;
		};
		ajax_call("post", url, form_data, fx, ["ajaxer-wait"]);
		return false;
	});
}

function ajax_call(method, url, data, collback_func, ajax_wait_ids, html_in_dialog){
	// handle ajax wait icon and can notice errors to modal dialog
	// if is all ok, call callback function
	
	// set defaults
	if (html_in_dialog == null){
		html_in_dialog = true;
	};
	
	collback_func_wrapper = function(data){
		// some problem, show notice dialog
		if (data.report_notice){ 
			if (html_in_dialog){ show_notice_dialog(data.html); } 
			else { collback_func(data); }
			return;
		} 
		// data is ok
		else {collback_func(data);};
	};
	
	$.ajax({
		url:url,
		type:(method == "post") ? "POST" : "GET",
		data:data,
		dataType:"json",
		success:collback_func_wrapper,
		beforeSend: function(){
		    for (var i=0; i<ajax_wait_ids.length; i++){
		    	$("#"+ajax_wait_ids[i]).show();
		    }
	    },
		complete: function(){
		    for (var i=0; i<ajax_wait_ids.length; i++){
		    	$("#"+ajax_wait_ids[i]).hide();
		    }
	    }
	});
};


//******************************************************************************
//image gallery
//******************************************************************************

function start_image_gallery(selector){
	
	$(selector).fancybox({
	    'type': 'image',
	    'transitionIn': 'none',
	    'transitionOut': 'none',
	    'titlePosition': 'over',
	    'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
	      return '<span id="fancybox-title-over">'+ image_text + " " + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	    }
	});
};

/*
 * hightlight links box
 * */

$(document).ready(function(){
	$(".product-box")
		.mouseover(function(){
			$(this).addClass("box-hover");
		})
		.mouseout(function(){
			$(this).removeClass("box-hover");
		})
		.click(function(){
			location.href = $(this).find("A").first().attr("href");
		});
});

