﻿/// <reference path = "lib/jquery-1.4.1-vsdoc.js" />

/**************************************
@file - Moondog Headliner Dynamic Layout
@author - Christian Schlensker <TAG>
**************************************/

//vars
var marquee;
var content;
var current;
var currentTextSize;
var currentFontSizeNum;

/**************************
//Document Ready Function
**************************/
$(function () {

    //populate variables
    marquee = $('.marquee');
    content = marquee.children();
    currentTextSize = content.css('font-size');
    currentFontSizeNum = parseFloat(currentTextSize);

    //fit the marquee content
    fitContent();


    //Setup proper layout based on the availible media

    //is there a video?
    if ($("#headliner").is(':has(object)')) {

        //make the thumbnails have three collumns
        $(".thumbnails li:nth-child(3n+1)").css({
            'clear': 'left'
        });

        //position the thumbnails
        $(".thumbnails").css({
            'float': 'right',
            'margin-top': '-20px'
        });
    }

    //if there are no images, center the video
    if (!$("#headliner").is(':has(.thumbnails li)')) {
        $(this).find('.video').css({
            'float': 'none',
            'text-align': 'center'
        });
    }

    //if there is no media, add the 'no-media' class
    if (!$("#headliner").is(':has(.thumbnails li)') && !$("#headliner").is(':has(object)')) {
        $('#headliner').addClass('no-media');
        $("#announcements").addClass('no-media');
    }

});


/**************************
//Recursive function that decreases the marquee content's font size until it fits inside the marquee.
**************************/
function fitContent() {

    content = $(content);

   

    if (content.height() > marquee.height()) {
        //decrement font size
        currentFontSizeNum--;

        //give content new font-size;
        content.css('font-size', $(currentFontSizeNum).toEm());

        fitContent();
    }

    
}
