$(document).ready(function() {

	// fancybox
	$('a[rel="fancy"]').fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	300, 
		'speedOut'		:	200,
		'titleShow'		:	false
	});

	// replace font
	//Cufon.replace('h2.title', { fontFamily: 'fago', fontSize: 36 });


  $('.product:odd').css('marginRight', 0);
 

	$(".anfragen").button({
		icons: {
			primary: 'ui-icon-document'
		}
	});
	$(".details").button({
		icons: {
			primary: 'ui-icon-info'
		}
	});
	$(".back").button({
		icons: {
			primary: 'ui-icon-arrowreturnthick-1-w'
		}
	});
	$(".print").button({
		icons: {
			primary: 'ui-icon-print'
		}
	});



	$("#accordion").accordion({
		autoHeight: false,
		navigation: true
	});


	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	equalHeight($('.product .box'));
	equalHeight($('.producttype'));

	// show requests response
	$('.requests a.showResponse').click(function() {
		openResponse($(this).attr('rel'));
		return false;
	});
	
	$('.openrequests a').click(function() {
		var checkbox = $(this).find('input:checkbox');
		if(checkbox.is(':checked')) {
			checkbox.attr('checked', false);
		} else {
			checkbox.attr('checked', true);
		}
		return false;
	});
	
	


	// chart graph
	
	
	if(typeof(chartdata1) != "undefined") {
    	var api = new jGCharts.Api(); 
    	jQuery('<img>')
    	.attr('src', api.make({
    		data		: chartdata1,
    		axis_labels : ['Jan','Feb','März', 'April', 'Mai', 'Juni', 'Juli', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
    		size		: '900x200',
    		bar_width	: 64,
    		bar_spacing	: 10,
    		colors		: ['AA0000'],
    		
    		grid        : true, //default false 
    		grid_x      : 0,    //default 10 
    		grid_y      : 10,    //default 10 
    		grid_line   : 1,   //default 10 
    		grid_blank  : 2    //default 0
    	}))
    	.appendTo("#chart1");
    	
    	
    	var api = new jGCharts.Api(); 
    	jQuery('<img>')
    	.attr('src', api.make({
    		data		: chartdata2,
     		axis_labels : days,
    		size		: '900x200',
    		bar_width	: 20,
    		bar_spacing	: 10,
    		colors		: ['AA0000'],
    		
    		grid        : true, //default false 
    		grid_x      : 0,    //default 10 
    		grid_y      : 10,    //default 10 
    		grid_line   : 1,   //default 10 
    		grid_blank  : 2    //default 0
    	}))
    	.appendTo("#chart2");
    }


});



function openResponse(id) {
	$.ajax({
		url: 'index.php?page=getResponse&id='+id,
		success: function(data) {
			$('<div>'+data+'</div>').dialog({
				modal: true,
				title: 'Anfrageergebnis',
				width: 960,
				resizable: false,
				buttons: {
					"Fenster schließen": function() {
						$(this).dialog("close");
					},
					"Drucken": function() {
						window.open('index.php?page=getResponse&id='+id+'&print=1','Druckansicht','width=900,height=600,directories=no,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=no,dependent=no');
					}
				}
			});
		}
	});
}
