$(document).ready( function() {

		// oznaczenie wiersza z dodatkowymi cechami dynamicznymi jako ROZNICA jesli wystepuja tam roznice
		$('.pojViewCompare .extraDynamicFeature').each(function(){
				
				var sFirstChildContent = $(this).children('td:first').text();
				if ( $(this).children('td').size() != $(this).children("td:contains('"+sFirstChildContent+"')").size() ){
					$(this).addClass('itemDiff');
				} 

				
		});
		
		// nadanie klasy itemDiffEven dla elementow majacych klase row-even
		$('.pojViewCompare .itemDiff').each(function(){
			if($(this).hasClass('row-even'))
				$(this).addClass('itemDiffEven');
		})
		
		$('#txtDrukujPorownanie').click(printCompare);			
		
		// naprawa linkow o klasie linkRightArrow (przesuniecie strzalki na srodek w pionie, dosuniecie jej do tekstu)
		fRepairLinkRightArrow();
		
		// dodanie zdarzenia over i click dla funkcji z opisami
		$('.pojFeatureDescContainer').each(function(){
				
				$(this).hover(function(){
						$(this).children().children('.pojFeatureDesc').css('display','block');
						iTop = 8+$(this).children().children('.pojFeatureDesc').height();
						$(this).children().children('.pojFeatureDesc').css('top','-'+iTop+'px');
						$(this).addClass('pojFeatureDescContainerActive');
				},
					function(){
						$(this).children().children('.pojFeatureDesc').hide();
						$(this).removeClass('pojFeatureDescContainerActive');
					}
				);
			
		});

})

/**
 * usuniecie produktu z sesji z listy do porownywania
 * @param {int} iProductId
 */
function fDelProductFromCompare(iProductId){
	
		sUrl = 'index.php?sModul=mProductsXML&sAction=delProductFromCompare&iProductId='+iProductId;
		
		$.ajax({
				type: 'GET',
				url: sUrl,
				dataType : 'xml',
				success: function(oXml){				
						
						var iStatus = $(oXml).find('iStatus').text();
						
						if (iStatus == 1){
							
								sHref = location.href;
								aHref = sHref.split('#');
								if(aHref.length>0)
										sHref = aHref[0];
							
								location.href = sHref;
							
						} else {
								
								alert( $(oXml).find('sMessage').text() );
						}
				}
		});
	
}

/**
 * pokazanie porownania produktow dla danej grupy
 * @param {string} sGroupName
 */
function fShowGroupCompare(iGroupId){
	sUrl = 'index.php?sModul=mProductsXML&sAction=showGroupCompare';
	sPostData = 'iGroupId=' + iGroupId +'&'+ sLangParams;
	
	$.ajax({
		type: 'POST',
		url: sUrl,
		data: sPostData,
		dataType: 'xml',
		error : function(XMLHttpRequest, textStatus, errorThrown){
			$('#pojProductsGroupCompare').html(sUrl);
		},
		success: function(oXml){
		
			var iStatus = $(oXml).find('iStatus').text();
			
			if (iStatus == 1) {
			
				$('#pojProductsGroupCompare').html($(oXml).find('content').text());
				
				// oznaczenie wiersza z dodatkowymi cechami dynamicznymi jako ROZNICA jesli wystepuja tam roznice
				$('.pojViewCompare .extraDynamicFeature').each(function(){
						
						var sFirstChildContent = $(this).children('td:first').text();
						if ( $(this).children('td').size() != $(this).children("td:contains('"+sFirstChildContent+"')").size() ){
							$(this).addClass('itemDiff');
						} 

						
				});
				
				// nadanie klasy itemDiffEven dla elementow majacych klase row-even
				$('.pojViewCompare .itemDiff').each(function(){
					if($(this).hasClass('row-even'))
						$(this).addClass('itemDiffEven');
				})
				
				// dodanie zdarzenia onclick dla linku do pobrania xlsa
				$('#btnSaveXls').click(function(){
						
						location.href = 'index.php?sModul=mProductsFiles&sAction=sendCompareToCSV&iGroupId='+iGroupId;
						
				});
				
				$('#txtDrukujPorownanie').click(printCompare);			
				
				// naprawa linkow o klasie linkRightArrow (przesuniecie strzalki na srodek w pionie, dosuniecie jej do tekstu)
				fRepairLinkRightArrow();
				
				Cufon.replace('#pojProductsGroupCompare h2 span',{ fontFamily: 'DINPro' });
				
				// dodanie zdarzenia over i click dla funkcji z opisami
				$('.pojFeatureDescContainer').each(function(){
						
						$(this).hover(function(){
								$(this).children().children('.pojFeatureDesc').css('display','block');
								iTop = 8+$(this).children().children('.pojFeatureDesc').height();
								$(this).children().children('.pojFeatureDesc').css('top','-'+iTop+'px');
								$(this).addClass('pojFeatureDescContainerActive');
						},
							function(){
								$(this).children().children('.pojFeatureDesc').hide();
								$(this).removeClass('pojFeatureDescContainerActive');
							}
						);
					
				});
				
			}
			else {
			
				alert($(oXml).find('sMessage').text());
			}
		}
	});
	
}


function printCompare() {
	
	window.print();
	return false;
	
}
