$(document).ready(function(){    
    $(".hoverButtons").hover(function(){
        $(this).attr('src', $(this).attr('src').replace( /_orig/i, '_rollover'));    
    }, function(){
        $(this).attr('src', $(this).attr('src').replace( /_rollover/i, '_orig'));                   
    });
    
    $('.item-rolover').each(function(){
        var img = $(this).parent().find("img.item-rolover");    
        var rollover_image = img.attr('src').replace( /_orig/i, '_rollover');      
        $('<img/>')[0].src = rollover_image;
    });    
    
    var img = null;
    var orig = null;
    $('.roloverselect').hover(function(){ 
        if (typeof orig != "undefined") {     
            img = $(this).parent().find("img.item-rolover");
            orig = img.attr('src');  
            img.attr('src', orig.replace( /_orig/i, '_rollover'));
        } 
    }, function(){
        if (img != null){
            img = $(this).parent().find("img.item-rolover"); 
            img.attr('src', orig);
        }
    });  
    

    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme:'facebook', 
        slideshow:5000, 
    });
    
    $('#frontpage-slider').nivoSlider({
        effect:       'random',
        controlNav:   false,    
        directionNav: false,
        manualAdvance:false,
        pauseTime:3000
    });
    
    $('#webtraders_beeldmerk>a').attr('title','');
    $('#wbtrslide').css('width','0').hide();
    $('#webtraders_beeldmerk').hover(function(){
        $('#wbtrslide').stop(true,true).animate({queue:false,width:"150px",opacity:"show",left:"0"},"slow");  
    },function(){
        $('#wbtrslide').animate({queue:false,width:"0",opacity:"hide",left:"-85"},"fast"); 
    });
    
    var default_values = new Array();
    $("input#searchfield").focus(function(){
        if (!default_values[this.id]){
          default_values[this.id] = this.value;
        }
        
        if (this.value == default_values[this.id]){
          this.value = '';
        }
        
        $(this).blur(function(){
          if (this.value == ''){
            this.value = default_values[this.id];
          }
        });
    });
    
    $('#searchform').click(function(){ 
        if($('#searchfield').val().length <= 2){
            $('#searchform').after('<div class="searchmsg">Search quote to short minimum is 3 letters</div>');
            //$('.search_msg').html('Search quote to short minimum is 4 letters');
        }else{
            $('#searchform').after('<div class="searchmsg">One moment please</div>');
            $.post(appPath+'search/prepare_string',{ 
                search_string: $('#searchfield').val() 
            }, function(data){                                                                
                $('#searchform').attr('action', appPath+'search/'+data);
                $('#searchform').submit();
                return false;
            });                
        }
        return false;    
    });
});     

