$(document).ready(function(){

    $('#bannerFader').hide();
    new Banner();

    var menuHeight = $('#menuBox').outerHeight();
    $('.twitterPanelLong').css({marginTop : (menuHeight - 70)+'px'});

    $('#menuBox').find('li').click(function(){
        var href = $(this).find('a.white').attr('href');
        window.location = href;
    });


    $('.threeCols').each(function(){
        var aHeight = $(this).height();
        $(this).find('[class~="textCol"]').each(function(){
            $(this).height(aHeight);
        })
    });

    $('.playBtn').click(function(){
        if($('#popUp').length == 0){
            var vid = $(this).parent().find('.youtube').html();
            $('body').prepend('<div id="popUp"><div>');
            setPopUpPos();
            $('#popUp').html(vid);
            $('#popUp').append('<p id="close" class="right dBlue text arial underline pointer">Close Window</p>');    
        }        
    });

    $('.galleryImg').click(function(){
			var title = $(this).attr('title');
        if($('#popUp').length == 0){
            var img = $(this).attr('src');
            img = img.replace('&w=153&h=100&zc=1', '');
            $('body').prepend('<div id="popUp"><div>');
            setPopUpPos();
            $('#popUp').append('<img src="'+img + '&w=545&h=390&zc=1' + '" alt="" width="545" height="390" />');
			 $('#popUp').append('<p class="left text arial">'+title+'</p>');
            $('#popUp').append('<p id="close" class="right dBlue text arial underline pointer">Close Window</p>');
        }        
    });

    $('#close').live('click', function(){
        $(this).parents('#popUp').remove();
    });

    $('[class~="newsItem"]').find('.readMore').click(function(){
        var title = $(this).parents('[class~="newsText"]').find('[class~="newsTitle"]').html();
        var copy = $(this).parents('[class~="newsText"]').find('.newsFullText').html();
        if($('#newsPopUp').length == 0){
            $(this).parents('[class~="newsItem"]').prepend('<div id="newsPopUp"><p id="newsCloser" class="grey text arial">Close Window</p></div>');
            $('#newsPopUp').append('<div class="floatFix"></div><h2 class="georgia brown italic light">'+title+'</h2>');
            $('#newsPopUp').append('<p class="grey text arial">'+copy+'</p>');
        }        
    });


    $('#newsCloser').live('click', function(){
        $(this).parents('#newsPopUp').remove();
    });
});

function setPopUpPos(){
    var width = $('body').outerWidth();
    var left = ((width - 980) / 2) + 345;
    var windowHeight = $(window).height();
    var top = 0;
    if(windowHeight > 430){
        top = (windowHeight - 430) / 2;
    }
    $('#popUp').css({top : top+'px', left: left+'px'});
}
