﻿var ready = false;

function scale()
{

    var x = $('body').width();
    x = (x < 1000) ? 1000 : x;
    
    $('.banner').width(x);
    $('.banner').height(250);        

    $('.banner .banner-homepage-slide').each(function(index) {
    
        var background = $(this).find('img.background');
        var aspect = background.height() / background.width();
        var y = x * aspect;
        
        background.width(x);
        background.height(y);   
        background.css('top', (y > 250) ? (250-y) / 2 : 0)     
        
        var content = $(this).find('.content');   
        
        content.height(400);    
        content.css('left', (x < 1000) ? 0 : (x-1000)/2 );                 

    });
}

function showFrame(stallionId, instant)
{
    if (!ready) {
        return;
    }

    if (instant == null) {
        instant = false;
    }
    
    $('.stallion-list a').each(function(index) {
        if($(this).attr('id') == "link" + stallionId) {
            $(this).attr('class', 'selected');
        }
        else {
            $(this).removeAttr('class');
        }       
    });
    
    if(instant)
    {
        $('.banner .banner-homepage-slide').each(function(index) {
            if($(this).attr('class') == "banner-homepage-slide banner-homepage-slide" + stallionId) {
                $(this).find('*').show();
            }
            else {
                $(this).find('*').hide();
            }          
        });        
    }
    else {
        $('.banner .banner-homepage-slide').each(function(index) {
            if($(this).attr('class') == "banner-homepage-slide banner-homepage-slide" + stallionId) {
                $(this).find('*').fadeIn(500, 'linear');
            }
            else {
                $(this).find('*').fadeOut(500, 'linear');
            }          
        });        
    }  
}

$(window).load(function() {
    $('img.loading').hide();
    scale();
    scale();
    ready = true;
});

$(window).resize(function() {
    scale();
});

