function setCompareFnc()
{
	//console.debug('setCompareFnc');
	$('input:checked').attr('disabled', true);
}

function resetCompareFnc( sCaid)
{
	$('input[name=caid['+ sCaid +']]').attr('disabled', false).attr('checked', false);
	oDivElm = document.getElementById( 'field_'+sCaid);
	$( oDivElm).removeClass('active');
}

function changeField( sId, oInp)
{
	oDiv = document.getElementById( sId);
	if( $( oInp).attr('checked'))
	{
		$( oDiv).addClass( 'active');
	}
	else
	{
		$( oDiv).removeClass( 'active');
	}		
}

$(document). ready( function(){
	$( '.gallery_box').hover( function ()
			{
				$('.to_detail', this).css( 'display', 'block');
			},
			function ()
			{
				$('.to_detail', this).css( 'display', 'none');
			});
	$( '.tree .open_cat').click( function ()
			{
				if ( $( '.tree .subcat').css( 'display') == 'none')
				{
					$( '.tree .subcat').css( 'display', 'block');
					$(this).addClass( 'close');
				}
				else
				{
					$( '.tree .subcat').css( 'display', 'none');
					$(this).removeClass( 'close');
				}
				return false;
			}
			);
	$( '.attributes .checkbox').click( function ()
			{
				actUl = $(this).parent().parent();
				name = $(this).attr('name');
				if ( $(this).hasClass( 'checked'))
				{
					$(this).removeClass( 'checked');
					//console.debug( $( 'input[name='+name+']', actUl));
					$( 'input[name='+name+']', actUl).val( '');
					var str = $( '#_filterlist').serialize();
					//console.debug(str);
					//console.debug(sShopUrl);
					//ajax_load( 'on');
					//$( '#body').load( sShopUrl, str, function (responseText) { setAjax(); ajax_load( 'off'); });
					$( '#_filterlist').submit();
				}
				else
				{
					//$( 'span', actUl).removeClass( 'checked');
					$(this).addClass( 'checked');
					$( 'input[name='+name+']', actUl).val( $(this).attr('value'));
					var str = $( '#_filterlist').serialize();
					//console.debug($( 'input[type=hidden]', actUl));
					//console.debug(str);
					//console.debug(sShopUrl);
					//ajax_load( 'on');
					//$( '#body').load( sShopUrl, str, function (responseText) { setAjax(); ajax_load( 'off'); });
					$( '#_filterlist').submit();
				}
			});
	$( '.attributes .attr_count').click( function ()
			{
				actLi = $(this).parent().parent();
				valuesUl = $( '.values', actLi);
				if ( $( valuesUl).css( 'display') == 'none')
				{
					$( valuesUl).css( 'display', 'block');
					$(this).addClass( 'close');
				}
				else
				{
					$( valuesUl).css( 'display', 'none');
					$(this).removeClass( 'close');
				}
				return false;
			});
	$( '.attributes .attr_count').filter(function()
			{
				actLi = $(this).parent().parent();
				if ($ ( '.checkbox', actLi).hasClass( 'checked'))
				{ 
					$('.values', actLi).css('display', 'block');
					
					//$( 'input', actLi).val( $( '.checked', actLi).attr('value'));
					return true;
				}
				return false;
			}).addClass('close');
	$( "div[id*='field_'] input").click( function()
			{
				divId = $( this).parent().attr( 'id');
				changeField( divId, $( this));
				$( this).blur();
			});
	$( '#delfilter').click( function()
			{
				$( 'ul.values input').val('');
				$( '#_filterlist').submit();
				return false;
				
			});
	//setAjax();
	setAvailability();
});

function setAjax()
{
	setAnsicht();
	setAvailability();
}

function setAnsicht()
{
	$( '#ansicht a').click( function()
			{
				var str = $( this).attr( 'href');
				var aStr = str.split('?');
				//console.debug( aStr);
				ajax_load( 'on');
				$( '#body').load( sShopUrl, aStr[1], function (responseText) { setAjax(); ajax_load( 'off'); });
				return false;
			});
}

function setAvailability()
{
	$( '#slct_availability').change( function ()
			{
				//var str = $( '#_availability').serialize();
				//ajax_load( 'on');
				//console.debug( str);
				//$( '#body').load( sShopUrl, str, function (responseText) { setAjax(); ajax_load( 'off'); });
				$( '#_availability').submit();
			});
}

function setSelectEvent( sUrl, sPBoxId, sCntr, sActId, bSlider)
{
	$( 'select', sPBoxId).change( function () 
			{
				if( $('option:selected', this).val() != '' && $('option:selected', this).val() != sActId)
				{
					var aid = $('option:selected', this).val();
					//ajax_load('on');
					productBoxLoad( true, sPBoxId);
					$( sPBoxId).load( sUrl + "index.php?cl=dd_productlist_cnt&anid=" + aid + "&cntr=" + sCntr, function (responseText) { 
																														 setSelectEvent( sUrl, sPBoxId, sCntr, sActId); 
																														 productBoxLoad( false, sPBoxId); 
																														 if ( bSlider)
																														 {
																															 //alert( '*');
																															 setSlider( 4, '#slider_list_' + sCntr, 4);
																														 }
																														 } );
				}
			});
}

function productBoxLoad( schalter, sPBox)
{
	if( schalter)
	{
		$( '.load', sPBox).addClass( 'on');
	}
	else
	{
		$( '.load', sPBox).removeClass( 'on');
	}
}

function setSlideAfterAjax( sSliderId, sUrl, sPBoxId)
{
	//console.debug( sSliderId + '  ' + sUrl + '  ' + sPBoxId);
	//setSlider(7, sSliderId, 1);
	//setSlideEvent(sSliderId, sUrl, sPBoxId);
	ajax_load( 'off');
}