
function LoadArticleEvents()
{
    LoadGames();
    LoadChannelHeader();
}

function LoadChannelHeader() {
    var channelClass = '' + $('#hiddenChannelClass').html();
    var channelUrl = '' + $('#hiddenChannelUrl').html();

    $('#content').addClass(channelClass);
    if (channelUrl.length > 0) {
        $('.channel-logo').click(function(event) {
            window.open(channelUrl);
        });
    }
}

function LoadPhotoGalleryEvents(firstImageUrl, firstImageTitle)
{
    // Load first image
    $('#full_img_title').html(firstImageTitle);
    LoadImage(firstImageUrl, 'full_img', 'full_img_loading');
    $('#full_img').attr('alt', firstImageTitle);
    
    // Photo gallery settings
    var offset = 0;
    var animate_speed = 100; // milliseconds;
    var animate_distance = 110; // pixels;
    var num_images = 0;
    
    var num_images_str = $('#num_images').val();
    num_images = parseInt(num_images_str);
    
    $('#slideLeft').click(function(event) {
            offset-=animate_distance;
            $('.nContainer').animate({
                left: offset
                },animate_speed);
            $('#slideRight').css('visibility','visible');
        if (offset<((num_images-5)*-1*110)) {
            $('#slideLeft').hide();
        }
    });
    
    $('#slideRight').click(function(event) {
        if (offset >=0) {
            offset = 0;
        } else {
            offset+=animate_distance;
            $('#slideLeft').show();
        }
        $('.nContainer').animate({
            left :offset
        }, animate_speed);
        if (offset >= 0) {
            $('#slideRight').css('visibility','hidden');
        }
    });
    
    $('.gallery_thumbnail').click(function(event) {                
        
        // Reset then set opacity on thumbnails
        $(this).parent('.oContainer').children('.gallery_thumbnail').children('img').css({ opacity:"1.0" });
        $(this).children('img').css({ opacity:"0.3" });
        
        // Load full image
        $('#full_img_title').html($(this).children('input').val());
        LoadImage($(this).children('input.theImage').val(), 'full_img', 'full_img_loading');
        $('#full_img').attr('alt', $(this).children('input').val());
    });
    
    $('.gallery_thumbnail').hover
    (
        function() 
        {
            $(this).children('img').removeClass('imgOff');
            $(this).children('img').addClass('imgOver');
        },
        function()
        {
            $(this).children('img').removeClass('imgOver');
            $(this).children('img').addClass('imgOff');
        }
    );
}

function GetSearchArticles(divId, terms, pageId, pageSize)
{
    scroll(0,0);
    $('#' + divId).html('<p class="loading">Loading articles, please wait...</p>');
    
    $.ajax
    (
        {
            type: "POST",
            url: "/ajax/getSearchArticles.aspx",
            data: "terms=" + encodeURIComponent(terms) + "&p=" + pageId + "&ps=" + pageSize,
            success: function(msg)
            {
                $('#' + divId).html(msg);
            }
        }
     );
}

// Used for flash gallery
function LoadFlashPhotoGallery(galleryFeed) {
    var host = $('#galleryHost').html();
    var id = $('#galleryId').html();

    var so = new SWFObject("http://assets.moviefill.com/swf/imagegallery_v14.swf", "ImageGallery", "600", "1500", "8", "#FFFFFF");
    so.addParam("FlashVars", 'celebid=-1&host=' + host + '&id=' + id);
    so.addParam("allowScriptAccess", "always");
    so.addParam("wmode", "Transparent");
    so.addParam("allowFullScreen", "false");
    so.addParam("allowNetworking", "all");
    so.write("flashPhotoGallery");
}

function HandlerOnChange(num)
{
	parent.location.hash = "id="+num;
}

// Set Photoview Clicking Ad Refresh
function changePage(PhotoId, ViewOrder, PhotoTitle, Height) {
    var _height = 200;
    if (Height != null) 
    {
        _height = _height + Height;
        $('#flashPhotoGallery').height(_height);
    }
    // show photo title
    if (PhotoTitle == null) {
        parent.document.title = $('#galleryPageTitle').html() + " - MovieFill.com";
    }
    else {
        parent.document.title = $('#galleryPageTitle').html() + " - " + PhotoTitle + " - MovieFill.com";
    }

    // photo photo in iframe
    parent.FlashPhotoLarge.location.href = "/FlashPhotoViewer.aspx?photoid=" + PhotoId;
    parent.IframeAdsTop.location.href = "/IframeAds.aspx?channelid=" + $('#hiddenChannelId').html() + "";
    parent.IframeAdsBottom.location.href = "/IframeAds.aspx?bottom=1&channelid=" + $('#hiddenChannelId').html() + "";
    document.location.href = "" + $('#viewPhotoFromLink').html() + "#id=" + ViewOrder + "";
}
  
// jump to correct photo from link #number
function LinkViewPhoto()
{
    var temphash = parent.location.hash;
    temphash = temphash.replace("#id=","");
    return temphash;
} 
//RollingStone Video Function
function popupVideoPlayer(video, preroll)
{
      var url = "http://www.rollingstone.com/videos/player/" + video;

      if (preroll == false)
        url = url + "?preroll=false";

     var popup =  window.open(url,"flashplayer","width=720,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");

     popup.focus();

     return false;
}