// JavaScript Document
$(document).ready(function(){
    $('ul#portfolio').innerfade({
	    speed: 1000,
	    timeout: 4000,
	    type: 'random_start',
	    containerheight: '220px'
    });
			
    $('a').attr('target','_blank');
    $('a[href^="http://hobbytime.siteworks.nl/"]').attr('target','_self');
    $('a[href^="http://www.hobbytime.nl/"]').attr('target','_self');
            
    var myElement = $('.top');
    myElement.css({
      position: 'absolute',
      left: '50%',          
      'margin-left': 0 - (myElement.width() / 2)
    });
		
    $('#postcode').keyup(function() {
        $('.dealer_item').fadeOut('slow');
        pcFilter = $(this).val().substring(0,1);
        $('.dealer_item[zip^="'+pcFilter+'"]').fadeIn('slow');
    });

    $("#slider").easySlider({
	    auto: true, 
	    continuous: true,
	    vertical: false,
	    pause: 800,
	    speed: 800,
	    prevText: '',
	    nextText: '',
	    controlsShow: false,
    });
	
    $(".social a img").fadeTo("fast", 1.0);
    $(".social a img").hover(function(){
        $(this).fadeTo("fast", 0.7);
        },function(){
        $(this).fadeTo("fast", 1.0);
    });
		
    $('.nws-short-txt').each(function () {
        $(this).append('<span>'+$(this).html()+'</span>');
        var $span = $('> span', this).css('opacity', 0);
        $(this).hover(function () {
            $span.stop().fadeTo(400, 0);
            }, function () {
            $span.stop().fadeTo(200, 0);
        });
    });
    
     
    $('.nws-short-txt')
        .css( {backgroundPosition: "0 0"} )
        .mouseover(function(){
        $(this).stop().animate({backgroundPosition:"(-30px 0)"}, {duration:350})
        })
        .mouseout(function(){
            $(this).stop().animate({backgroundPosition:"(30px 0)"}, {duration:200, complete:function(){
                $(this).css({backgroundPosition: "0 0"})
        }})
    });
});

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
            
