var ytswf;

function onYouTubePlayerReady(playerId) {
    //console.log("onYouTubePlayerReady");
    ytswf = document.getElementById('ytapiObject');
}

function stopvid() {
    if (ytswf && ytswf != 'undefined') {
        if (typeof ytswf.stopVideo == 'function') { 
            ytswf.stopVideo();
            ytswf.clearVideo();
            //console.log("stopped and cleared video");
        }
    }
    else {
        //console.log("called stopvid but ytswf was undefined");    
    }

}

function closemomentwindow() {
    if (ytswf && ytswf != 'undefined') {
        stopvid();
        swfobject.removeSWF("ytapiObject");
    }
    else {
        //console.log("called closemomentwindow but ytswf was undefined");    
    }
}

function openmomentwindow(podsid) {
    jQuery.openDOMWindow({ 
        windowSource:'iframe', 
        windowHTTPType:'post',
        width:480,
        height:560,
        borderSize:8,
        borderColor:'#fff',
        windowSourceURL:'http://beta.sportclipsmvp.com/watch/'+podsid
    }); 
}




















































jQuery(document).ready(function($) {

    // Birthday checker for any gravity forms on the site with the class set to 'birthdaycheck-18'
    $('.gform_wrapper .gform_footer input[type="image"]').click(
        function(){
            // Convert m/d/yyyy into date and test for validity
            var myDateArr = [];
            var myDate = $('.birthdaycheck-18 input').each(function(){myDateArr.push($(this).val())});
            var myDateStr = myDateArr[0]+'/'+myDateArr[1]+'/'+myDateArr[2];
            $('.birthdaycheck-18').removeClass('gfield_error');
            $('.birthdaycheck-18 .validation_message').remove();
            // Get upper age limit date
            var birth_date = Date.parse(myDateStr);
            var today_date = new Date();
            var diff_date =  today_date - birth_date;
            var num_years = Math.floor(diff_date/31536000000);
            if (isNaN(num_years) || num_years < 18) {
                $('.birthdaycheck-18').addClass('gfield_error');
                $('.birthdaycheck-18 .validation_message').remove();
                $('.birthdaycheck-18').append('<div class="gfield_description validation_message">You must be at least 18 years of age to enter.</div>');
                return false;
            }
            else {
                $('.birthdaycheck-18').removeClass('gfield_error');
                $('.birthdaycheck-18 .validation_message').remove();
                return true;
            }
        }
    );

});

// Get url parameter helper function
function gup( name, url )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( url );
    if( results == null )
        return "";
    else
        return results[1];
}

// Track zip code lookup with google analytics
function trackZipLookup($zipbox) {
    var theZip = jQuery($zipbox).val();
    _gaq.push(['_trackEvent', 'Zipcode Lookup', theZip]);
}	



