﻿// **********************************************************************************************
// main stage
// **********************************************************************************************


function mainStage_init() {


    selectedTab = Math.floor(Math.random() * 4) + 1;
    
    mainStage_selectTab(selectedTab);
       
}

var mainStageInterval = null;
function mainStage_selectTab(tabNum) {

    // reset stage
    document.getElementById('gallery1text').innerHTML = '';
    document.getElementById('mainStage_image1').src = '';
    document.getElementById('mainStage_image2').src = '';
    document.getElementById('gallery1leftright').innerHTML = '';
    document.getElementById('mainStage_text').innerHTML = '';
    mainStage_activeImage = 2;

    mainStage_updateItem(tabNum, "", true);

    if (mainStageInterval != null) {
        clearInterval(mainStageInterval);
    }

    mainStageInterval = setInterval(function() { mainStage_currentItemNum = parseInt (mainStage_currentItemNum)+1;  mainStage_updateItem(tabNum, mainStage_currentItemNum, false) }, 10000);


    document.getElementById(mainStage_tab1).className = 'gallery2';
    document.getElementById(mainStage_tab2).className = 'gallery2';
    document.getElementById(mainStage_tab3).className = 'gallery2';
    document.getElementById(mainStage_tab4).className = 'gallery2';
    document.getElementById(mainStage_tab5).className = 'gallery2';

    if (tabNum == 1) { document.getElementById(mainStage_tab1).className = 'gallery2curr'; }
    if (tabNum == 2) { document.getElementById(mainStage_tab2).className = 'gallery2curr'; }
    if (tabNum == 3) { document.getElementById(mainStage_tab3).className = 'gallery2curr'; }
    if (tabNum == 4) { document.getElementById(mainStage_tab4).className = 'gallery2curr'; }
    if (tabNum == 5) { document.getElementById(mainStage_tab5).className = 'gallery2curr'; }


}

var mainStage_currentItemNum = null;
var mainStage_currentItemNum2 = null;
var mainStage_activeImage = 2;
function mainStage_updateItem(tabNum, itemNum, selectRandom) {
    

    if (parseInt(itemNum) > parseInt(tabsData[tabNum].length - 1)) { itemNum = 0; mainStage_currentItemNum = itemNum; }
    
    if (!selectRandom) {
        // dont switch item on if currently on the first or last item
        if ((itemNum > tabsData[tabNum].length - 1) || (itemNum < 0)) { itemNum = 0; mainStage_currentItemNum = itemNum; return; }        
    }
    else {
        // select random item
        itemNum = Math.floor(Math.random() * tabsData[tabNum].length);
        mainStage_currentItemNum = itemNum;
    }
   
       

    var itemImage;
    if (tabsData[tabNum].length > 0) {

        // populate stage
        itemHeadline = tabsData[tabNum][itemNum][0];
        itemAd = tabsData[tabNum][itemNum][1];
        itemLink = tabsData[tabNum][itemNum][2];
        itemImage = tabsData[tabNum][itemNum][3];

        // disable paging
        itemBullets = '<a class="dotsright"  style="cursor:pointer" onclick="" ></a>';
        for (i = tabsData[tabNum].length - 1; i >= 0; i--) {

            if (i == itemNum) {
                itemBullets += '<a alt="" class="dota3" />';
            }
            else {
                itemBullets += '<a alt="" class="dota2" onclick="" />';
            }
        }

        itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="" ></a>';
        document.getElementById('gallery1leftright').innerHTML = itemBullets;



        document.getElementById('gallery1text').innerHTML = itemHeadline;
        document.getElementById('mainStage_text').innerHTML = itemAd;
        

        if (mainStage_activeImage == 2) {

            if (!selectRandom) {

                
                    
                    document.getElementById('mainStage_image1').src = tabsData[tabNum][itemNum][3]; // prepare the previous image                    

                mainStage_currentItemNum2 = itemNum;

                // run this if not the first time
                $('#mainStage_image1').css({ opacity: 0.0 }).animate({ opacity: 1.0 }, 1000);
                $('#mainStage_image2').animate({ opacity: 0.0 }, 1000);

                $.when($('#mainStage_image1'), $('#mainStage_image2')).done(function () {

                    document.getElementById('mainStage_image1').src = itemImage;

                    
                    if (parseInt(itemNum + 1) > parseInt(tabsData[tabNum].length - 1)) {
                        //document.getElementById('mainStage_image2').src = tabsData[tabNum][0][3]; // prepare the next image
                    }
                    else {
                        //document.getElementById('mainStage_image2').src = tabsData[tabNum][itemNum + 1][3]; // prepare the next image
                    }

                    if (itemLink != '') { document.getElementById('mainStage_image1').style.cursor = 'pointer'; document.getElementById('mainStage_image1').onclick = function () { window.open(itemLink); }; }
                    else { document.getElementById('mainStage_image1').style.cursor = 'arrow'; document.getElementById('mainStage_image1').onclick = function () { }; }

                    // paging
                    itemBullets = '<a class="dotsright"  style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum + 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum + 1) + ', false);" ></a>';
                    for (i = tabsData[tabNum].length - 1; i >= 0; i--) {

                        if (i == itemNum) {
                            itemBullets += '<a alt="" class="dota3" />';
                        }
                        else {
                            itemBullets += '<a alt="" class="dota2" onclick="mainStage_currentItemNum = ' + parseInt(i) + '; mainStage_updateItem(' + tabNum + ', ' + i + ', false);" />';
                        }
                    }

                    itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum - 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum - 1) + ', false);" ></a>';
                    document.getElementById('gallery1leftright').innerHTML = itemBullets;


                    mainStage_activeImage = 1;
                });
            }
            else {
                // run this if it's the first time

                mainStage_currentItemNum2 = itemNum;

                $('#mainStage_image1').css({ opacity: 1.0 });
                $('#mainStage_image2').css({ opacity: 0.0 });

                document.getElementById('mainStage_image1').src = itemImage;

                if (parseInt(itemNum + 1) > parseInt(tabsData[tabNum].length - 1)) {
                    //document.getElementById('mainStage_image2').src = tabsData[tabNum][0][3]; // prepare the next image
                }
                else {
                    //document.getElementById('mainStage_image2').src = tabsData[tabNum][itemNum + 1][3]; // prepare the next image
                }

                if (itemLink != '') { document.getElementById('mainStage_image1').style.cursor = 'pointer'; document.getElementById('mainStage_image1').onclick = function () { window.open(itemLink); }; }
                else { document.getElementById('mainStage_image1').style.cursor = 'arrow'; document.getElementById('mainStage_image1').onclick = function () { }; }


                // paging
                itemBullets = '<a class="dotsright"  style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum + 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum + 1) + ', false);" ></a>';
                for (i = tabsData[tabNum].length - 1; i >= 0; i--) {

                    if (i == itemNum) {
                        itemBullets += '<a alt="" class="dota3" />';
                    }
                    else {
                        itemBullets += '<a alt="" class="dota2" onclick="mainStage_currentItemNum = ' + parseInt(i) + '; mainStage_updateItem(' + tabNum + ', ' + i + ', false);" />';
                    }
                }

                itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum - 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum - 1) + ', false);" ></a>';
                document.getElementById('gallery1leftright').innerHTML = itemBullets;

                mainStage_activeImage = 1;

            }


        }
        else {

            if (!selectRandom) {

                // run this if not the first time

                
                    document.getElementById('mainStage_image2').src = tabsData[tabNum][itemNum][3]; // prepare the previous image                    


                mainStage_currentItemNum2 = itemNum;

                $('#mainStage_image2').css({ opacity: 0.0 }).animate({ opacity: 1.0 }, 1000);
                $('#mainStage_image1').animate({ opacity: 0.0 }, 1000);


                $.when($('#mainStage_image1'), $('#mainStage_image2')).done(function () {

                    document.getElementById('mainStage_image2').src = itemImage;

                    if (parseInt(itemNum + 1) > parseInt(tabsData[tabNum].length - 1)) {
                        //document.getElementById('mainStage_image1').src = tabsData[tabNum][0][3]; // prepare the next image
                    }
                    else {
                        //document.getElementById('mainStage_image1').src = tabsData[tabNum][itemNum + 1][3]; // prepare the next image
                    }

                    if (itemLink != '') { document.getElementById('mainStage_image2').style.cursor = 'pointer'; document.getElementById('mainStage_image2').onclick = function () { window.open(itemLink); }; }
                    else { document.getElementById('mainStage_image2').style.cursor = 'arrow'; document.getElementById('mainStage_image2').onclick = function () { }; }

                    // paging
                    itemBullets = '<a class="dotsright"  style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum + 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum + 1) + ', false);" ></a>';
                    for (i = tabsData[tabNum].length - 1; i >= 0; i--) {

                        if (i == itemNum) {
                            itemBullets += '<a alt="" class="dota3" />';
                        }
                        else {
                            itemBullets += '<a alt="" class="dota2" onclick="mainStage_currentItemNum = ' + parseInt(i) + '; mainStage_updateItem(' + tabNum + ', ' + i + ', false);" />';
                        }
                    }

                    itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum - 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum - 1) + ', false);" ></a>';
                    document.getElementById('gallery1leftright').innerHTML = itemBullets;

                    mainStage_activeImage = 2;
                });
            }
            else {
                // run this if it's the first time

                mainStage_currentItemNum2 = itemNum;

                $('#mainStage_image1').css({ opacity: 1.0 });
                $('#mainStage_image2').css({ opacity: 0.0 });

                document.getElementById('mainStage_image2').src = itemImage;

                if (parseInt(itemNum + 1) > parseInt(tabsData[tabNum].length - 1)) {
                    //document.getElementById('mainStage_image1').src = tabsData[tabNum][0][3]; // prepare the next image
                }
                else {
                    //document.getElementById('mainStage_image1').src = tabsData[tabNum][itemNum + 1][3]; // prepare the next image
                }

                if (itemLink != '') { document.getElementById('mainStage_image2').style.cursor = 'pointer'; document.getElementById('mainStage_image2').onclick = function () { window.open(itemLink); }; }
                else { document.getElementById('mainStage_image2').style.cursor = 'arrow'; document.getElementById('mainStage_image2').onclick = function () { }; }

                // paging
                itemBullets = '<a class="dotsright"  style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum + 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum + 1) + ', false);" ></a>';
                for (i = tabsData[tabNum].length - 1; i >= 0; i--) {

                    if (i == itemNum) {
                        itemBullets += '<a alt="" class="dota3" />';
                    }
                    else {
                        itemBullets += '<a alt="" class="dota2" onclick="mainStage_currentItemNum = ' + parseInt(i) + '; mainStage_updateItem(' + tabNum + ', ' + i + ', false);" />';
                    }
                }

                itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="mainStage_currentItemNum = ' + parseInt(itemNum - 1) + '; mainStage_updateItem(' + tabNum + ', ' + parseInt(itemNum - 1) + ', false);" ></a>';
                document.getElementById('gallery1leftright').innerHTML = itemBullets;

                mainStage_activeImage = 2;
            }

        }


    }
}

var mainStage_openText_isOpen = false;
function mainStage_openText() {
    
    if (!mainStage_openText_isOpen) { document.getElementById('mainStage_text').style.display = ''; mainStage_openText_isOpen = true; document.getElementById('gallery1updown').style.background = 'url(images/gallery1updown2.png) no-repeat'; }
    else { document.getElementById('mainStage_text').style.display = 'none'; mainStage_openText_isOpen = false; document.getElementById('gallery1updown').style.background = 'url(images/gallery1updown.png) no-repeat'; }

}

// **********************************************************************************************
// video stage
// **********************************************************************************************

function videoStage_init() {

    selectedTab = Math.floor(Math.random() * 5) + 1;

    videoStage_selectTab(selectedTab);

}

function videoStage_selectTab(tabNum) {
    videoStage_updateItem(tabNum, "", true);

    document.getElementById(videoStage_tab1).className = 'gallery2';
    document.getElementById(videoStage_tab2).className = 'gallery2';
    document.getElementById(videoStage_tab3).className = 'gallery2';
    document.getElementById(videoStage_tab4).className = 'gallery2';
    document.getElementById(videoStage_tab5).className = 'gallery2';
    document.getElementById(videoStage_tab6).className = 'gallery2';

    if (tabNum == 1) { document.getElementById(videoStage_tab1).className = 'gallery2curr'; }
    if (tabNum == 2) { document.getElementById(videoStage_tab2).className = 'gallery2curr'; }
    if (tabNum == 3) { document.getElementById(videoStage_tab3).className = 'gallery2curr'; }
    if (tabNum == 4) { document.getElementById(videoStage_tab4).className = 'gallery2curr'; }
    if (tabNum == 5) { document.getElementById(videoStage_tab5).className = 'gallery2curr'; }
    if (tabNum == 6) { document.getElementById(videoStage_tab6).className = 'gallery2curr'; }
}

function videoStage_updateItem(tabNum, itemNum, selectRandom) {

    if (!selectRandom) {
        itemNum = 0;
    }
    else {
        // select random item (cancelled for now)
        itemNum = 0;
    }


    // reset stage
    document.getElementById('videoStage_image').src = '';
    document.getElementById('videoIframe').src = '';
    document.getElementById('videoStage_previewImageContainer').style.display = '';
    document.getElementById('videoIframe').style.display = 'none';

    var itemImage;
    if (tabsData_videoStage[tabNum].length > 0) {


        // populate stage
        itemImage = tabsData_videoStage[tabNum][itemNum][0];
        videoPlayerURL = tabsData_videoStage[tabNum][itemNum][1];


        document.getElementById('videoStage_previewImageLink').href = "javascript:playVideo('" + videoPlayerURL + "');";
        document.getElementById('videoStage_image').src = itemImage;

    }
    else {
        document.getElementById('videoStage_previewImageContainer').style.display = 'none';
    }
}

function playVideo(videoPlayerURL) {
    document.getElementById('videoStage_previewImageContainer').style.display = 'none';
    document.getElementById('videoIframe').src = 'http://switch5.castup.net/Customers/WeekendTV/V_512x288/design.asp?as=1&clipurl=' + videoPlayerURL;
    document.getElementById('videoIframe').style.display = '';
}


// **********************************************************************************************
// search categories links
// **********************************************************************************************
function changeSearchCategory(catNum) 
{

    if (searchCategoriesLinks_ARR) 
    {
        if (searchCategoriesLinks_ARR.length > catNum)
        {
            document.getElementById('searchCategoriesLinks').innerHTML = searchCategoriesLinks_ARR[catNum];
        }
    }
    
    // reset selected categories
    for (i = 1; i <= 7; i++) {
        document.getElementById('topmenutab' + i).className = '';
    }
    
    // set selected category
    document.getElementById('topmenutab' + catNum).className = 'currtab';


}




// **********************************************************************************************
// Ads Section 2
// **********************************************************************************************
function adsSection2(pageNum) {

    if (AdsData.length > 0) {

        if (pageNum > (AdsData.length / 4)) { pageNum = 1; }
        if (pageNum < 1) { pageNum = (AdsData.length / 4); }

        // populate ads for current page
        var counter = 0;
        for (i = (pageNum - 1) * 4; counter<4; i++) {

            counter++;
            
            document.getElementById('SelectedZimmers_headline' + counter).innerHTML = AdsData[i][0];
            document.getElementById('SelectedZimmers_headline' + counter).href = AdsData[i][1];

            document.getElementById('SelectedZimmers_link' + counter).href = AdsData[i][1];
            document.getElementById('SelectedZimmers_image' + counter).src = AdsData[i][2];
            document.getElementById('SelectedZimmers_image' + counter).alt = AdsData[i][3];

        }



        itemBullets = '<a class="dotsright" style="cursor:pointer" onclick="adsSection2(' + parseInt(pageNum + 1) + ');" ></a>';
        for (i = (AdsData.length / 4); i >= 1; i--) {
            
            if (i == pageNum) {
                itemBullets += '<img alt="" src="images/a3.png" />';
            }
            else {
                itemBullets += '<img alt="" src="images/a2.png" onclick="adsSection2(' + i + ');" />';
            }
        }

        itemBullets += '<a class="dotsleft" style="cursor:pointer" onclick="adsSection2(' + parseInt(pageNum - 1) + ');" ></a>';

        document.getElementById('SelectedZimmers_paging').innerHTML = itemBullets;
    }

}

function adsData_init() {
    adsSection2(1);
}


/* VIP videos */

function videosVIP_init() {


    var i;
    for (i = 0; i < videosVIP.length; i++) {
        document.getElementById('videosVIP_video_image' + i).src = videosVIP[i][3];
        document.getElementById('videosVIP_video_link' + i).innerHTML = videosVIP[i][1];
        document.getElementById('videosVIP_video_link' + i).href = "javascript:videosVIP_playVideo(" + i + ");";
        document.getElementById('videosVIP_video_play' + i).href = "javascript:videosVIP_playVideo(" + i + ");";
        
    }
    
    
}

function videosVIP_playVideo(itemNum) {

    document.getElementById('videos_modalPage').style.display = '';

    // update main video data
    document.getElementById('videosVIP_mainVideo_customerName').innerHTML = videosVIP[itemNum][0];
    document.getElementById('videosVIP_mainVideo_videoTitle').innerHTML = videosVIP[itemNum][1];
    document.getElementById('videosVIP_mainVideo_player').src = videosVIP[itemNum][4];
    document.getElementById('videosVIP_mainVideo_Homepage').href = videosVIP[itemNum][5];

    document.getElementById('videosVIP_video_frame0').style.display = 'none';
    document.getElementById('videosVIP_video_frame1').style.display = 'none';
    document.getElementById('videosVIP_video_frame2').style.display = 'none';
    document.getElementById('videosVIP_video_frame3').style.display = 'none';

    document.getElementById('videosVIP_video_play0').style.display = '';
    document.getElementById('videosVIP_video_play1').style.display = '';
    document.getElementById('videosVIP_video_play2').style.display = '';
    document.getElementById('videosVIP_video_play3').style.display = '';

    document.getElementById('videosVIP_video_frame' + itemNum).style.display = '';
    document.getElementById('videosVIP_video_play' + itemNum).style.display = 'none';

    



}

function videosVIP_closePopup() {
    document.getElementById('videos_modalPage').style.display = 'none';
    document.getElementById('videosVIP_mainVideo_player').src = '';
}
