$(document).ready(function() {
	
	var mygrid = jQuery("#bestpracticesGrid").jqGrid({
		url:'index.php?type=9992',
		datatype: "json",
		width: 915,
		height: '100%',
		altRows: true,
		altclass: 'gridEvenRow',
		colNames:['Vorzeige-Beispiele', 'Bild', 'PLZ', 'Ort', 'Link','ID'],
		forceFit: true,
		colModel: [
			  {name:'titel',index:'titel', width:250}, 
			  {name:'screenshot1',index:'screenshot1',sortable:false, search:false},
			  {
			  	name: 'unternehmensplz',
			  	index: 'unternehmensplz',
			  	width: 65,
			  	formatter: {
			  		integer: {
			  			thousandsSeparator: "",
			  			defaultValue: '0'
			  		}
			  	}
			  },
			  {name:'unternehmensort', index:'unternehmensort',width: 70},
			  {name:'link',index:'link', search:false},
			  {name:'id',index:'id',hidden:true}
			],
		cellLayout:30,
		rowNum:25, 
		mtype: "POST", 
		rowList:[25,50,100],
		pager: '#bestpracticesGridPager',
		sortname: 'titel', 
		viewrecords: true, 
		sortorder: "asc", 
		gridview : true, 
		caption:"Vorzeigebeispiele Prototype Grid",
		onSelectRow: function(ids) {
					var ret = jQuery("#bestpracticesGrid").jqGrid('getRowData',ids);
					
					 
					window.location.href ='/index.php?id='+digiID+'&tx_digipetseic_pi2[bestpractices]='+ret.id+'&tx_digipetseic_pi2[action]=detailview&tx_digipetseic_pi2[controller]=Bestpractices';
			  },
		gridComplete: function() {
			/* Hover */
			$('.ui-jqgrid-btable tr').hover(function(){
				$(this).find('h5,a,p').css('textDecoration','underline');
				$(this).find('td').css('cursor','pointer');
			}, function(){
				$(this).find('h5,a,p').css('textDecoration','none');
			});
		},
		
		beforeRequest: function() {
			$('.jqgrid-overlay').css('display','block'); //Overlay während dem Laden
		},
		
		loadComplete: function() {
			$('.jqgrid-overlay').css('display','none'); //Entfernen des Overlays nach dem Laden
		}
	}); 
				  
	jQuery("#bestpracticesGrid").jqGrid('navGrid','#bestpracticesGridPager',{edit:false,add:false,del:false,search:false,refresh:false}); 
	jQuery("#bestpracticesGrid").jqGrid('navButtonAdd',"#bestpracticesGridPager",{caption:"Toggle",title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s', onClickButton:function(){ mygrid[0].toggleToolbar() } });
	jQuery("#bestpracticesGrid").jqGrid('navButtonAdd',"#bestpracticesGridPager",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh', onClickButton:function(){ mygrid[0].clearToolbar() } }); 
	jQuery("#bestpracticesGrid").jqGrid('filterToolbar');


	//Hinzugefügt von Simon - 01.02.2010 BEGIN
	$('.ui-jqgrid-labels th:first').addClass('STYLE_datenbankTabelleHeadSelect');
	$('.ui-jqgrid-labels th:first').attr('aria-selected','true');
	
	$('.ui-jqgrid-labels th .ui-jqgrid-sortable').not(".ui-jqgrid-labels th:nth-child(2) .ui-jqgrid-sortable").click(function(){
		$('.ui-jqgrid-labels th').not($(this).parent()).removeClass('STYLE_datenbankTabelleHeadSelect');
		$(this).parent().addClass('STYLE_datenbankTabelleHeadSelect');

		if ($(this).find('.ui-icon-asc').hasClass('ui-state-disabled') && $(this).find('.ui-icon-desc').hasClass('ui-state-disabled')) {
			
			if (navigator.appName=='Microsoft Internet Explorer') {
				$(this).find('.ui-icon-desc').css('backgroundPositionX','-11px');
				$(this).find('.ui-icon-desc').css('backgroundPositionY','-8px');
				
				$(this).find('.ui-icon-asc').css('backgroundPositionX','0');
				$(this).find('.ui-icon-asc').css('backgroundPositionY','-8px');	
	        } else {
				$(this).find('.ui-icon-desc').css('backgroundPosition','-11px -8px');
				$(this).find('.ui-icon-asc').css('backgroundPosition','0 -8px');
			}
		} else {
			if ($(this).find('.ui-icon-asc').hasClass('ui-state-disabled')) {
				
				
				if (navigator.appName=='Microsoft Internet Explorer') {
					$(this).find('.ui-icon-asc').css('backgroundPositionX','0');
					$(this).find('.ui-icon-asc').css('backgroundPositionY','-8px');
		        } else {
		            $(this).find('.ui-icon-asc').css('backgroundPosition', '0 100%');
		        }
			} else {
				if (navigator.appName=='Microsoft Internet Explorer') {
					$(this).find('.ui-icon-asc').css('backgroundPositionX','0');
					$(this).find('.ui-icon-asc').css('backgroundPositionY','0');
		        } else {
		            $(this).find('.ui-icon-asc').css('backgroundPosition', '0 0');
		        }
			}
		
			if ($(this).find('.ui-icon-desc').hasClass('ui-state-disabled')) {	
				if (navigator.appName=='Microsoft Internet Explorer') {
					$(this).find('.ui-icon-desc').css('backgroundPositionX','-11px');
					$(this).find('.ui-icon-desc').css('backgroundPositionY','0');
		        } else {
		            $(this).find('.ui-icon-desc').css('backgroundPosition','100% 0');
		        }
				
			} else {
				if (navigator.appName=='Microsoft Internet Explorer') {
					$(this).find('.ui-icon-desc').css('backgroundPositionX','-11px');
					$(this).find('.ui-icon-desc').css('backgroundPositionY','-8px');
		        } else {
		            $(this).find('.ui-icon-desc').css('backgroundPosition','100% 100%');
		        }
			}
		}
		
	});
	
	$('.ui-jqgrid-labels th').not(".ui-jqgrid-labels th:nth-child(2)").hover(
	//mouseover
	function(){
		$(this).addClass('STYLE_datenbankTabelleHeadSelect');
		$(this).find('.s-ico').css('display','block');
	//mouseleave	
	},function() {
		if ($(this).attr('aria-selected') != 'true') {
			$(this).removeClass('STYLE_datenbankTabelleHeadSelect');
			$(this).find('.s-ico').css('display','none');
		}
	});
	
	//Hinzugefügt von Simon - 01.02.2010 END

}); 
