function gotoAnchor(anchor) {
    location.href="#" + anchor;
}
function resizePopup()
{
    $('#popup_modal').css('height', parseInt(($(window).height()*0.8))+'px');    
}
$(document).ready(function() {  
    
      
    $('#privacy').click(function()
    {
        $('#popup_modal').html($('#privacy-content').html());
        hbc_popup('popup_modal', '#?w=910&h=450');
        return false;
    });
    $('#terms').click(function()
    {
        $('#popup_modal').html($('#terms-content').html());
        hbc_popup('popup_modal', '#?w=910&h=450');
        return false;
    });
    $('a[rel=video]').each(function()
    {
        $(this).click(function(){
            var scr = '<iframe title="YouTube video player" width="640" height="510" src="'+$(this).attr('href')+'?rel=0&amp;autoplay=1&amp;hd=1" frameborder="0" allowfullscreen></iframe>';
            $('#popup_modal').html(scr);
            hbc_popup('popup_modal', '#?w=640&h=510');
            return false;
        });
    });
   
    //Close Popups and Fade Layer
    $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  //fade them both out
            $('#popup_modal').html('');
        });
        return false;
    });
    var _ar = document.location.toString().split('#');
    var _str = "";
    if(_ar.length > 1)
        _str = _ar[1].toString();
    if(_str.toLowerCase() == "download")
    {
        $("#download-link").trigger("click");
        /*if($("#download-link"))
        {

            /*$('#popup_modal').html($('#download-form').html());
            hbc_popup('popup_modal', '#?w=465');
            return false;
        }*/
    }

});

function hbc_popup(popID, popURL, unfloat, _percent, video)
{
    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    
    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({
        'width': Number( popWidth )
    }).prepend('<a href="#" class="close" style="position: absolute; float: right; right: 8px; top: -8px;" ><img id="btn_close_popup" src="/images/buttons/close.png" border="0" class="btn_close" title="Close Window" alt="Close" /></a>');
    if(video)
        $('#' + popID).css({
            'height' : Number(dim[1].split('=')[1])
        });
    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft,
        'position' : 'fixed',
        'top' : '50%',
        'padding' : '20px',
        'display' : 'block'
    });
    
   

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({
        'filter' : 'alpha(opacity=80)'
    }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
}
