function lll (m)
{
    if(typeof console != 'undefined')
        console.log(m)
}
function b(e)
{
    $(e).css('border','1px red');
}


var lastTarget;

//$(function()
$(window).load(function()
        {
            // must *calc* width of slider images
            // 1. gallery
            var width = 0;
            var images=$('div.galleryProduct div.lineContent>ul img');
            for(var i=0;i<images.length;++i)
                width += $(images[i]).width()+20;
            $('div.galleryProduct div.lineContent>ul').width(width);
            if(width<=444)
               $('div.galleryProduct a.left,div.galleryProduct a.right,').hide();
    
            // http://simm-marketing.com/darda/produkte/produkte/item/50105/
            width =0 ;
            var images=$('div.galleryMoreProducts div.lineContent>ul img');
            for(var i=0;i<images.length;++i)
            {
                //alert($(images[i]).width())
                var w=$(images[i]).width()||0;
                if(w<=10) w = 400;
                width += w +20;
            }
            $('div.galleryMoreProducts div.lineContent>ul').width(width);
            if(width<=960) $('div.galleryMoreProducts a.left,div.galleryMoreProducts a.right,').hide();
            var min=900;
            if(width<min)  $('div.galleryMoreProducts div.lineContent>ul').width(min);
            
            
            
            $('div.gallery a, div.lineNav a').css('cursor','pointer');
            $('div.gallery a, div.lineNav a').mousedown(function(e)
            {
                lastTarget=e.target;
                if(typeof __slidertimer != 'undefined') 
                    clearInterval(__slidertimer);
                __slidertimer=setInterval(function()
                {
                    if($(lastTarget).hasClass('left')) direction=1;
                    else 
                                                       direction=-1;
                    var speed=25;
                    
                    var tomove=$(lastTarget).siblings('div.lineContent').children('ul');
                    if(tomove.length==0) 
                    {  
                        // for the other one
                        tomove = $('div.lineContent ul',$(lastTarget).parents('div.linePictures'));                    
                    }
                    
                    
                    tomove=$(tomove);
                    var old;
                    try{
                        old = tomove.css('margin-left');                    
                        old = parseInt(old.split('px')[0]);
                    } catch(e) {
                        old = 0;
                    }
                    old += speed*direction;
                    var min=0;
                    
                    
                    var max=-   $(lastTarget).parents('div').find('ul').width() +400;                                         
                    if(old>min) old=min;
                    if(old<max) old=max;
                    
                    //$(tomove).css('margin-left',old+'px');
                    $(tomove).css('margin-left',old);
                    
                    
                }, 50);                
            })            
            $('div.gallery a, div.lineNav a').mouseup(function(e)
            {
                if(typeof __slidertimer != 'undefined') 
                    clearInterval(__slidertimer);
            });
            $('div.galleryProduct div.lineContent ul li a img').css('cursor','pointer');
            $('div.galleryProduct div.lineContent ul li a img').click(function(e)
            {
                // same products, different views
                var src=$(e.target).attr('rel');
                $('div.galleryProduct table td a img').attr('src',src);
               // $('div.galleryProduct table td a img').height(244);
                // update zoom icons URL
                $('div.galleryProduct a.zoom').attr('href',src);                                
            });        
            $('div.galleryMoreProducts div.lineContent ul li a img').click(function(e)
            {
                // random related products
                var src=$(e.target).attr('rel');
                window.location = src;                
            });        
          //  $('div.galleryProduct table td a img').height(244);
            
            
            
            
            /* Neu Produkte handler 2009.10.15 */   
            $('div.showcase a.left,div.showcase a.right').css('cursor','pointer');            
            $('div.showcase a.left,div.showcase a.right').click(function(evt)
            {
                
                var images=$('div.showcase img');                
                for(var i =0;i<images.length;i++)
                {
                    var img=images[i];
                    if($(img).parents('a').css('display') != 'none')
                    {                    
                        $(img).parents('a').css('display','none');
                        if($(evt.target).hasClass('left'))
                            img2 = i>0? $(images[i-1]) : $(images[images.length-1]);
                        else
                            img2 = i<images.length-1? $(images[i+1]) : $(images[0]);
                        
                        $(img2).parents('a').css('display','inline');                                                
                        $(img2).css('display','inline');                                                
                        np_set_title($(img2).parents('a').attr('rel'));
                        return;
                    }
                }
                
            });
            /* Title of neu produkt  */
            function np_set_title(title){
                $('div.showcase div.title').html(title);
            }
            
            np_set_title($($('div.showcase img')[0]).parents('a').attr('rel'));
           
           
            // Clear search text field
           $('form.search input').focus(function()
           {    
                if($('form.search input').attr('value') == 'Produkt suchen'
                || $('form.search input').attr('value') == 'Product search')
                
                    $('form.search input').attr('value',''); 
           });
           
           
            $("form.search").submit(function() {
                if($('form.search input').attr('value')==''||$('form.search input').attr('value').length<1)
                {
                    return false;
                }
            });

            
                      
            // arm colorbox
            $("a[rel='bigimages']").colorbox({photo:true,maxWidth:'600px',maxHeight:'600px'});
            $("a.zoom").colorbox({photo:true,maxWidth:'600px',maxHeight:'600px'});
           
            
        });


