$(function(){
	var list = 1;
	//var ilosc = $('.cont_prod').length;
	if($('#cont_prod_2').length == 1)
		check('.cont_prod', '#cont_prod');
	
	if($('#cont_cat_2').length == 1)
		check('.cont_cat', '#cont_cat');
	
    $(".logo").click(function(){
        window.location = base_url;
    });

	if($("dt.name").length > 0){
		if($("dt.name").width() > 240) { $("dt.name").css({'width':'240px'}); $("dd.subname").css({'top':'55px'}); };
	}
	
	if($("dd.name").length > 0){
		$("dd.name").each(function(i, e){
			if($(e).height() > 13) { $(e).parent().find("dd.subname").css({'top':'47px'}); };
		});
	}
	
	function check(eleme, strin) {
		var ilosc = $(eleme).length;
		if( list == 1 || list < ilosc ) {
			$("#content_bg_inner").append('<a id="next_cont_prod" ><img src="/media/layout/next_button.png" alt="Next products" /></a>').fadeIn("fast");
		}
		
		if( list > 1) {
			$("#content_bg_inner").append('<a id="prev_cont_prod" ><img src="/media/layout/prev_button.png" alt="Previous products" /></a>').fadeIn("fast");
		}
		
		$("#next_cont_prod").bind('click', function(){
			$(this).remove();
			$(strin+'_'+list).animate({
				marginTop:'-=380px'
			}, 300, function(){
				list++; check(eleme, strin);
			});
		});

		$('#prev_cont_prod').bind('click', function(){
			$(this).remove();
			$((strin+'_'+(list-1))).animate({
				marginTop:'+=380px'
			}, 300, function(){
				list--; check(eleme, strin);
			});
		})
	}
	
})
window.onload = function () {
    var container = $('div.samples');
    var ul = $('ul', container);
    var itemsHeight = ul.innerHeight() - container.outerHeight();

    if(itemsHeight > 0){
        $('.slider', container).slider({
            min:0,
            max:itemsHeight,
            value: itemsHeight,
            orientation: 'vertical',
            slide: function (e, ui){
                ul.css('top' , '-'+(itemsHeight - ui.value)+'px');
            }
        });
    } else {
        $('#slidCont').hide();
    }
}
