$(document).ready(function() {
	
	
	
	
	var mygrid = jQuery("#softwareGrid").jqGrid({
		url:'index.php?type=9999',
		datatype: "json",
		width: 915,
		height: '100%',
		altRows: true,
		altclass: 'gridEvenRow',
		colNames:['Software','Screenshot', 'Anwendungsbereiche','ID'],
		forceFit: true,
		colModel: [
			  {name:'title',index:'title', width:350}, 
			  {name:'screenshot',index:'screenshot', sortable:false, search:false,width: 150},
			  {
			  	name: 'kategorie',
			  	index: 'kategorie',
			  	width: 150,
			  	stype: 'select',
			  	searchoptions: {
			  		dataUrl: 'index.php?type=9999&getCategories=true'
			  	}
			  },
			  {name:'id',index:'id',hidden:true}
			],
		cellLayout:30,
		rowNum:10, 
		mtype: "POST", 
		rowList:[10,20,30],
		pager: '#softwareGridPager',
		sortname: 'title', 
		viewrecords: true, 
		sortorder: "asc", 
		gridview : true, 
		caption:"Software ",
		onSelectRow: function(ids) {
			var ret = jQuery("#softwareGrid").jqGrid('getRowData',ids);					
			window.location.href ='/index.php?id='+digiID+'&tx_digipetseic_pi2[software]='+ret.id+'&tx_digipetseic_pi2[action]=detailview&tx_digipetseic_pi2[controller]=Software';
		},
		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("#softwareGrid").jqGrid('navGrid','#softwareGridPager',{edit:false,add:false,del:false,search:false,refresh:false}); 
	jQuery("#softwareGrid").jqGrid('navButtonAdd',"#softwareGridPager",{caption:"Toggle",title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s', onClickButton:function(){ mygrid[0].toggleToolbar() } });
	jQuery("#softwareGrid").jqGrid('navButtonAdd',"#softwareGridPager",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh', onClickButton:function(){ mygrid[0].clearToolbar() } }); 
	jQuery("#softwareGrid").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')) {
			$(this).find('.ui-icon-desc').css('backgroundPosition','100% 100%');
			$(this).find('.ui-icon-asc').css('backgroundPosition','0 100%');
		} else {
			if ($(this).find('.ui-icon-asc').hasClass('ui-state-disabled')) {	
				$(this).find('.ui-icon-asc').css('backgroundPosition','0 100%');
			} else {
				$(this).find('.ui-icon-asc').css('backgroundPosition','0 0');
			}
		
			if ($(this).find('.ui-icon-desc').hasClass('ui-state-disabled')) {	
				$(this).find('.ui-icon-desc').css('backgroundPosition','100% 0');
			} 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

}); 
