var m_aCalendar = new Array();
var m_aChatTexts = new Array();
var m_aDetailedData = new Array();
var m_aEmail = new Array();
var m_aOnlineOperators = new Array();
var m_aOperatorsList = new Array();
var m_aPhone = new Array();
var m_aPhoto = new Array();
var m_aSms = new Array();
var m_aSpotlightData = new Array();
var m_aStatuses = new Array();
var m_aVideo = new Array();
var m_aWebcam = new Array();
var m_aWebshop = new Array();
var m_aImages = new Array();
var m_aProfilePosition = new Array();
var m_aPageCreated = new Array();
var m_aOnlineFreeWebcam = new Array();
var m_aAvailableFreeWebcam = new Array();

var m_bCreatelayout = true;
var m_bDetailedData = false;
var m_bFreeCamLoaded = false;
var m_bPayCamOnline = false;

var m_iOperatorCounter = 0;
var m_iPosition = 0;
var m_iTotalProfilesFrontPage = 8;
var m_iTotalProfilesPages = 20;
var m_iCurrentStartPosition = 0;
var m_iCurrentStopPosition = m_iTotalProfilesFrontPage;
var m_iCurrentIndex = 0;
var m_iSpotlightPosition = 0;

var m_sCallText = ''; 
var m_sDefaultProfilePicture = '/images/layout/no-pic.png';
var m_sImageResizer = '/_assets/resizeImage.php?width=184&height=135&urlPicture=';
var m_sPlayMyVoice = '';
var m_sSystem = 'cry';
var m_sCustomerId = 'dsf098g5';
var m_sSmsKeyWord = 'VAMP';
var m_sSmsNumber = '9695';

$(function (){
    m_aCalendar['StatusText'] = m_aSettings.CalendarStatusText;
    m_aCalendar['Available'] = m_aSettings.CalendarAvailableTitle;
    m_aCalendar['Unavailable'] = m_aSettings.CalendarUnavailableTitle;

    m_aEmail['StatusText'] = m_aSettings.EmailStatusText;
    m_aEmail['Available'] = m_aSettings.EmailAvailableTitle;
    m_aEmail['Unavailable'] = m_aSettings.EmailUnavailableTitle;

    m_aPhone['StatusText'] = m_aSettings.PhoneStatusText;
    m_aPhone['Online'] = m_aSettings.PhoneAvailableTitle;
    m_aPhone['Busy'] = m_aSettings.PhoneBusyTitle;
    m_aPhone['Offline'] = m_aSettings.PhoneUnavailableTitle;

    m_aPhoto['StatusText'] = m_aSettings.PhotoStatusText;
    m_aPhoto['Available'] = m_aSettings.PhotoAvailableTitle;
    m_aPhoto['Unavailable'] = m_aSettings.PhotoUnavailableTitle;

    m_aSms['StatusText'] = m_aSettings.SmsStatusText;
    m_aSms['Available'] = m_aSettings.SmsAvailableTitle;
    m_aSms['Unavailable'] = m_aSettings.SmsUnavailableTitle;
    
    m_aStatuses['Available'] = '/images/layout/available.png';
    m_aStatuses['Busy'] = '/images/layout/busy.png';
    m_aStatuses['Unavailable'] = '/images/layout/unavailable.png';
    m_aStatuses['Online'] = m_aStatuses['Available'];
    m_aStatuses['Offline'] = m_aStatuses['Unavailable'];

    m_aVideo['StatusText'] = m_aSettings.VideoStatusText;
    m_aVideo['Available'] = m_aSettings.VideoAvailableTitle;
    m_aVideo['Unavailable'] = m_aSettings.VideoUnavailableTitle;

    m_aWebcam['StatusText'] = m_aSettings.WebcamStatusText;
    m_aWebcam['Online'] = m_aSettings.WebcamAvailableTitle;
    m_aWebcam['Offline'] = m_aSettings.WebcamUnavailableTitle;

    m_aWebshop['StatusText'] = m_aSettings.WebshopStatusText;
    m_aWebshop['Available'] = m_aSettings.WebshopAvailableTitle;
    m_aWebshop['Unavailable'] = m_aSettings.WebshopUnavailableTitle;
    
    m_sCallText = m_aSettings.CallText;
    m_sPlayMyVoice = m_aSettings.PlayMyVoice;
    m_sPlayTitle = m_aSettings.PlayTitle;
    m_sPauseTitle = m_aSettings.PauseTitle;
    startTimer();
});

function startTimer() {
    startProfiles();
    
    $('#ContentContainer').everyTime(120000, function () { 
        startProfiles();
    });
}

function stopTimer(){
    $('#ContentContainer').stopTime();
}

function startProfiles (){
    var p_sClientcode;
    m_iOperatorCounter = 0
    m_aOnlineOperators = new Array();
    m_aOnlineFreeWebcam = new Array();
    m_aAvailableFreeWebcam = new Array();
    
    loadProfiles();
    
    if(parseInt(m_iPreferedSpotlightOperator) != 0)
        p_sClientcode = m_iPreferedSpotlightOperator;
    else if (m_aAvailableFreeWebcam.length > 0){
        if(m_aOnlineFreeWebcam.length > 0 )
            p_sClientcode = m_aOnlineFreeWebcam[0];
        else 
            p_sClientcode = m_aAvailableFreeWebcam[0];
    } else {
        m_aOnlineOperators = $.shuffle(m_aOnlineOperators);
        p_sClientcode = m_aOnlineOperators[0];
    }

    m_iPreferedSpotlightOperator = p_sClientcode;
    
    loadDetailedData(p_sClientcode);

    if(m_bCreatelayout){
        $('.NavigationList').empty();
        $('#ContentContainer').empty();
        m_bFreeCamLoaded = false;
        
        var p_iPosition = 0;
        var p_iPage = 1;
        var p_bAddPage = true;
        var i;
        
        for(i = 0; i <= m_iOperatorCounter; i++){
            if(p_bAddPage){
                $('<div>').attr('class', 'page').attr('id', 'Page' + p_iPage).appendTo('#ContentContainer');
                $('<li>').html('<a href="#" onfocus="blur()">' + p_iPage + '</a>').appendTo('.NavigationList');
            
                if(p_iPage == 1){
                    $('<div>').attr('id', 'FreeWebcam').appendTo('#Page1');
                    $('<div>').attr('id', 'FreeCam').appendTo('#FreeWebcam');
                    addSpotlight();
                }
                
                m_aPageCreated[i] = false;
                
                p_bAddPage = false;
            }
            
            if((p_iPage == 1 && p_iPosition > m_iTotalProfilesFrontPage - 1) || 
                (p_iPage > 1 && p_iPosition > m_iTotalProfilesPages - 1)) {
                
                p_iPosition = 0;
                p_iPage++;
                p_bAddPage = true;
            }
            
            p_iPosition++;
        }
        
        $('ul.NavigationList').tabs('div.page');
        
        var p_aData = new Array();
        p_aData.addTo = 'Page1';
        p_aData.prefix = '';
        
        for(i = 0; i < m_iTotalProfilesFrontPage; i++){
            p_aData.position = i;
            p_iPosition = i + 1;
            
            if(i != 0 && (i % 4 == 0)) 
                $('<div>').attr('class', 'dummy').appendTo('#' + p_aData.addTo);
            if(m_aProfilePosition[i] != undefined)
                smallProfile(p_aData);
        }
    
        var tapTop = $('#NavigationListTop').data('tabs');
        var tapBottom = $('#NavigationListBottom').data('tabs');

        tapTop.onClick(function(e, index) { 
            $('#NavigationListBottom a.current').removeAttr('class');
            $('#NavigationListBottom a:contains(' + (index + 1) + ')').attr('class', 'current');
            m_iCurrentIndex = index;
            createLayout();
	    overlayHandler();
        })
        
        tapBottom.onClick(function(e, index) {
            $('#NavigationListTop a.current').removeAttr('class');
            $('#NavigationListTop a:contains(' + (index + 1) + ')').attr('class', 'current');
            m_iCurrentIndex = index;
            createLayout();
	    overlayHandler();
        })
       
        m_bCreatelayout = false;
        m_aPageCreated[1] = true;
    }
    
    addProfilesData();
    addSpotlightData();
    setAudioClickHandler(); // from http://www.crystalentertainment.nl/js/soundmanager.js
    overlayHandler();
}

function loadChatTexts() {
    $.ajax({
        data: ({
            action: 'chatTexts'
        }),
        dataType: 'json',
        success: function(data){
            if(data.result == 'ok'){
                m_aChatTexts = data.data;
                var t = '';
                var f = true;
                for(var i = 1; i <= 17; i++){
                    if(!f)
                        t += '<br />';
                    t += m_aChatTexts['chatBodyLine'+i];
                    f = false;
                }
                
                $('#FreeCamHeaderText').html(m_aChatTexts.chatTopLine1 + ' ' + m_aChatTexts.chatTopLine2);
                $('#FreeCamBodyText').html(t);
                
                if(m_bPayCamOnline){
                    $('#FreeCamFooterText').html(m_aChatTexts.chatBottomLine1online + '<br />' + m_aChatTexts.chatBottomLine2online + ' ');
                    $('<a>')
                    .attr('action', 'Webcam')
                    .attr('available', 'Available')
                    .attr('alias', 'Chelly')
                    .attr('clientcode', '928')
                    .attr('href', "#")
                    .attr('id', 'SeeMyMovieLink')
                    .attr('onfocus', 'blur()')
                    .attr('rel', '#Overlay')
                    .attr('status', 'Online')
                    .html('')
                    .appendTo('#FreeCamFooterText');
                }
                else 
                    $('#FreeCamFooterText').html(m_aChatTexts.chatBottomLine1offline + ' ' + m_aChatTexts.chatBottomLine2offline);
            }
        },
        url: '/_assets/data.php'
    });
}

function overlayHandler(){
    $('#SeeMyMovieLink, .statuses, .smallProfileClickField, #SeeMyMoviesText a.ClickHere').overlay({
        mask: '#000',
        fixed: false,
        load: false,
        speed: 'slow',
        fadeInSpeed: 'slow',
        onBeforeLoad : function (){
            var p_sClientcode;
            var p_sAlias;
            var p_sAvailable;
            var p_sStatus;
            var p_sHref;
            var p_sAction;
            
            $('#OverlayContent').empty();
            stopTimer();

            soundManager.stopAll();
            
            p_sClientcode = this.getTrigger().attr('clientcode');
            p_sAvailable = this.getTrigger().attr('available');
            p_sStatus = this.getTrigger().attr('status');
            p_sAlias = this.getTrigger().attr('alias');
            p_sAction = this.getTrigger().attr('action');

            _gaq.push(['_trackEvent', 'Operators', p_sClientcode, p_sAction]);
            
            switch(p_sAction){
                case 'Calendar':
                    _gaq.push(['_trackEvent', 'Calendar', p_sClientcode]);
                    p_sHref = m_aSettings.sourceUrl + '/pages/is/index.php?type=1&system=' + m_sSystem + '&customerid=' + m_sCustomerId;
                    iframeOverlay(p_sAlias, p_sHref, p_sAvailable);
                    break;
                case 'Email':
                    _gaq.push(['_trackEvent', 'Email', p_sClientcode]);
                    p_sHref = m_aSettings.sourceUrl + '/messages/index.php?clientcode=' + p_sClientcode + '&system=' + m_sSystem + '&customerid=' + m_sCustomerId
                    iframeOverlay(p_sAlias, p_sHref, p_sAvailable);
                    break;
                case 'Phone':
                    phoneOverlay(p_sClientcode);
                    break;
                case 'Photo':
                    photoOverlay(p_sClientcode, p_sAlias, p_sAvailable);
                    break;
                case 'Sms':
                    smsOverlay(p_sClientcode, p_sAlias, p_sAvailable);
                    break;
                case 'Video':
                    videoOverlay(p_sClientcode, p_sAlias, p_sAvailable);
                    break;
                case 'Webcam':
                    webcamOverlay(p_sClientcode, p_sAlias, p_sAvailable, p_sStatus);
                    break;
                case 'Webshop':
                    webshopOverlay(p_sClientcode, p_sAlias, p_sAvailable, p_sStatus);
                    break;
                case 'makemovie':
                    sendEmailOverlay();
                    break;
            }
        },
        onBeforeClose: function (){
            m_bDetaildData = false;
            soundManager.stopAll();
            
            switch(this.getTrigger().attr('action')){
                case 'Calendar':
                    $('#OverlayContent').empty();
                    var p_sAvailable = this.getTrigger().attr('available');
                    
                    if(p_sAvailable == 'Available'){
                        var p_sHref = m_aSettings.sourceUrl + '/pages/is/index.php?action=logoff';
                    
                        iframeOverlay('', p_sHref, 'Available');
                    }
                    break;
                case 'Video':
                    $('#playMovie').empty();

                    break;
            }
        }, 
        onClose: function (){
            startTimer();
        }
    });
}

function sendEmailOverlay(){
    $('#Overlay').css('width', '400px').css('height', '120px');
    $('<div>').attr('id', 'InfoAboutFilmText').text('meer info vul dan onderstaande informatie in u krijgt dan spoedig een email terug').appendTo('#OverlayContent');
    $('<div>').attr('id', 'sendEmailName').appendTo('#OverlayContent');
    $('<div>').attr('id', 'sendEmailNameLabel').attr('class', 'labels').html('Naam :&nbsp;').appendTo('#sendEmailName')
    $('<div>').attr('id', 'sendEmailNameInput').attr('class', 'inputs').appendTo('#sendEmailName');
    $('<input>').attr('id', 'sendEmailInputName').attr('name', 'name').attr('type', 'text').appendTo('#sendEmailNameInput');
    $('<div>').attr('id', 'sendEmailEmail').appendTo('#OverlayContent');
    $('<div>').attr('id', 'sendEmailEmailLabel').attr('class', 'labels').html('Email :&nbsp;').appendTo('#sendEmailEmail');
    $('<div>').attr('id', 'sendEmailEmailInput').attr('class', 'inputs').appendTo('#sendEmailEmail');
    $('<input>').attr('id', 'sendEmailInputEmail').attr('name', 'emailaddress').attr('type', 'text').appendTo('#sendEmailEmailInput');
    $('<input>').attr('id', 'sendEmail').attr('type', 'button').attr('value', 'versturen').appendTo('#OverlayContent');
    
    $('#sendEmail').click(function(){
        var p_sName = $('#sendEmailInputName').attr('value');
        var p_sEmail = $('#sendEmailInputEmail').attr('value');
        $.ajax({
            async: true,
            data: {
                action: 'sendEmail',
                name: p_sName,
                email: p_sEmail
            },
            success: function (data){
                if(data.result == 'ok')
                    alert('verzonden');
                else 
                    alert('er is iets mis gegaan');
            },
            url: '/_assets/data.php'
        });
        
        $('.close').click();
    });
}

function webshopOverlay(){
    $('#Overlay').css('width', '300px').css('height', '50px');
    $('<div>').attr('id', 'smsContainer').html('Helaas is deze functie nog niet beschikbaar').appendTo('#OverlayContent');
}

function videoOverlay(p_sClientcode, p_sAlias, p_sAvailable){
    _gaq.push(['_trackEvent', 'Video', p_sClientcode]);
    
    if(p_sAvailable == 'Available'){
        var p_aData = new Array();
        p_aData.appendTo = '#playMovie';
        p_aData.name = 'VideoStreams';
        p_aData.height = 225;
        p_aData.width = 400;
        
        $('#Overlay').css('width', '601px').css('height', '602px');
        $('<div>').attr('id', 'smsContainer').html('Klik op de foto om het filmpje te bekijken de foto&#39;s met de ster zijn gratis de overige zijn betaalde filmpjes.<br />\n\
Na het klikken op een betaalde filmpje belt u het nummer achter (phonenumber).<br />\n\
en toetst u de pincode in wanneer daarom word gevraagd.').appendTo('#OverlayContent');
        $('<div>').attr('id', 'playMovie').appendTo('#OverlayContent');
        $('<div>').attr('id', 'MoviesContainer').appendTo('#OverlayContent');
        
        $.ajax({
            data: ({
                agent_id: p_sClientcode
            }),
            dataType: 'xml',
            success: function(data) {
                var p_sFreeImagePath, p_sPaidImagePath, p_sPaidMovieId;
                var p_bFirstFree, p_bFirstPaid;
                var i, j
                var k = 0;
                var p_iWriteone;
               
                for(i = 1; ;i++){
                    if(i > 10) break;
                    k++;
                    
                    p_bFirstFree = true;
                    p_bFirstPaid = true;
                    p_sFreeImagePath = $(data).find('free_video_path_' + i).text();
                    
                    if(p_sFreeImagePath != ''){
                        p_bFirstFree = false;
                        
                        $('<div>').attr('class', 'Movies').attr('id', 'Movies' + k).appendTo('#MoviesContainer');
                        $('<div>').attr('class', 'FreeMovie').attr('id', 'FreeMovie' + k).attr('movieid', p_sClientcode + '_' + i).css('background-image', 'url('+ m_aSettings.sourceUrl + '/' + p_sFreeImagePath + ')').appendTo('#Movies' + k);
                        $('<div>').attr('class', 'FreeMovieStar').attr('id', 'FreeMovieStar' + k).appendTo('#FreeMovie' + k);
                        $('<div>').attr('class', 'FreeMovieFreeText').attr('id', 'FreeMovieFreeText' + k).text('GRATIS').appendTo('#FreeMovieStar' + k);
                        $('<div>').attr('class', 'FreeMovieText').attr('id', 'FreeMovieText' + k).text('Film').appendTo('#FreeMovieStar' + k);
                        $('<div>').attr('class', 'FreeMovieFilmRoll').attr('id', 'FreeMovieFilmRoll' + k).appendTo('#FreeMovieStar' + k);
                        
                        for(j = 1; ;j++){
                            p_sPaidImagePath = $(data).find('paid_video_path_' + j).text();
                            p_sPaidMovieId = $(data).find('paid_video_id_' + j).text();
                            p_iWriteone = p_sPaidImagePath.indexOf(p_sClientcode + '_' + i)

                            if(p_sPaidImagePath != ''){
                                if(p_iWriteone > 0){ 
                                    if(p_bFirstFree && p_bFirstPaid) {
                                        k++;
                                        $('<div>').attr('class', 'Movies').attr('id', 'Movies' + k).appendTo('#MoviesContainer');
                                        $('<div>').attr('class', 'FreeMovie').attr('id', 'FreeMovie' + k).appendTo('#Movies' + k);
                                    }

                                    $('<div>').attr('class', 'PaidMovie').attr('id', 'PaidMovie_' + k + '_' + j).attr('movieid', p_sPaidMovieId).css('background-image', 'url('+ m_aSettings.sourceUrl + '/' + p_sPaidImagePath + ')').appendTo('#Movies' + k);
                                
                                    if(p_bFirstPaid){
                                        p_bFirstPaid = false;
                                        p_bFirstFree = false;
                                    } else {
                                        p_bFirstPaid = true;
                                        p_bFirstFree = true;
                                    }
                                }
                            } else break;
                        }
                    } else break;
                }
            },
            url: '/_assets/proxy.php'            
        });
        
        $('.FreeMovie, .PaidMovie').click(function(){
            var p_sMovieId = $(this).attr('movieid');
            var p_sFilename;
            var p_sApplication;
            
            $('#playMovie').empty();
            
            _gaq.push(['_trackEvent', 'Video', p_sClientcode], p_sMovieId);
            
            if($(this).attr('class') == 'FreeMovie'){
                p_sFilename = m_aSettings.sourceUrl + '/swf/trailer.swf';
                p_sApplication = 'erotrailers';
            }
            
            if($(this).attr('class') == 'PaidMovie'){
                p_sFilename = m_aSettings.sourceUrl + '/swf/VideoStream.swf';
                p_sApplication = 'VideoStreams';
            }
            
            
            flashembed('playMovie', {
                src: p_sFilename,
                width: 400,
                height: 225,
                wmode: 'transparent'
            
            }, {
                application: p_sApplication,
                country: 'Netherlands',
                customerid: m_sCustomerId,
                fmshost: m_aSettings.sourceUrl.substr(7),
                operatorid: p_sMovieId,
                movieid: p_sMovieId,
                phphost: 'scripts.crystalentertainment.nl'
            });
        });
    } else {
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas heeft ' + p_sAlias + ' geen filmpjes beschikbaar gesteld').appendTo('#OverlayContent');
    }
}

function photoOverlay(p_sClientcode, p_sAlias, p_sAvailable){
    _gaq.push(['_trackEvent', 'Photo', p_sClientcode]);
    
    if(p_sAvailable == 'Available'){
        var p_sApplication = 'photoGallery';
        var p_sFilename = m_aSettings.sourceUrl + '/swf/photoGallery.swf';
        
        $('#Overlay').css('width', '955px').css('height', '672px');
        $('<div>').attr('id', 'smsContainer').html('Bel onderstaande nummer(phonenumber)<br /> Toets wanneer daar om word gevraagt de onderstaande pincode in<br />Klik vervolgens op de foto&#39;s').appendTo('#OverlayContent');
        $('<div>').attr('id', 'photoContent').appendTo('#OverlayContent');

        flashembed('photoContent', {
            src: p_sFilename,
            width: 955,
            height: 600,
            wmode: 'transparent'
            
        }, {
            application: p_sApplication,
            country: 'Netherlands',
            customerid: m_sCustomerId,
            fmshost: m_aSettings.sourceUrl.substr(7),
            operatorid: p_sClientcode,
            phphost: 'scripts.crystalentertainment.nl'
        });
    } else {
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas heeft ' + p_sAlias + ' geen foto&#39;s beschikbaar gesteld').appendTo('#OverlayContent');
    }
}

function webcamOverlay(p_sClientcode, p_sAlias, p_sAvailable, p_sStatus){
    _gaq.push(['_trackEvent', 'Webcam', p_sClientcode]);

    if(p_sAvailable == 'Available' && p_sStatus == 'Online'){
        $('#Overlay').css('width', '800px').css('height', '672px');
        $('<div>').attr('id', 'smsContainer').html('Vul eventueel een naam in bij Nickname<br />Bel onderstaande nummer(phonenumber)<br /> Toets wanneer daar om word gevraagt de onderstaande pincode in').appendTo('#OverlayContent');
        $('<div>').attr('id', 'webcamContainer').appendTo('#OverlayContent');
        
        flashembed('webcamContainer', {
            src: m_aSettings.sourceUrl + '/swf/ChatVisitor.swf',
            width: 800,
            height: 600,
            wmode: 'transparent'
            
        }, {
            application: 'videochat',
            channelid: 'channel1',
            country: 'Netherlands',
            customerid: m_sCustomerId,
            fmshost: m_aSettings.sourceUrl.substr(7),
            operatorid: p_sClientcode,
            phphost: 'chat.crystalentertainment.nl',
            system: m_sSystem
        });

    } else if(p_sAvailable == 'Available' && p_sStatus == 'Offline'){
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas is ' + p_sAlias + ' op dit moment niet beschikbaar Webcammen').appendTo('#OverlayContent');
    } else {
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas heeft ' + p_sAlias + ' niet aagegeven dat ze wil Webcammen').appendTo('#OverlayContent');
    }
}

function smsOverlay(p_sClientcode, p_sAlias, p_sAvailable){
    _gaq.push(['_trackEvent', 'Sms', p_sClientcode]);
    
    if(p_sAvailable == 'Available'){
        $('#Overlay').css('width', '600px').css('height', '410px');
        $('<div>').attr('id', 'smsContainer').appendTo('#OverlayContent');
        $('<div>').attr('id', 'smsInstructions').html('<img src="http://www.crystalentertainment.nl/images/SMS/eenmalig_200_chat.jpg" align="right" />\n\
SMS: <b><span id="smsKeyword" class="smsSendText">' + m_sSmsKeyWord + '</span> (spatie) <span id="smsClientcode" class="smsSendText">' + p_sClientcode + 
            '</span> (dan het bericht) aan <span id="smsNumber" class="smsSendText">' + m_sSmsNumber + '</span></b><br />\n\
<br /><span id="smsName">' + p_sAlias + '</span> zal je dan een sms terugsturen!<br />\n\
Het persoonlijke nummer is direct aan de bijbehorende persoon gekoppeld!<br />\n\
Niemand anders zal het smsje beantwoorden.<br /><br />').appendTo('#smsContainer');
    
        $('<div>').attr('id', 'smsStopInfo').html('Stoppen: stuur STOP, bel 0900-6623375 info www.mobdesk.com of smsgedragscode.nl of services@mobdesk.com<br /><br /><br />').appendTo('#smsContainer');
        $('<div>').attr('id', 'smsDesclaimer').html('Geen fysieke afspraken mogelijk - fictieve profielen.<br />\n\
(De vorige zin moeten we verplicht vermelden. Anders dan veel aanbieders van sms diensten, worden alle sms-jes hier ook echt door de dame waaraan je de sms stuurt beantwoordt.\n\
Als beheerder van deze dienst/website (Crystal Entertainment) weten wij dus niet of de dame wel of niet afspraakjes maakt.\n\
Dit is iets tussen de dame en de persoon die haar sms&rsquo;t.<br />\n\
Wij weten niet wat voor foto&rsquo;s de dames uploaden voor op de site,\n\
maar in ieder geval een groot deel stuurt eigen foto&rsquo;s,\n\
en velen zijn ook op prive-film danwel webcam te zien.\n\
Wettelijk zijn we echter verplicht te melden dat ook deze profielen &rsquo;fictief&rsquo;\n\ zijn.)').appendTo('#smsContainer');
    } else {
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas heeft ' + p_sAlias + ' niet aagegeven dat ze SMSjes wil ontvangen en beantwoorden').appendTo('#OverlayContent');
    }
}

function iframeOverlay(p_sAlias, p_sHref, p_sAvailable) {
    if(p_sAvailable == 'Available'){
        $('#Overlay').css('width', '750px').css('height', '560px');
        $('<iframe>').attr('id', 'Iframe').css('background-color', '#FFF').attr('src', p_sHref).appendTo('#OverlayContent');
    } else {
        $('#Overlay').css('width', '300px').css('height', '50px');
        $('<div>').attr('id', 'smsContainer').html('Helaas heeft ' + p_sAlias + ' deze optie niet aangezet').appendTo('#OverlayContent');
    }
}

function phoneOverlay (p_sClientcode){
    _gaq.push(['_trackEvent', 'Phone', p_sClientcode]);
    
    $('#Overlay').css('height', '553px');
    
    loadDetailedData(p_sClientcode);
    bigProfile(p_sClientcode);

    var p_iPhoto = m_aOperatorsList[p_sClientcode].paidPhotos;
    var p_iVideo = m_aOperatorsList[p_sClientcode].paidVideos;
    var p_bPhoto = false;
    var p_sFilename = m_aSettings.sourceUrl + '/images/operators/erotiek/' + p_sClientcode + '/' + p_sClientcode + '_1.jpg';

    $.ajax({
        data: ({
            filename: p_sFilename
        }),
        dataType: 'json',
        error: function(event, request, settings){
            alert('Event: ' + event + '\nRequest: ' + request + '\nSettings: ' + settings)
        },
        success: function(data){
            if(data.file == 'found') {
                p_bPhoto = true;
            }
        },
        url: '/_assets/file_exists.php'
    });
    
    if(p_iVideo > 0 && p_bPhoto) {
        $('#Overlay').css('width', '812px');
        $('#bigProfileContainer').css('width', '812px');
        $('#bigProfileBg').css('width', '793px');
        $('#bigProfileHeaderPhotoVideo').show();
        $('#bigProfileVideoPhoto').show();
        $('#bigProfileTextPhotoVideo').show();
    } else if(p_iVideo > 0 && !p_bPhoto){
        $('#Overlay').css('width', '812px');
        $('#bigProfileContainer').css('width', '812px');
        $('#bigProfileBg').css('width', '793px');
        $('#bigProfileHeaderPhotoVideo').show();
        $('#bigProfileVideoPhoto').show();
        $('#bigProfileTextPhotoVideo').show();
    } else if(p_iVideo < 1 && p_bPhoto){
        $('#Overlay').css('width', '812px');
        $('#bigProfileContainer').css('width', '812px');
        $('#bigProfileBg').css('width', '793px');
        $('#bigProfileHeaderPhotoVideo').show();
        $('#bigProfileVideoPhoto').show();
        $('#bigProfileTextPhotoVideo').show();
    } else {
        $('#Overlay').css('width', '527px');
        $('#bigProfileContainer').css('width', '527px');
        $('#bigProfileBg').css('width', '507px');
        $('#bigProfileHeaderPhotoVideo').hide();
        $('#bigProfileVideoPhoto').hide();
        $('#bigProfileTextPhotoVideo').hide();
    }
                        
    if(p_iVideo > 0 ) {
        $('#bigProfileVideo').show();
        
        flashembed('bigProfileVideo', {
            src: m_aSettings.sourceUrl + '/swf/trailer.swf',
            width: 266,
            height: 166,
            wmode: 'transparent'
            
        }, {
            application: 'erotrailers',
            channelid: 'channel1',
            country: 'Netherlands',
            customerid: m_sCustomerId,
            fmshost: m_aSettings.sourceUrl.substr(7),
            operatorid: p_sClientcode + '_1',
            phphost: 'chat.crystalentertainment.nl',
            system: m_sSystem
        });
    } else {
        $('#bigProfileVideo').hide();
    }
                        
    if(p_bPhoto){
        $('#bigProfilePhoto').show();
        $('<img>').attr('class', 'PreviewPhoto').attr('src', p_sFilename).appendTo('#bigProfilePhoto');
        $('.bigProfilePhotoThumb').show();
        $('.bigProfileDummy').show();
        
        for(var i = 1; i <= 3 ; i++){
            $('<a>').attr('id', 'preview' + i).attr('href', m_aSettings.sourceUrl + '/images/operators/erotiek/' + p_sClientcode + '/' + p_sClientcode + '_' + i + '.jpg').attr('onclick', 'blur()').appendTo('#bigProfilePhotoThumb' + i);
            $('<img>').attr('src', m_aSettings.sourceUrl + '/images/operators/erotiek/' + p_sClientcode + '/' + p_sClientcode + '_' + i + '_thm.jpg').attr('border','0').attr('class', 'Photothumb').appendTo('#preview' + i);
        }
        
        $('a:has(img.Photothumb)').click(function() {
            var path = $(this).attr('href');
            $('img.PreviewPhoto').attr({
                src: path
            });
            return false;
        });
    } else {
        $('#bigProfilePhoto').hide();
        $('.bigProfilePhotoThumb').hide();
        $('.bigProfileDummy').hide();
    }
    
    $('#bigProfile_smallProfileInfo_').empty();
}

function createLayout(){
    var p_iPage = m_iCurrentIndex + 1;

    if(!m_aPageCreated[p_iPage]){
        m_aPageCreated[p_iPage] = true;
        var i;
        var p_aData = new Array();
        var p_iLineCounter = 1;
        p_aData.addTo = 'Page' + p_iPage;
        p_aData.prefix = '';
        
        if(m_iCurrentIndex > 0){
            m_iCurrentStartPosition = ((m_iCurrentIndex - 1) * 20) + 1 + m_iTotalProfilesFrontPage;
            m_iCurrentStopPosition = m_iCurrentStartPosition + m_iTotalProfilesPages;

            for(i = m_iCurrentStartPosition; i < m_iCurrentStopPosition && i < m_iOperatorCounter; i++){
                if(p_iLineCounter == 5){
                    $('<div>').attr('class', 'dummy').appendTo('#' + p_aData.addTo);
                    p_iLineCounter = 1;
                }
                
                p_aData.position = i;
                smallProfile(p_aData);
                addProfileData(i, false, '');
                
                p_iLineCounter++;
            }
        }    
    }
}

function loadProfiles(){
    m_iOperatorCounter = 0;
    m_aOperatorsList = new Array();
    var p_bLoadProfile = false;
    
    $.ajax({
        data: ({
            category: m_sCategory
        }),
        dataType: 'xml',
        error: function(event, request, settings){
            alert('Event: ' + event + '\nRequest: ' + request + '\nSettings: ' + settings)
        },
        success: function (data){
            m_aProfilePosition = new Array();
            
            $(data).find('agent').each(function (){
                var p_sClientcode = $(this).find('clientcode').text()
                var p_iCategory = parseInt($(this).find('category').text());
                
                if((p_iCategory & m_iCategory) == m_iCategory){
                    p_bLoadProfile = false;
                    
                    var p_iPaidPhotos = parseInt($(this).find('paid_photo_count').text());
                    var p_iPaidVideos = parseInt($(this).find('paid_video_count').text())

                    var p_sCalendarAvailable = $(this).find('calendarAvailable').text();
                    var p_sEmailStatus = $(this).find('emailStatus').text();
                    var p_sPhoneStatus = $(this).find('phoneStatus').text();
                    var p_sShopAvailable = $(this).find('shopAvailable').text();
                    var p_sSmsStatus = $(this).find('smsStatus').text();
                    var p_sWebcamStatus = $(this).find('webcamStatus').text();
                
                    if(m_sSystemFilter == 'All' ||
                        (m_sSystemFilter == 'Photo' && p_iPaidPhotos > 0 ) || 
                        (m_sSystemFilter == 'Video' && p_iPaidVideos > 0) || 
                        (m_sSystemFilter == 'Email' && p_sEmailStatus == 'Available') ||
                        (m_sSystemFilter == 'Calendar' && p_sCalendarAvailable == 'Available') ||
                        (m_sSystemFilter == 'Phone' && p_sPhoneStatus == 'Online') ||
                        (m_sSystemFilter == 'Sms' && p_sSmsStatus == 'Available') ||
                        (m_sSystemFilter == 'Webshop' && p_sShopAvailable == 'Available') ||
                        (m_sSystemFilter == 'Webcam' && p_sWebcamStatus == 'Online'))
                        p_bLoadProfile = true;

                    if(p_bLoadProfile){
                        var p_sAge = $(this).find('age').text();
                        var p_sAlias = $(this).find('alias').text();
                        var p_sDescription = $(this).find('description').text();
                        var p_sFreeWebcamStatus = $(this).find('freeWebcamStatus').text();
                        var p_sFreeWebcamAvailable = $(this).find('freeWebcamAvailable').text();
                        var p_sImage = $(this).find('pic1').text();
                        var p_sLocation = $(this).find('location').text();
                        var p_sFreeVideos = $(this).find('free_video_count').text();
                        var p_sWebcamAvailable = $(this).find('webcamAvailable').text();
                    
                        if(p_sPhoneStatus == 'Online' || p_sWebcamStatus == 'Online')
                            m_aOnlineOperators.push(p_sClientcode);
                        
                        if(p_sFreeWebcamAvailable == 'Available'){
                            if(p_sFreeWebcamStatus == 'Online')
                                m_aOnlineFreeWebcam.push(p_sClientcode);
                            
                            m_aAvailableFreeWebcam.push(p_sClientcode);
                        }
                        
                    
                        m_aOperatorsList[p_sClientcode] = new Array();
                        m_aOperatorsList[p_sClientcode].age = p_sAge;
                        m_aOperatorsList[p_sClientcode].alias = p_sAlias;
                        m_aOperatorsList[p_sClientcode].calendarStatus = p_sCalendarAvailable;
                        m_aOperatorsList[p_sClientcode].category = p_iCategory;
                        m_aOperatorsList[p_sClientcode].clientcode = p_sClientcode;
                        m_aOperatorsList[p_sClientcode].description = p_sDescription;
                        m_aOperatorsList[p_sClientcode].emailStatus = p_sEmailStatus;
                        m_aOperatorsList[p_sClientcode].freeVideos = p_sFreeVideos;
                        m_aOperatorsList[p_sClientcode].freeWebcamStatus = p_sFreeWebcamStatus;
                        if(p_sImage != '')
                            m_aOperatorsList[p_sClientcode].image = m_sImageResizer + m_aSettings.sourceUrl + '/' + p_sImage;
                        else 
                            m_aOperatorsList[p_sClientcode].image = m_sDefaultProfilePicture;
                        m_aOperatorsList[p_sClientcode].location = p_sLocation;
                        m_aOperatorsList[p_sClientcode].phoneStatus = p_sPhoneStatus;
                        m_aOperatorsList[p_sClientcode].webshopStatus = p_sShopAvailable;
                        m_aOperatorsList[p_sClientcode].smsStatus = p_sSmsStatus;
                        m_aOperatorsList[p_sClientcode].paidPhotos = p_iPaidPhotos;
                        m_aOperatorsList[p_sClientcode].paidVideos = p_iPaidVideos;
                        m_aOperatorsList[p_sClientcode].webcamAvailable = p_sWebcamAvailable;
                        m_aOperatorsList[p_sClientcode].webcamStatus = p_sWebcamStatus;
          
                        m_aProfilePosition.push(p_sClientcode);
                    
                        m_iOperatorCounter++;
                    }
                }
            });
        },
        url: '/_assets/proxy.php'
    }); 
}

function bigProfile(p_sClientcode){
    var p_aData = new Array();
    p_aData.addTo = 'bigSmallProfile';
    p_aData.prefix = 'bigProfile_';
    p_aData.position = 1;
    
    var p_aPreferences;
    
    var p_sAlias = m_aOperatorsList[p_sClientcode].alias;
    var p_iPhoto = m_aOperatorsList[p_sClientcode].paidPhotos;
    var p_iVideo = m_aOperatorsList[p_sClientcode].paidVideos;
    var p_iAge = m_aOperatorsList[p_sClientcode].age;
    var p_sHairColor = m_aOperatorsList[p_sClientcode].hairColor;
    var p_sCupsize = m_aOperatorsList[p_sClientcode].cupsize;
    var p_sFigure = m_aOperatorsList[p_sClientcode].figure;
    var p_sCity = m_aOperatorsList[p_sClientcode].location;
    var p_sDesciption = m_aOperatorsList[p_sClientcode].longDescription;
    var p_iPreferences = m_aOperatorsList[p_sClientcode].preferences;
    var p_sImage = m_aOperatorsList[p_sClientcode].image;

    $('<div>').attr('id', 'bigProfileContainer').appendTo('#OverlayContent');
    $('<div>').attr('id', 'bigProfileBg').appendTo('#bigProfileContainer');
    $('<div>').attr('id', 'bigProfileHeaderPhotoVideo').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfileLabelPhotoVideo').html('Foto/Video').appendTo('#bigProfileHeaderPhotoVideo');
    $('<div>').attr('id', 'bigProfileTextPhotoVideo').html('Mijn foto&#39;s <span color="#8c8c8b">(' + p_iPhoto + ')</span> | Mijn films <span color="#8c8c8b">(' + p_iVideo + ')</span>').appendTo('#bigProfileHeaderPhotoVideo');
    $('<div>').attr('id', 'bigProfileOf').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfileOfText').html('PROFIEL VAN:').appendTo('#bigProfileOf');
    $('<div>').attr('id', 'bigProfileName').html(p_sAlias + ', ' + p_iAge + ' jaar').appendTo('#bigProfileOf');
    $('<div>').attr('id', 'bigProfileRating').appendTo('#bigProfileOf');
    $('<div>').attr('id', 'bigProfileVideoPhoto').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfileVideo').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfilePhoto').css('background-image', '').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfilePhotoThumb1').attr('class', 'bigProfilePhotoThumb').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfileDummy1').attr('class', 'bigProfileDummy').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfilePhotoThumb2').attr('class', 'bigProfilePhotoThumb').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfileDummy2').attr('class', 'bigProfileDummy').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigProfilePhotoThumb3').attr('class', 'bigProfilePhotoThumb').appendTo('#bigProfileVideoPhoto');
    $('<div>').attr('id', 'bigSmallProfile').appendTo('#bigProfileBg');
    smallProfile(p_aData);
    $('<div>').attr('id', 'bigProfileInfo').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfileTitle').html('Info').appendTo('#bigProfileInfo');
    $('<div>').attr('id', 'bigProfileDescriptionLabel').html('Beschrijving:').appendTo('#bigProfileInfo');
    $('<div>').attr('id', 'bigProfileDescritpionText').html(p_sDesciption).appendTo('#bigProfileInfo');
    $('<div>').attr('id', 'bigProfileCallMe').appendTo('#bigProfileInfo');
    $('<div>').attr('id', 'bigProfileCallMeTeaser').html('Voor een heet gesprekje').appendTo('#bigProfileCallMe');
    $('<div>').attr('id', 'bigProfileCallMeText').html('BEL MIJ NU!').appendTo('#bigProfileCallMe');
    $('<div>').attr('id', 'bigProfileCallMePhone').html(m_aSettings.phonenumber + '<span style="font-size: 12px"> ' + m_aSettings.price + '</span>').appendTo('#bigProfileCallMe');
    $('<div>').attr('id', 'bigProfileAboutMe').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfileAboutMeLabel').html('Over Mij').appendTo('#bigProfileAboutMe');
    $('<div>').attr('id', 'bigProfilePersonalInfoLabel').html('Persoonlijke Informatie:').appendTo('#bigProfileAboutMe');
    $('<div>').attr('id', 'bigProfilePersonalInfoText').html('Leeftijd: ' + p_iAge + ' jaar<br />Haarkleur: ' + p_sHairColor + '<br />Cup maat: ' + p_sCupsize + '<br />Lichaamsbouw: ' + p_sFigure + '<br />Regio: ' + p_sCity).appendTo('#bigProfileAboutMe');
    $('<div>').attr('id', 'bigProfilePreferences').appendTo('#bigProfileBg');
    $('<div>').attr('id', 'bigProfilePreferencesLabel').html('Voorkeuren:').appendTo('#bigProfilePreferences');
    $('<div>').attr('id', 'bigProfilePreferencesILikeLabel').html('Ik hou van:').appendTo('#bigProfilePreferences');
    $('<div>').attr('id', 'bigProfilePreferencesList').appendTo('#bigProfilePreferences');
    p_aPreferences = preferences(p_iPreferences);
    
    var p = 0;
    for(var i in p_aPreferences){
        if (i > 11) break;
        
        if(i == 0 || i == 6){
            p++;
            $('<div>').attr('id', 'bigProfilePreferencesList' + p).attr('class', 'bigProfilePreferencesList').appendTo('#bigProfilePreferencesList');
            $('<ul>').attr('id', 'bigProfilePreferencesListUl' + p).attr('class', 'bigProfilePreferencesListUl').appendTo('#bigProfilePreferencesList' + p)
        }
        
        $('<li>').text(p_aPreferences[i]).appendTo('#bigProfilePreferencesListUl' + p)
    }

    for(var i in m_aProfilePosition){
        if(m_aProfilePosition[i] == p_sClientcode){
            p_iPositionDetails = i;
            break;
        }
    }
    
    addProfileData(p_iPositionDetails, true, p_aData.prefix, 1); 
    
    if(p_sImage != '') 
        $('#' + p_aData.prefix + 'smallProfilePhoto_').css('background-image', 'url(' + m_sImageResizer + m_aSettings.sourceUrl + '/' + p_sImage + ')');
    else 
        $('#' + p_aData.prefix + 'smallProfilePhoto_').css('background-image', 'url(' + m_sDefaultProfilePicture + ')');
}

function smallProfile(p_aData){ 
    var p = p_aData.position;
    var p_sAddTo = '#' + p_aData.addTo;
    var p_sPrefix = p_aData.prefix;

    $('<div>').attr('class', 'smallProfile').attr('id', p_sPrefix + 'smallProfile_' + p).appendTo(p_sAddTo);
            
    $('<div>').attr('class', 'onlineStatusLayer1').attr('id', p_sPrefix + 'onlineStatusLayer1_' + p).appendTo('#' + p_sPrefix + 'smallProfile_' + p);
    $('<div>').attr('class', 'offlineStatusLayer2').attr('id', p_sPrefix + 'onlineStatusLayer2_' + p).appendTo('#' + p_sPrefix + 'onlineStatusLayer1_' + p);
    $('<div>').attr('class', 'offlineStatusLayer3').attr('id', p_sPrefix + 'onlineStatusLayer3_' + p).appendTo('#' + p_sPrefix + 'onlineStatusLayer2_' + p);
    $('<div>').attr('class', 'offlineStatusLayer4').attr('id', p_sPrefix + 'onlineStatusLayer4_' + p).appendTo('#' + p_sPrefix + 'onlineStatusLayer3_' + p);
    $('<div>').attr('class', 'offlineStatusLayer5').attr('id', p_sPrefix + 'onlineStatusLayer5_' + p).appendTo('#' + p_sPrefix + 'onlineStatusLayer4_' + p);
    $('<div>').attr('class', 'onlinestatusLabel').attr('id', p_sPrefix + 'onlineStatusLabel_' + p).text('Live').appendTo('#' + p_sPrefix + 'onlineStatusLayer5_' + p);
    
    $('<div>').attr('class', 'smallProfileOf').attr('id', p_sPrefix + 'smallProfileOf_' + p).appendTo('#' + p_sPrefix + 'smallProfile_' + p);
            
    $('<div>').attr('class', 'smallProfileInfo').attr('id', p_sPrefix + 'smallProfileInfo_' + p).attr('title', m_aSettings.ProfileInfoText).html('i').appendTo('#' + p_sPrefix + 'smallProfile_' + p);
                
    $('<div>').attr('class', 'smallProfilePhoto').attr('id', p_sPrefix + 'smallProfilePhoto_' + p).appendTo('#' + p_sPrefix + 'smallProfile_' + p);
    $('<div>').attr('class', 'smallProfileClickField').attr('id', p_sPrefix + 'smallProfileClickField_' + p).attr('rel', '#Overlay').attr('action', 'Phone').appendTo('#' + p_sPrefix + 'smallProfilePhoto_' + p);
    $('<div>').attr('class', 'smallProfileAudioControl').attr('id', p_sPrefix + 'smallProfileAudioControl_' + p).appendTo('#' + p_sPrefix + 'smallProfilePhoto_' + p);
    $('<div>').attr('class', 'smallProfilePlayMyVoice').attr('id', p_sPrefix + 'smallProfilePlayMyVoice_' + p).html(m_sPlayMyVoice).appendTo('#' + p_sPrefix + 'smallProfileAudioControl_' + p);
    $('<div>').attr('class', 'PlayButton').attr('id', p_sPrefix + 'PlayButton_' + p).attr('title', m_sPlayTitle).appendTo('#' + p_sPrefix + 'smallProfileAudioControl_' + p);
    $('<div>').attr('class', 'PauseButton').attr('id', p_sPrefix + 'PauseButton_' + p).attr('title', m_sPauseTitle).appendTo('#' + p_sPrefix + 'smallProfileAudioControl_' + p);
                        
    $('<div>').attr('class', 'smallProfileStatuses').attr('id', p_sPrefix + 'smallProfileStatuses_' + p).appendTo('#' + p_sPrefix + 'smallProfile_' + p);
    
    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'PhoneStatus_' + p).attr('rel', '#Overlay').attr('action', 'Phone').attr('title', m_aPhone['Offline']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'PhoneStatusImage_' + p).appendTo('#' + p_sPrefix + 'PhoneStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'PhoneStatusText_' + p).html(m_aPhone['StatusText']).appendTo('#' + p_sPrefix + 'PhoneStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'WebcamStatus_' + p).attr('rel', '#Overlay').attr('action', 'Webcam').attr('title', m_aWebcam['Offline']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'WebcamStatusImage_' + p).appendTo('#' + p_sPrefix + 'WebcamStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'WebcamStatusText_' + p).html(m_aWebcam['StatusText']).appendTo('#' + p_sPrefix + 'WebcamStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'SmsStatus_' + p).attr('rel', '#Overlay').attr('action', 'Sms').attr('title', m_aSms['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'SmsStatusImage_' + p).appendTo('#' + p_sPrefix + 'SmsStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'SmsStatusText_' + p).html(m_aSms['StatusText']).appendTo('#' + p_sPrefix + 'SmsStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'EmailStatus_' + p).attr('rel', '#Overlay').attr('action', 'Email').attr('title', m_aEmail['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'EmailStatusImage_' + p).appendTo('#' + p_sPrefix + 'EmailStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'EmailStatusText_' + p).html(m_aEmail['StatusText']).appendTo('#' + p_sPrefix + 'EmailStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'VideoStatus_' + p).attr('rel', '#Overlay').attr('action', 'Video').attr('title', m_aVideo['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'VideoStatusImage_' + p).appendTo('#' + p_sPrefix + 'VideoStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'VideoStatusText_' + p).html(m_aVideo['StatusText']).appendTo('#' + p_sPrefix + 'VideoStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'PhotoStatus_' + p).attr('rel', '#Overlay').attr('action', 'Photo').attr('title', m_aPhoto['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'PhotoStatusImage_' + p).appendTo('#' + p_sPrefix + 'PhotoStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'PhototatusText_' + p).html(m_aPhoto['StatusText']).appendTo('#' + p_sPrefix + 'PhotoStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'CalendarStatus_' + p).attr('rel', '#Overlay').attr('action', 'Calendar').attr('title', m_aCalendar['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'CalendarStatusImage_' + p).appendTo('#' + p_sPrefix + 'CalendarStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'CalendarStatusText_' + p).html(m_aCalendar['StatusText']).appendTo('#' + p_sPrefix + 'CalendarStatus_' + p);

    $('<div>').attr('class', 'statuses').attr('id', p_sPrefix + 'WebshopStatus_' + p).attr('rel', '#Overlay').attr('action', 'Webshop').attr('title', m_aWebshop['Unavailable']).appendTo('#' + p_sPrefix + 'smallProfileStatuses_' + p);
    $('<div>').attr('class', 'StatusImage').attr('id', p_sPrefix + 'WebshopStatusImage_' + p).appendTo('#' + p_sPrefix + 'WebshopStatus_' + p);
    $('<div>').attr('class', 'StatusText').attr('id', p_sPrefix + 'WebshopStatusText_' + p).html(m_aWebshop['StatusText']).appendTo('#' + p_sPrefix + 'WebshopStatus_' + p);

    $('<div>').attr('class', 'smallProfileCallMe').attr('id', p_sPrefix + 'smallProfileCallMe_' + p).appendTo('#' + p_sPrefix + 'smallProfile_' + p);
    $('<div>').attr('class', 'smallProfileCallText').attr('id', p_sPrefix + 'smallProfileCallText_' + p).html(m_sCallText).appendTo('#' + p_sPrefix + 'smallProfileCallMe_' + p);
    $('#Clientcode').attr('id', p_sPrefix + 'Clientcode_' + p);
}

function addProfileData(p_iPosition, p_bDetailed, p_sPrefix, p2){
    var p_sPhotoStatus = 'Unavailable';
    var p_sVideoStatus = 'Unavailable';
    
    var p = p_iPosition;
    
    var p_sClientcode = m_aProfilePosition[p];
    
    if(p_bDetailed) p = p2;

    var p_iPhotos = m_aOperatorsList[p_sClientcode].paidPhotos;
    var p_iVideos = m_aOperatorsList[p_sClientcode].paidVideos;
    
    var p_sAlias = m_aOperatorsList[p_sClientcode].alias;
    var p_sCalendarStatus = m_aOperatorsList[p_sClientcode].calendarStatus;
    var p_sEmailStatus = m_aOperatorsList[p_sClientcode].emailStatus
    var p_sImage = m_aOperatorsList[p_sClientcode].image;
    var p_sPhoneStatus = m_aOperatorsList[p_sClientcode].phoneStatus;
    var p_sSmsStatus = m_aOperatorsList[p_sClientcode].smsStatus;
    var p_sWebcamStatus = m_aOperatorsList[p_sClientcode].webcamStatus;
    var p_sWebshopStatus = m_aOperatorsList[p_sClientcode].webshopStatus;
    var p_sWebcamAvailable = m_aOperatorsList[p_sClientcode].webcamAvailable;
        
    if(p_iPhotos) 
        p_sPhotoStatus = 'Available';
    
    if(p_iVideos) 
        p_sVideoStatus = 'Available';

    $('#' + p_sPrefix + 'onlineStatusLayer2_' + p).removeClass().addClass(p_sPhoneStatus.toLowerCase() + 'StatusLayer2');
    $('#' + p_sPrefix + 'onlineStatusLayer3_' + p).removeClass().addClass(p_sPhoneStatus.toLowerCase() + 'StatusLayer3');
    $('#' + p_sPrefix + 'onlineStatusLayer4_' + p).removeClass().addClass(p_sPhoneStatus.toLowerCase() + 'StatusLayer4');
    $('#' + p_sPrefix + 'onlineStatusLayer5_' + p).removeClass().addClass(p_sPhoneStatus.toLowerCase() + 'StatusLayer5');
            
    if(p_sPhoneStatus == 'Online') 
        $('#' + p_sPrefix + 'onlineStatusLabel_' + p).html('Live');
    else if (p_sPhoneStatus == 'Busy') 
        $('#' + p_sPrefix + 'onlineStatusLabel_' + p).html('');
    else 
        $('#' + p_sPrefix + 'onlineStatusLabel_' + p).html('');

    $('#' + p_sPrefix + 'Clientcode_' + p).html(p_sClientcode);
    $('#' + p_sPrefix + 'smallProfileOf_' + p).html(p_sAlias);
    $('#' + p_sPrefix + 'smallProfileInfo_' + p).attr('clientcode', p_sClientcode);

    $('#' + p_sPrefix + 'smallProfilePhoto_' + p).css('background-image', 'url(' + p_sImage + ')');
        
    $('#' + p_sPrefix + 'smallProfileClickField_' + p).attr('clientcode', p_sClientcode);
    $('#' + p_sPrefix + 'PlayButton_' + p).attr('rel', p_sClientcode);

    $('#' + p_sPrefix + 'CalendarStatus_' + p).attr('title', m_aCalendar[p_sCalendarStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('available', p_sCalendarStatus);
    $('#' + p_sPrefix + 'CalendarStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sCalendarStatus] + ')');

    $('#' + p_sPrefix + 'EmailStatus_' + p).attr('title', m_aEmail[p_sEmailStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('available', p_sEmailStatus);
    $('#' + p_sPrefix + 'EmailStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sEmailStatus] + ')');
        
    $('#' + p_sPrefix + 'PhoneStatus_' + p).attr('title', m_aPhone[p_sPhoneStatus]).attr('clientcode', p_sClientcode);
    $('#' + p_sPrefix + 'PhoneStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sPhoneStatus] + ')');
        
    $('#' + p_sPrefix + 'PhotoStatus_' + p).attr('title', m_aPhoto[p_sPhotoStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('available', p_sPhotoStatus);
    $('#' + p_sPrefix + 'PhotoStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sPhotoStatus] + ')');
        
    $('#' + p_sPrefix + 'SmsStatus_' + p).attr('title', m_aSms[p_sSmsStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('available', p_sSmsStatus);
    $('#' + p_sPrefix + 'SmsStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sSmsStatus] + ')');
        
    $('#' + p_sPrefix + 'VideoStatus_' + p).attr('title', m_aVideo[p_sVideoStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('available', p_sVideoStatus);
    $('#' + p_sPrefix + 'VideoStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sVideoStatus] + ')');

    $('#' + p_sPrefix + 'WebcamStatus_' + p).attr('title', m_aWebcam[p_sWebcamStatus]).attr('clientcode', p_sClientcode).attr('alias', p_sAlias).attr('status', p_sWebcamStatus).attr('available', p_sWebcamAvailable);
    $('#' + p_sPrefix + 'WebcamStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sWebcamStatus] + ')');
        
    $('#' + p_sPrefix + 'WebshopStatus_' + p).attr('title', m_aWebshop[p_sWebshopStatus]).attr('clientcode', p_sClientcode);
    $('#' + p_sPrefix + 'WebshopStatusImage_' + p).css('background-image', 'url(' + m_aStatuses[p_sWebshopStatus] + ')');
    
    if(p_bDetailed && p_sPrefix != 'bigProfile_') {
        var p_aPreferences;
        var p_bFirst = true;
        var p_iAge = m_aOperatorsList[p_sClientcode].age;
        var p_iPreferences = m_aOperatorsList[p_sClientcode].preferences;
        var p_sCupSize = m_aOperatorsList[p_sClientcode].cupsize;
        var p_sDescription = m_aOperatorsList[p_sClientcode].description;
        var p_sFigure = m_aOperatorsList[p_sClientcode].figure;
        var p_sHairColor = m_aOperatorsList[p_sClientcode].hairColor;
        
        $('#spotlightPreferencesText'+p).empty();

        $('#spotlightPersonalInfoText'+p).html('Leeftijd: ' + p_iAge + ' jaar<br />Haarkleur: ' + p_sHairColor + '<br />Cup-maat: ' + p_sCupSize + '<br />Lichaamsbouw: ' + p_sFigure);
        p_aPreferences = preferences(p_iPreferences);
        
        var max = 7;
        
        for(var i = 0; i < max; i++){
            if(p_aPreferences[i] == undefined) break;
            if(p_aPreferences[i].length > 19) max = 6;
            if(p_aPreferences[i].length > 19 && i == 6) break;
            
            if(!p_bFirst)
                $('#spotlightPreferencesText'+p).append('<br />');

            $('#spotlightPreferencesText'+p).append('- ' + p_aPreferences[i]);
            
            p_bFirst = false;
        }
        $('#spotlightDescriptionText'+p).html(p_sDescription);
        
        $('#spotlightProfile1').show();
        $('#spotlightProfile2').show();
    }    
    
    return p_sClientcode;
}

function preferences(p_iPreferences){
    var k = 0;
    var p_aPreferences = new Array();
    var p_iPreference;
    
    if(p_iPreferences > 0){
        for (var p_sPreference in m_aSettings.PREFERENCES){
            p_iPreference = parseInt(m_aSettings.PREFERENCES[p_sPreference]['value'])
            if ((p_iPreferences & p_iPreference) === p_iPreference){
                p_aPreferences[k++] = m_aSettings.PREFERENCES[p_sPreference]['text'];
            }
        }
                                
        p_aPreferences = $.shuffle(p_aPreferences);
    }

    return p_aPreferences;
}

function addProfilesData(){
    if(m_iCurrentIndex > 0){
        m_iCurrentStartPosition = ((m_iCurrentIndex - 1) * 20) + 1 + m_iTotalProfilesFrontPage;
        m_iCurrentStopPosition = m_iCurrentStartPosition + m_iTotalProfilesPages;
    } else {
        m_iCurrentStartPosition = 0;
        m_iCurrentStopPosition = m_iTotalProfilesFrontPage;
    }    
    
    for(var i = m_iCurrentStartPosition; i < m_iCurrentStopPosition; i++){
        if(m_aProfilePosition[i] != undefined){
            addProfileData(i, false, '');
        }
    }
}

function loadDetailedData(p_sClientcode){ 
    $.ajax({
        data: ({
            agent_id: p_sClientcode
        }),
        dataType: 'xml',
        error: function(event, request, settings){
            alert('Event: ' + event + '\nRequest: ' + request + '\nSettings: ' + settings)
        },
        success: function (data){
            var p_iPreferences = parseInt($(data).find('preferences').text());
            var p_sCupsize = $(data).find('cupsize').text();
            var p_sEyeColor = $(data).find('eyeColor').text();
            var p_sFigure = $(data).find('figure').text();
            var p_sHairColor = $(data).find('hairColor').text();
            var p_sHobbies = $(data).find('hobbies').text();
            var p_sLongDescription = $(data).find('longDescription').text();
            var p_sNationality = $(data).find('nationality').text();

            m_aOperatorsList[p_sClientcode].cupsize = p_sCupsize;
            m_aOperatorsList[p_sClientcode].eyeColor = p_sEyeColor;
            m_aOperatorsList[p_sClientcode].figure = p_sFigure;
            m_aOperatorsList[p_sClientcode].hairColor = p_sHairColor;
            m_aOperatorsList[p_sClientcode].hobbies = p_sHobbies;
            m_aOperatorsList[p_sClientcode].longDescription = p_sLongDescription;
            m_aOperatorsList[p_sClientcode].nationality = p_sNationality;
            m_aOperatorsList[p_sClientcode].preferences = p_iPreferences;
        },        
        url: '/_assets/proxy.php'
    });

}

function addSpotlight (){
    var p_aData = new Array();
    p_aData.addTo = 'spotlightSmallProfile1';
    p_aData.prefix = 'spotlight_';
    p_aData.position = 1;
    
    $('<div>').attr('id', 'spotlightProfile1').attr('class', 'spotlightProfile').appendTo('#Page1');
    $('<div>').attr('id', 'spotlightProfileBg1').attr('class', 'spotlightProfileBg').appendTo('#spotlightProfile1');
    $('<div>').attr('id', 'spotlightTitle1').attr('class', 'spotlightTitle').html('Profile:').appendTo('#spotlightProfileBg1');
    $('<div>').attr('id', 'spotlightSmallProfile1').attr('class', 'spotlightSmallProfile').appendTo('#spotlightProfileBg1');
    smallProfile(p_aData);
    $('<div>').attr('id', 'spotlightAboutMe1').attr('class', 'spotlightAboutMe').appendTo('#spotlightProfileBg1');
    $('<div>').attr('id', 'spotlightAboutMeTitle1').attr('class', 'spotlightAboutMeTitle').html('Over Mij:').appendTo('#spotlightAboutMe1');
    $('<div>').attr('id', 'spotlightPersonalInfoTitle1').attr('class', 'spotlightPersonalInfoTitle').html('Persoonlijke info:').appendTo('#spotlightAboutMe1');
    $('<div>').attr('id', 'spotlightPersonalInfoText1').attr('class', 'spotlightPersonalInfoText').appendTo('#spotlightAboutMe1');
    $('<div>').attr('id', 'spotlightPreferencesTitle1').attr('class', 'spotlightPreferencesTitle').html('Voorkeuren:').appendTo('#spotlightAboutMe1');
    $('<div>').attr('id', 'spotlightPreferencesText1').attr('class', 'spotlightPreferencesText').appendTo('#spotlightAboutMe1');
    $('<div>').attr('id', 'spotlightDescription1').attr('class', 'spotlightDescription').appendTo('#spotlightProfileBg1');
    $('<div>').attr('id', 'spotlightInfoTitle1').attr('class', 'spotlightInfoTitle').html('Info').appendTo('#spotlightDescription1')
    $('<div>').attr('id', 'spotlightDescriptionTitle1').attr('class', 'spotlightDescriptionTitle').html('Beschrijving:').appendTo('#spotlightDescription1');
    $('<div>').attr('id', 'spotlightDescriptionText1').attr('class', 'spotlightDescriptionText').appendTo('#spotlightDescription1');
    
    p_aData.addTo = 'spotlightSmallProfile2';
    p_aData.position = 2;
    $('<div>').attr('id', 'spotlightProfile2').attr('class', 'spotlightProfile').appendTo('#Page1');
    $('<div>').attr('id', 'spotlightProfileBg2').attr('class', 'spotlightProfileBg').appendTo('#spotlightProfile2');
    $('<div>').attr('id', 'spotlightTitle2').attr('class', 'spotlightTitle').html('Profile:').appendTo('#spotlightProfileBg2');
    $('<div>').attr('id', 'spotlightSmallProfile2').attr('class', 'spotlightSmallProfile').appendTo('#spotlightProfileBg2');
    smallProfile(p_aData);
    $('<div>').attr('id', 'spotlightAboutMe2').attr('class', 'spotlightAboutMe').appendTo('#spotlightProfileBg2');
    $('<div>').attr('id', 'spotlightAboutMeTitle2').attr('class', 'spotlightAboutMeTitle').html('Over Mij:').appendTo('#spotlightAboutMe2');
    $('<div>').attr('id', 'spotlightPersonalInfoTitle2').attr('class', 'spotlightPersonalInfoTitle').html('Persoonlijke info:').appendTo('#spotlightAboutMe2');
    $('<div>').attr('id', 'spotlightPersonalInfoText2').attr('class', 'spotlightPersonalInfoText').appendTo('#spotlightAboutMe2');
    $('<div>').attr('id', 'spotlightPreferencesTitle2').attr('class', 'spotlightPreferencesTitle').html('Voorkeuren:').appendTo('#spotlightAboutMe2');
    $('<div>').attr('id', 'spotlightPreferencesText2').attr('class', 'spotlightPreferencesText').appendTo('#spotlightAboutMe2');
    $('<div>').attr('id', 'spotlightDescription2').attr('class', 'spotlightDescription').appendTo('#spotlightProfileBg2');
    $('<div>').attr('id', 'spotlightInfoTitle2').attr('class', 'spotlightInfoTitle').html('Info').appendTo('#spotlightDescription2')
    $('<div>').attr('id', 'spotlightDescriptionTitle2').attr('class', 'spotlightDescriptionTitle').html('Beschrijving:').appendTo('#spotlightDescription2');
    $('<div>').attr('id', 'spotlightDescriptionText2').attr('class', 'spotlightDescriptionText').appendTo('#spotlightDescription2');


//    $('<div>').attr('id', 'spotlightCallMe').appendTo('#spotlightProfileBg2');
//    $('<div>').attr('id', 'spotlightCallMeText1').html('Voor een heet gesprekje').appendTo('#spotlightCallMe');
//    $('<div>').attr('id', 'spotlightCallMeText2').html('BEL MIJ NU!').appendTo('#spotlightCallMe');
//    $('<div>').attr('id', 'spotlightCallMeText3').html('0906-0135 <span style="font-size:10px">80cpm</span> <span class="smallProfileCallText">Mijn code:</span> <span class="colorClientcode">928</span>').appendTo('#spotlightCallMe');
//
//    $('<div>').attr('id', 'SeeMyMovies').appendTo('#spotlightProfileBg2');
//    $('<div>').attr('id', 'SeeMyMoviesText').html('FILMS van Chelly zien <a action="Video" available="Unavailable" alias="Chelly" clientcode="928" class="ClickHere" href="#" rel="#Overlay">klik hier</a> of <br />ZELF meedoen in een film van Chelly? <a href="#" rel="#Overlay" action="makemovie" class="ClickHere">klik hier</a>').appendTo('#SeeMyMovies');
//    
//    $('<div>').attr('id', 'spotlightPhoto').appendTo('#spotlightProfileBg2');
//    $('<div>').attr('id', 'spotlightShop').appendTo('#spotlightProfileBg2');
//    $('<div>').attr('id', 'spotlightBuySomething').html('Bovenstaande schilderij met mij er op kopen?').appendTo('#spotlightShop');
//    $('<div>').html('<a id="ClickMeLink" href="shop/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=1&category_id=1&option=com_virtuemart&Itemid=1&vmcchk=1&Itemid=1" target="_blank" onfocus="blur()">klik hier</a>').appendTo('#spotlightShop');
}

function addSpotlightData (){
    m_bPayCamOnline = false;
    
    var p_sPrefix = 'spotlight_';
    var p_iPositionDetails;
    
    for(var i in m_aProfilePosition){
        if(m_aProfilePosition[i] == m_iPreferedSpotlightOperator){
            p_iPositionDetails = i;
            break;
        }
    }
    
    var p_sClientcode = addProfileData(p_iPositionDetails, true, p_sPrefix, 1);
    var p_sFreeWebcamStatus = m_aOperatorsList[p_sClientcode].freeWebcamStatus;
    var p_sWebcamStatus = m_aOperatorsList[p_sClientcode].webcamStatus;
    
    if(p_sWebcamStatus == 'Online') m_bPayCamOnline = true;

    if(!m_bFreeCamLoaded && p_sFreeWebcamStatus == 'Online'){
        flashembed('FreeCam', {
            src: m_aSettings.sourceUrl + '/swf/FreeChatVisitor.swf',
            width: 800,
            height: 300,
            wmode: 'transparent'
            
        }, {
            application: 'freevideochat',
            channelid: 'channel1',
            country: 'Netherlands',
            customerid: '000000',
            fmshost: m_aSettings.sourceUrl.substr(7),
            operatorid: p_sClientcode,
            phphost: 'chat.crystalentertainment.nl',
            system: m_sSystem
        });

        m_bFreeCamLoaded = true;
    } else if (p_sFreeWebcamStatus == 'Offline') {
        m_bFreeCamLoaded = false;
        addInfoAboutWebcam();
    }
    
    for(i in m_aAvailableFreeWebcam){
        //alert(m_aAvailableFreeWebcam[i])
        if(p_sClientcode != m_aAvailableFreeWebcam[i]){
            p_sClientcode = m_aAvailableFreeWebcam[i];
            for(var p in m_aProfilePosition){
                if(m_aProfilePosition[p] == p_sClientcode){
                    p_iPositionDetails = p;
                    break;
                }
            }
            break;
        }
    }
    loadDetailedData(p_sClientcode);
    addProfileData(p_iPositionDetails, true, p_sPrefix, 2);
}

function addInfoAboutWebcam(){
    $('#FreeCam').empty();
    $('<div>').attr('id', 'webcamImage').appendTo('#FreeCam');
    $('<div>').attr('id', 'FreeCamImage').appendTo('#FreeCam');
    $('<div>').attr('id', 'FreeCamHeaderText').appendTo('#FreeCamImage');
    $('<div>').attr('id', 'FreeCamBodyText').appendTo('#FreeCamImage');
    $('<div>').attr('id', 'FreeCamFooterText').appendTo('#FreeCamImage');
    
    loadChatTexts();
}

