﻿var currentWebKitPage = 1;
var webKitLoaded = false;
var showpagecontent;

function swapWebKitPanels(goto) {
    if (goto == 'prev') {
        if (currentWebKitPage > 1) { currentWebKitPage--; } else { return false; }
    } else if (goto == 'next') {
        if (currentWebKitPage < totalWebKitPages) { currentWebKitPage++; } else { return false; }
    } else {
        currentWebKitPage = goto;
    }
    jQuery('.web-kit-page-dot').removeClass('web-kit-page-dot-active');
    jQuery('#web-kit-page-' + currentWebKitPage).addClass('web-kit-page-dot-active');
    webKitPanels.fadeOut(100, function() {
        var startLoadingAt = (currentWebKitPage * 3 - 2);
        var loadIntoPanel = 0;
        for (i = startLoadingAt; i <= startLoadingAt + 2; i++) {
            // First check to see if the panel exists in case we're on the
            // last page and there are less than 3 panels to display.
            // With jQuery, jQuery('#item') returns an array of elements, so if
            // the array is empty, that label doesn't exists.
            var thisPanel = jQuery('#web-kit-panel-' + i)
            jQuery(webKitPanels[loadIntoPanel]).text('');
            if (thisPanel.length > 0) {
                jQuery(webKitPanels[loadIntoPanel]).html(thisPanel.html());
                loadIntoPanel++;
            }
        }

        webKitPanels.fadeIn(100);
        jQuery('.panel-visible').jScrollPane({ scrollbarWidth: 12, scrollbarMargin: 12, dragMinHeight: 24 });
    });
}


function GetShowFolders(showid) {

    jQuery.ajax({

        type: 'Post',
        url: "/Browse/ShowGrid.aspx/GetFolders",
        data: '{showid:' + showid + ',userid:' + 85 + '}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',

        success: function(response) {
            var div = jQuery("div[id=" + showid + "]");
            div.html(response.d);
            div.jScrollPane();
        }
    })
};



jQuery(document).ready(function() {

    var defaultSize = 40;
    jQuery("#current-show-name a").each(function() {
        var h = jQuery(this).height();
        var i = defaultSize;
        while (h > defaultSize) {
            i--;
            this.style.fontSize = i + 'px';
            h = jQuery(this).height();
        }
    });
    jQuery('.home-show-overlay').css({});
  //  jQuery('.home-show-overlay').fadeTo(0, 0.80);
    jQuery(".home-show").hover(
		    function() {
                 var id = jQuery(this).attr('id');
                 jQuery('#' + id + ' .home-show-overlay-content').css({ 'display': 'none', 'visibility': 'visible' });
                 jQuery('#' + id + ' .home-show-overlay').fadeTo(0, 0.80);
		        jQuery('#' + id + ' .home-show-overlay,#' + id + ' .home-show-overlay-content').fadeIn(250);
		    },
		    function() {
		    var id = jQuery(this).attr('id');
		        jQuery('#' + id + ' .home-show-overlay,#' + id + ' .home-show-overlay-content').fadeOut(250);
		    }
	    );
    jQuery('#show-img-buttons li').each(function() {

        var target = '#' + jQuery(this).attr('id').replace('-btn', '');
        var url = jQuery(this).children('a').attr('href');
        var tsTimeStamp = new Date().getTime();
        jQuery.get(url, { action: "get", time: tsTimeStamp }, function(response) {

            jQuery(target).html(response);
            //  alert(jQuery("#affiliate-news-content").height());
            jQuery("#affiliate-news-content").jScrollPane();

        });

    });

    jQuery('.show-page-content-container').hide();
    jQuery('.show-page-content-container:first').show();
    jQuery('#show-img-buttons li:first').addClass('show-img-btn-active');


    // swapWebKitPanels(1); // populate the panels on first load

    jQuery('#show-img-buttons li').click(function(event) {
        webKitPanels = jQuery('.panel-visible');
        event.preventDefault();
        var contentToShow = '#' + jQuery(this).attr('id').replace('-btn', '');
        jQuery('#show-img-buttons li').removeClass('show-img-btn-active');
        jQuery(this).addClass('show-img-btn-active');

        jQuery('.show-page-content-container').hide();
        jQuery(contentToShow).show();
        if ((contentToShow == '#web-kit') && (!webKitLoaded)) {
            swapWebKitPanels(currentWebKitPage);
            totalHiddenPanels = jQuery('.panel-hidden').length;
            totalWebKitPages = Math.ceil(totalHiddenPanels / 3);
            webKitLoaded = true;
        }


    });


});

