/**
 * @author archie llorca damongkal@yahoo.com
 * @since 28-apr-2008
 * @package live-chat
 * @copyright Intermax Asia Group 2008
 */
var is_chatcam_iframe = 'false';
var so;
//2 GIRL CAM vars
var specialtag;
var saveId1;
var saveId2;

//-------------------------------------------------------------------------------
// FLASH THUMBNAIL MANIPULATION
//

/**
 * show the flash container for thumbnails.
 * used by model_thumbnail.tpl
 */
function thumbnailFlash(cam_src,cam_status,cam_id,cam_type,model_id)
{
    so = new SWFObject("flash/flash_jpgpush.swf", "funct"+model_id, "159", "116",  "8", "#ffffff");
    so.addVariable("jpgsource", cam_src);
    so.addVariable("modstat", cam_status);
    so.addVariable("modId", cam_id);
    so.addVariable("modType", cam_type);
    so.addParam("wmode", "transparent");
    so.addParam("allowscriptaccess", "always");
    ret = so.write("cam_swf"+model_id);
//    alert(so.getSWFHTML());
    if (ret == false)
    {
        ret = so.getSWFHTML();
        $("#cam_img"+model_id).html(ret);
    }
    so = null;
}

function getFlashMovieObject(movieName)
{
    if (window.document[movieName])
    {
        //alert('name');
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1)
    {
        //alert('embed');
        if (document.embeds && document.embeds[movieName])
        {
            return document.embeds[movieName];
        }
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        //alert('id');
        return document.getElementById(movieName);
    }
}

function getFlashIDOvr($bodyID)
{
    var flashMovie=getFlashMovieObject($bodyID);
    flashMovie.sendFlashOver();
}

function getFlashIDOut($bodyID)
{
    var flashMovie=getFlashMovieObject($bodyID);
    flashMovie.sendFlashOut();
}

function chngeReqst($mode)
{
    var flashMovie;
    $('.thumb_swf').each(function (i) {
        flashMovie = getFlashMovieObject(this.id);
        flashMovie.sendChangeStat($mode);
    });
    flashMovie = null;
}

function cam2camMode($girlId)
{
    window.location='index.php?ctrl=cam2cam_normal&id='+$girlId;
}

function girlSelect($girlId)
{
    if (specialtag == 1)
    {
        saveId2 = $girlId;
        //window.location='index.php?ctrl=chat2girl_normal&id1='+saveId1+'&id2='+saveId2;
        // added
        $('#samplelist').modal({onOpen: function (dialog) {
            dialog.overlay.show();
            dialog.container.show();
            dialog.data.show().fadeOut(4000);
            dialog.container.slideDown();
            dialog.overlay.fadeOut(4000, function () {
                $.modal.close();
                window.location='index.php?ctrl=whoisonline';
            });
        }});

        // added
        specialtag = 2;
    }
    else if (specialtag == null)
    {
        saveId1 = $girlId;
        specialtag = 1;
    }
    else
    {
        alert("2girl mode already started!");
    }
}

function resetMode(){
    specialtag = null;
}

//-------------------------------------------------------------------------------
// CHAT REDIRECTION
//

function showChat(id, category , tag, uname, sofortzugang, pravs)
{
    if(uname=="none")
    {
        var logwindow = window.open('index.php?ctrl=login_client', 'popUpWindow','scrollbars=no,width=1004,height=520,screenX=10,screenY=10');
    }
    else
    {
        // disable chat for VODIX
        if (category=='vodix')
        {
            alert('Chat not available for this model.');
        }
        else
        {
            // determine controller
            var chatCtrl = '';

            if (category=='priv')
            {
                chatCtrl = 'login_fpchat&size=3';
            }
            else
            {
                chatCtrl = 'login_fpchat&size=1';
            }
            //getURL('index.php?ctrl=hardcore&id='+ _root.modId);
            // request hardcore
            var rqstHC = '';

            if (tag == 'HC')
            {
                rqstHC = '&tag='+tag;
                chatCtrl = 'login_chat_rhc';
            }

            if (tag == 'HCD' && category != 'priv')
            {
                chatCtrl = 'login_hardcore&size=1';
            }

            if (tag == 'HC' || tag == 'HCD')
            {
                if(sofortzugang != "none")
                {
                    if(tag == 'HC')
                    {
                        chatCtrl = 'login_chat_rhc';
                    }
                    else
                    {
                        chatCtrl = 'login_hardcore&size=1';
                    }
                }
                else
                {
                    if(pravs==1)
                    {
                        window.open('index.php?ctrl=avs');
                        //alert("Bitte Vollj�hrigkeit �berpr�fen");
                        return false;
                        //chatCtrl = '';
                    }

                    if (current_coins<=199)
                    {
                        var answ = confirm('Du hast nicht genügend Coins um den Hardcorechat zu starten. Klicke um Coins zu kaufen.');
                        if (answ)
                        {
                            chatCtrl = 'payment';
                        }
                        else
                        {
                            return false;
                            //chatCtrl = '';
                        }
                    }
                }
            }

            // redirect
            if (chatCtrl!='' && chatCtrl != 'login_chat_rhc')
            {
                /*
                if (is_chatcam_iframe == 'false')
                {
                    var newwindow = window.location='index.php?ctrl='+chatCtrl+'&id='+$id+rqstHC;
                }
                else
                {
                    var newwindow = window.location='index.php?ctrl='+chatCtrl+'&id='+$id+rqstHC;
                }
                 */
                var newwindow = window.open('index.php?ctrl='+chatCtrl+'&type='+category+'&id='+id+rqstHC, 'popUpWindow','scrollbars=yes,width=1004,height=720,screenX=10,screenY=10');
                newwindow.opener.location.reload();
            }
            else
            {
                show_informHC(id);
            }
        }
    }// end if
}// end function

function show_informHC(id)
{
    jQuery.facebox({ ajax: 'index.php?ctrl=login_chat_rhc&id='+ id + '&tag=HC' })
    // added jquery modal
    $.modal($('#facebox'), {onShow: function (dialog) {
        dialog.overlay.fadeIn(1000);
        dialog.overlay.one('click', function () {
            $.modal.close();
            window.location='index.php?ctrl=whoisonline';
      });
    }})
    // end jquery modal
}

function showVideo($id, $category)
{
    var $mode = 'tk';
    if ($category=='vodix')
    {
        $mode = 'vodix';
    }
   // var newwindow = window.location='index.php?ctrl=vodix_profile&id='+$id+'&mode='+$mode;
    var profilewindow = window.open('index.php?ctrl=login_vodix_profile&id='+$id+'&mode='+$mode+'&cam_source='+$category, 'popUpWindow','scrollbars=yes,width=1004,height=535,screenX=10,screenY=10');
    profilewindow.opener.location.reload();
}

function showInfo($id, $category)
{
    showVideo($id, $category);
}

//-------------------------------------------------------------------------------
// TOOLTIP
//

// load the tooltip object
$(document).ready(function(){
    //Tooltip.init();
 });

function doTooltip(e, cam_id, source)
{
    if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;

    // get the index of the JSON object
    var my_cam_model;
    var cam_model = 0;
    if (source==1)
    {
        for (var i=0; i<camlist.length; i++)
        {
            if (camlist[i].id == cam_id)
            {
                cam_model = i;
            }
        }
        my_cam_model = camlist[cam_model];
    }
    else
    {
        for (var i=0; i<camlist2.length; i++)
        {
            if (camlist2[i].id == cam_id)
            {
                cam_model = i;
            }
        }
        my_cam_model = camlist2[cam_model];
    }

    // retrieve the model thumbnail
    var msg = document.getElementById('model_tooltip').innerHTML;
    // general attributes
    var model_attr = my_cam_model.attributes;
    var model_nickname = my_cam_model.nickname;
    var tmp_cat = model_attr.category;
    tmp_cat = tmp_cat.replace('vodix', 'amateur');

    // populate the template
    msg = msg.replace(/tpl_cam_id/g, cam_id);
    msg = msg.replace(/tpl_name/g, model_nickname);
    msg = msg.replace(/tpl_age/g, model_attr.age);
    msg = msg.replace(/tpl_category/g, tmp_cat);
	msg = msg.replace(/tpl_price/g, model_attr.price_category);
    if (model_attr.status!= -1){
        msg = msg.replace(/tpl_status/g, "ONLINE");
    }else{
        msg = msg.replace(/tpl_status/g, "OFFLINE");
    }

    // vodix specific
    if (my_cam_model.attributes.category=='vodix')
    {
        // populate the template
        msg = msg.replace(/tpl_look/g, '-');
        msg = msg.replace(/tpl_info/g, '-');
        msg = msg.replace(/tpl_hobby/g, '-');
        msg = msg.replace(/tpl_favorite/g, '-');
        msg = msg.replace(/tpl_height/g, '-');
        msg = msg.replace(/tpl_weight/g, '-');
        msg = msg.replace(/tpl_breast/g, '-');
        msg = msg.replace(/tpl_langs/g, '-');
        msg = msg.replace(/tpl_clip_count/g, my_cam_model.profile.urclipcount);
        msg = msg.replace(/tpl_video_count/g, my_cam_model.profile.urvideocount);
        msg = msg.replace(/tpl_gallery_count/g, my_cam_model.profile.urgallerycount);
    }
    // turnkey specific
    else
    {
        // lets get the profile
        var profile_lang = my_cam_model.attributes.profile_lang;
        var tmp = my_cam_model.profile;
        var profile = tmp[profile_lang];

        // populate the template
        msg = msg.replace(/tpl_look/g, profile.look);
        msg = msg.replace(/tpl_info/g, profile.info);
        msg = msg.replace(/tpl_hobby/g, profile.hobbies);
        msg = msg.replace(/tpl_favorite/g, profile.favorites);
        msg = msg.replace(/tpl_height/g, profile.height);
        msg = msg.replace(/tpl_weight/g, profile.weight);
        msg = msg.replace(/tpl_breast/g, profile.breast);
        msg = msg.replace(/tpl_langs/g, model_attr.langs);
        msg = msg.replace(/tpl_clip_count/g, '0');
        msg = msg.replace(/tpl_video_count/g, '0');
        msg = msg.replace(/tpl_gallery_count/g, model_attr.gallery_count);
    }

    // remove undefined variables
    msg = msg.replace(/undefined/g,'-');

    Tooltip.show(e, msg);
}

function doTooltipbox(msg)
{
    //alert("fasfds");
    //if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
    //alert(msg);
    var txt = document.getElementById('modelinfo_tooltip').innerHTML;

    txt = txt.replace(/tpl_text/g, msg);
    //alert(txt);
    Tooltip.showe(txt);
}

function doTooltipdating(usid)
{
    //alert(datinglist);
    //if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
    //alert(msg);
    var my_dating_model;
    var dating_model = 0;
    for (var i=0; i<datinglist.length; i++)
    {
       if (datinglist[i].id == usid)
       {
          dating_model = i;
       }
    }
    my_dating_model = datinglist[dating_model];

    var txt = document.getElementById('sexkontakt_tooltip').innerHTML;

    //txt = txt.replace(/tpl_cam_id/g, cam_id);
    if(my_dating_model.urgender==0)
    {
        my_urgender = "male";
    }
    else if(my_dating_model.urgender==1)
    {
        my_urgender = "female";
    }

    txt = txt.replace(/tpl_id/g, my_dating_model.id);
    txt = txt.replace(/tpl_urphotosmall/g, my_dating_model.urphotosmall);
    txt = txt.replace(/tpl_urnickname/g, my_dating_model.urnickname);
    txt = txt.replace(/tpl_urgender/g, my_urgender);
    txt = txt.replace(/tpl_cizip/g, my_dating_model.cizip);
    txt = txt.replace(/tpl_coname/g, my_dating_model.coname);
    txt = txt.replace(/tpl_usercivilstatus/g, my_dating_model.usercivilstatus);
    txt = txt.replace(/tpl_urage/g, my_dating_model.urage);
    txt = txt.replace(/tpl_usereyescolor/g, my_dating_model.usereyescolor);
    txt = txt.replace(/tpl_urfigure/g, my_dating_model.urfigure);
    txt = txt.replace(/tpl_urbodysize/g, my_dating_model.urbodysize);
    txt = txt.replace(/tpl_urfigure/g, my_dating_model.urfigure);
    txt = txt.replace(/tpl_userhaircolor/g, my_dating_model.userhaircolor);
    txt = txt.replace(/tpl_ursmoker/g, my_dating_model.ursmoker);
    txt = txt.replace(/tpl_urgendersearch/g, my_dating_model.urgendersearch);
    txt = txt.replace(/tpl_cit_ciid/g, my_dating_model.cit_ciid);
    //txt = txt.replace(/tpl_text/g, msg);
    //alert(txt);
    Tooltip.showed(txt);
}

function hideTip()
{
    if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
    Tooltip.hide();
}

function doTooltipdating2(usid)
{
    var my_dating_model;
    var dating_model = 0;
    for (var i=0; i<datinglist.length; i++)
    {
       if (datinglist[i].dating_id == usid)
       {
          dating_model = i;
       }
    }

    my_dating_model = datinglist[dating_model];

    var txt = document.getElementById('sexkontakt_tooltip').innerHTML;

    txt = txt.replace(/tpl_id/g, my_dating_model.dating_id);
    txt = txt.replace(/tpl_urphotosmall/g, my_dating_model.image);
    txt = txt.replace(/tpl_urnickname/g, my_dating_model.nickname);
    txt = txt.replace(/tpl_urgender/g, my_dating_model.gender);
    txt = txt.replace(/tpl_cizip/g, my_dating_model.zip);
    txt = txt.replace(/tpl_coname/g, my_dating_model.country);
    txt = txt.replace(/tpl_usercivilstatus/g, my_dating_model.status);
    txt = txt.replace(/tpl_urage/g, my_dating_model.age);
    txt = txt.replace(/tpl_usereyescolor/g, my_dating_model.eye);
    txt = txt.replace(/tpl_urfigure/g, my_dating_model.body);
    txt = txt.replace(/tpl_urbodysize/g, my_dating_model.height);
    txt = txt.replace(/tpl_urfigure/g, my_dating_model.body);
    txt = txt.replace(/tpl_userhaircolor/g, my_dating_model.hair);
    txt = txt.replace(/tpl_ursmoker/g, my_dating_model.smoker);
    txt = txt.replace(/tpl_urgendersearch/g, my_dating_model.looking);
    txt = txt.replace(/tpl_cit_ciid/g, my_dating_model.plz);
    //txt = txt.replace(/tpl_text/g, msg);
    //alert(txt);
    Tooltip.showed(txt);
}

function transRegistration()
{
    window.location='#';
    var flashMovie=getFlashMovieObject('fake');
    flashMovie.sendFlash();
    ShowInfoLayer("Info_Nickname");
    setfocus();
}

function chngeBySession($mode)
{
    var flashMovie2;
    $('.thumb_swf').each(function (i) {
        flashMovie2 = getFlashMovieObject(this.id);
        flashMovie2.sendSession(mode);
    });
    flashMovie2 = null;
}

function _getFlash(mc)
{
    if (window.document[mc]) 
    {
        return window.document[mc];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1)
    {
        if (document.embeds && document.embeds[mc]) return document.embeds[mc]; 
    }
    else
    {
        return document.getElementById(mc);
    }
}
function _callFlashMethod(methodName)
{
    var swf = _getFlash("tkc_chat_client");
    if (!swf) 
    {
        alert('flash object with id *tkc_chat_client* not found');
        return;
    }
    swf.SetVariable("/_root/externalMethodCaller:callMethod", methodName);
} 

function externalMethod_chatLogout()
{
    _callFlashMethod('socketLogout'); 
    return false;
}
