var PAGE = 'http://joyharper.com/index.php/';
$(window).load(function(){
    resizeLogos();
    $('.joy').click(function(){
        location.href = PAGE + 'joy-harper-kollektion';
    });
    $('.miss').click(function(){
        location.href = PAGE + 'miss-harper-kollektion';
    });
});

$(window).resize(function(){
    resizeLogos();
});

var resizeLogos = function(){
    $('.block img').each(function(){
        var w = $(this).parent().innerWidth();
        var h = $(this).parent().innerHeight();

        var ow = $(this).innerWidth();
        var oh = $(this).innerHeight();


        var scale = 1;
        if(ow > w || oh > h){
            var scale = (ow >= w) ? (w/ow) : (h/oh);
        }else{
            var scale = (w >= ow) ? (w/ow) : (h/oh);
        }

        var m = (h - (oh*scale))/2;
        var nw = ow * scale;
        var nh = oh * scale;

        var maxW = $(this).css('max-width').substring(0, $(this).css('max-width').length-2);
        var maxH = $(this).css('max-height').substring(0, $(this).css('max-height').length-2);

        if(nw > maxW || nh > maxH){
            $(this).css({
                'margin-top': (($(this).parent().innerHeight()-maxH) / 2) + 'px',
                'width': maxW + 'px',
                'height': maxH + 'px'
            });
        }else{
            $(this).css({
                'width': nw + 'px',
                'height': nh + 'px',
                'margin-top': m + 'px'
            });
        }
    });
}

$(window).ready(function(){
   setTimeout((function(){location.href=PAGE + 'joy-harper-kollektion'}), 30000);
});
